예제 #1
0
 public function validateCSRF($input)
 {
     $v = Validate::required()->csrf()->placeholders(['name' => 'CSRF-token']);
     if (!$v->validate($input)) {
         $this->addError('alerts', $v->getFirstError());
     }
 }
예제 #2
0
 public function validate($input)
 {
     if (is_object($input)) {
         $input = (array) $input;
     }
     if ($this->attributes instanceof Validate) {
         $this->each($input);
     }
     foreach ($this->attributes as $attribute => $validate) {
         if (!$validate instanceof Validate) {
             throw new ValidateException("`{$attribute}` is not `" . Validate::className() . "`");
         }
         if ($attribute === $this->remainder) {
             $this->remainder($validate, $input);
             continue;
         }
         if (!isset($input[$attribute])) {
             $input[$attribute] = null;
         }
         $validate->invert = $this->invert;
         if ($validate->validate($input[$attribute])) {
             continue;
         }
         if ($errors = $validate->getErrors()) {
             $this->errors[$attribute] = $errors;
             if ($this->one) {
                 break;
             }
         }
     }
 }
예제 #3
0
 public function validate($value)
 {
     $this->if->invert = $this->then->invert = $this->invert;
     if ($this->if->validate($value)) {
         if (!$this->then->validate($value)) {
             $this->errors = $this->then->getErrors();
             return false;
         }
         return true;
     }
     if (!isset($this->else)) {
         return $this->invert;
     }
     $this->else->invert = $this->invert;
     if (!$this->else->validate($value)) {
         $this->errors = $this->else->getErrors();
         return false;
     }
     return true;
 }
예제 #4
0
 protected function defaultRules()
 {
     $rules = [];
     if (class_exists('\\rock\\mongodb\\validate\\rules\\MongoIdRule')) {
         $rules['mongoId'] = ['class' => \rock\mongodb\validate\rules\MongoIdRule::className(), 'locales' => ['en' => \rock\mongodb\validate\locale\en\MongoIdLocale::className(), 'ru' => \rock\mongodb\validate\locale\ru\MongoIdLocale::className()]];
     }
     if (class_exists('\\rock\\db\\validate\\rules\\Unique')) {
         $rules['unique'] = ['class' => \rock\db\validate\rules\Unique::className(), 'locales' => ['en' => \rock\db\validate\locale\en\Unique::className(), 'ru' => \rock\db\validate\locale\ru\Unique::className()]];
     }
     return $rules + parent::defaultRules();
 }
예제 #5
0
파일: classes.php 프로젝트: romeoz/rock
        return !Rock::$app->user->isGuest();
    }
    return \rock\helpers\ArrayHelper::getValue(Rock::$app->user->getAll(), $keys);
}, 'call' => function (array $call, array $params = [], Template $template) {
    if (!isset($call[1])) {
        $call[1] = null;
    }
    list($class, $method) = $call;
    if ($class === 'context') {
        $object = $template->context;
        $function = [$object, $method];
    } elseif (function_exists($class) && !$class instanceof \Closure) {
        return call_user_func_array($class, $params);
    } else {
        $object = \rock\di\Container::load($class);
        if (!method_exists($object, $method)) {
            throw new \rock\base\BaseException(\rock\base\BaseException::UNKNOWN_METHOD, ['method' => "{$class}::{$method}"]);
        }
        $function = [$object, $method];
    }
    return call_user_func_array($function, $params);
}], 'title' => 'Demo', 'metaTags' => ['charset' => '<meta charset="' . Rock::$app->charset . '" />'], 'linkTags' => ['favicon' => '<link rel="Shortcut Icon" type="image/x-icon" href="/favicon.ico?10">'], 'snippets' => ['request.get' => ['class' => \rock\snippets\request\Get::className()], 'request.post' => ['class' => \rock\snippets\request\Post::className()], 'csrf' => ['class' => \rock\snippets\CSRF::className()], 'captchaView' => ['class' => \rock\snippets\CaptchaView::className()], 'activeForm' => ['class' => \rock\snippets\ActiveForm::className()]]], 'execute' => ['class' => \rock\execute\CacheExecute::className()], 'i18n' => ['class' => \rock\i18n\i18n::className(), 'pathsDicts' => ['ru' => ['@rock/messages/ru/lang.php', '@rock/messages/ru/validate.php'], 'en' => ['@rock/messages/en/lang.php', '@rock/messages/en/validate.php']], 'locale' => [\rock\LocaleProperties::className(), 'locale']], 'date' => ['class' => \rock\date\DateTime::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale'], 'formats' => ['dmy' => function (\rock\date\DateTime $dateTime) {
    $nowYear = date('Y');
    $lastYear = $dateTime->format('Y');
    return $nowYear > $lastYear ? $dateTime->format('j F Y') : $dateTime->format('d F');
}, 'dmyhm' => function (\rock\date\DateTime $dateTime) {
    $nowYear = date('Y');
    $lastYear = $dateTime->format('Y');
    return $nowYear > $lastYear ? $dateTime->format('j F Y H:i') : $dateTime->format('j F H:i');
}]], 'mail' => ['class' => \rock\mail\Mail::className(), 'From' => 'support@' . (new \rock\request\Request())->getHost(), 'FromName' => 'Rock Framework'], 'url' => ['class' => \rock\url\Url::className()], 'request' => ['class' => \rock\request\Request::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale']], 'response' => ['class' => \rock\response\Response::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale']], 'htmlResponseFormatter' => ['class' => \rock\response\HtmlResponseFormatter::className()], 'jsonResponseFormatter' => ['class' => \rock\response\JsonResponseFormatter::className()], 'xmlResponseFormatter' => ['class' => \rock\response\XmlResponseFormatter::className()], 'rssResponseFormatter' => ['class' => \rock\response\RssResponseFormatter::className()], 'session' => ['class' => \rock\session\Session::className(), 'cookieParams' => ['httponly' => true, 'lifetime' => 60 * 60 * 24 * 60, 'setUseCookies' => \rock\session\Session::USE_ONLY_COOKIES]], 'cookie' => ['class' => \rock\cookie\Cookie::className()], 'security' => ['class' => Security::className()], 'sanitize' => ['class' => \rock\sanitize\Sanitize::className()], 'validate' => ['class' => \rock\validate\Validate::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale']], 'csrf' => ['class' => \rock\csrf\CSRF::className()], 'captcha' => ['class' => \rock\captcha\Captcha::className(), 'length' => 0, 'whiteNoiseDensity' => 1 / 6, 'blackNoiseDensity' => 1 / 30], 'user' => ['class' => \rock\user\User::className(), 'container' => 'user'], 'rbac' => ['class' => \rock\rbac\DBManager::className()], 'log' => ['class' => \rock\log\Log::className()], Role::className() => ['class' => Role::className()], Permission::className() => ['class' => Permission::className()]], require __DIR__ . '/widgets.php');
예제 #6
0
 protected function validateInternal(Validate $validate, $ruleName, $attributeName, $args, $placeholders, $messages)
 {
     if ($validate instanceof ModelValidate) {
         $validate->model = $this->model;
         $validate->attribute = $attributeName;
     }
     // rule
     if ($placeholders) {
         $validate->setPlaceholders($placeholders);
     }
     if ($messages) {
         $validate->setMessages($messages);
     }
     $validate = call_user_func_array([$validate, $ruleName], $args);
     if (!$validate->validate($this->model->{$attributeName})) {
         $this->model->addError($attributeName, $validate->getFirstError());
     }
 }