当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::add方法代码示例

本文整理汇总了PHP中Validator::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::add方法的具体用法?PHP Validator::add怎么用?PHP Validator::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Validator的用法示例。


在下文中一共展示了Validator::add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testValidate

 public function testValidate()
 {
     $className = 'Same\\Class\\Name';
     $validator1 = $this->getMock('Magento\\Framework\\Code\\ValidatorInterface');
     $validator1->expects($this->once())->method('validate')->with($className);
     $validator2 = $this->getMock('Magento\\Framework\\Code\\ValidatorInterface');
     $validator2->expects($this->once())->method('validate')->with($className);
     $this->model->add($validator1);
     $this->model->add($validator2);
     $this->model->validate($className);
 }
开发者ID:ViniciusAugusto,项目名称:magento2,代码行数:11,代码来源:ValidatorTest.php

示例2: array

     $vars['token'] = Csrf::token();
     $vars['user'] = User::find($id);
     $vars['statuses'] = array('inactive' => __('global.inactive'), 'active' => __('global.active'));
     $vars['roles'] = array('administrator' => __('global.administrator'), 'editor' => __('global.editor'), 'user' => __('global.user'));
     return View::create('users/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 Route::post('admin/users/edit/(:num)', function ($id) {
     $input = Input::get(array('username', 'email', 'real_name', 'bio', 'status', 'role'));
     $password_reset = false;
     if ($password = Input::get('password')) {
         $input['password'] = $password;
         $password_reset = true;
     }
     $validator = new Validator($input);
     $validator->add('safe', function ($str) use($id) {
         return $str != 'inactive' and Auth::user()->id == $id;
     });
     $validator->check('username')->is_max(2, __('users.username_missing', 2));
     $validator->check('email')->is_email(__('users.email_missing'));
     if ($password_reset) {
         $validator->check('password')->is_max(6, __('users.password_too_short', 6));
     }
     if ($errors = $validator->errors()) {
         Input::flash();
         Notify::error($errors);
         return Response::redirect('admin/users/edit/' . $id);
     }
     if ($password_reset) {
         $input['password'] = Hash::make($input['password']);
     }
     User::update($id, $input);
开发者ID:pmachowski,项目名称:pm-cms,代码行数:31,代码来源:users.php

示例3: function

     $vars['field'] = $extend;
     $vars['pagetypes'] = Query::table(Base::table('pagetypes'))->sort('key')->get();
     return View::create('extend/fields/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 Route::post('admin/extend/fields/edit/(:num)', function ($id) {
     $input = Input::get(array('type', 'field', 'key', 'label', 'attributes', 'pagetype'));
     if (empty($input['key'])) {
         $input['key'] = $input['label'];
     }
     $input['key'] = slug($input['key'], '_');
     array_walk_recursive($input, function (&$value) {
         $value = eq($value);
     });
     $validator = new Validator($input);
     $validator->add('valid_key', function ($str) use($id, $input) {
         return Extend::where('key', '=', $str)->where('type', '=', $input['type'])->where('id', '<>', $id)->count() == 0;
     });
     $validator->check('key')->is_max(1, __('extend.key_missing'))->is_valid_key(__('extend.key_exists'));
     $validator->check('label')->is_max(1, __('extend.label_missing'));
     if ($errors = $validator->errors()) {
         Input::flash();
         Notify::error($errors);
         return Response::redirect('admin/extend/fields/edit/' . $id);
     }
     if ($input['field'] == 'image') {
         $attributes = Json::encode($input['attributes']);
     } elseif ($input['field'] == 'file') {
         $attributes = Json::encode(array('attributes' => array('type' => $input['attributes']['type'])));
     } else {
         $attributes = '';
     }
开发者ID:anchorcms,项目名称:anchor-cms,代码行数:31,代码来源:fields.php

示例4: function

     // print_r($vars);exit;
     return View::create('posts/add', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
 });
 Route::post('admin/posts/add', function () {
     $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js', 'category', 'status', 'comments', 'company', 'department'));
     // if there is no slug try and create one from the title
     if (empty($input['slug'])) {
         $input['slug'] = $input['title'];
     }
     // convert to ascii
     $input['slug'] = slug($input['slug']);
     // encode title
     $input['title'] = e($input['title'], ENT_COMPAT);
     $validator = new Validator($input);
     $validator->add('duplicate', function ($str) {
         return Post::where('slug', '=', $str)->count() == 0;
     });
     $validator->check('title')->is_max(3, __('posts.title_missing'));
     $validator->check('slug')->is_max(3, __('posts.slug_missing'))->is_duplicate(__('posts.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('posts.slug_invalid'));
     if ($errors = $validator->errors()) {
         Input::flash();
         Notify::error($errors);
         return Response::redirect('admin/posts/add');
     }
     if (empty($input['created'])) {
         $input['created'] = Date::mysql('now');
     }
     $user = Auth::user();
     $input['author'] = $user->id;
     if (is_null($input['comments'])) {
         $input['comments'] = 0;
开发者ID:pepfi,项目名称:anchor-cms,代码行数:31,代码来源:posts.php

示例5: function

 /*
     Edit Var
 */
 Route::get('admin/extend/pagetypes/edit/(:any)', function ($key) {
     $vars['token'] = Csrf::token();
     $vars['pagetype'] = Query::table(Base::table('pagetypes'))->where('key', '=', $key)->fetch();
     return View::create('extend/pagetypes/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 Route::post('admin/extend/pagetypes/edit/(:any)', function ($key) {
     $input = Input::get(array('key', 'value'));
     $input['key'] = slug($input['key'], '_');
     $validator = new Validator($input);
     $validator->add('valid_key', function ($str) use($key) {
         // no change
         if ($str == $key) {
             return true;
         }
         // check the new key $str is available
         return Query::table(Base::table('pagetypes'))->where('key', '=', $str)->count() == 0;
     });
     $validator->check('key')->is_max(2, __('extend.key_missing'))->is_valid_key(__('extend.key_exists'));
     $validator->check('value')->is_max(1, __('extend.name_missing'));
     if ($errors = $validator->errors()) {
         Input::flash();
         Notify::error($errors);
         return Response::redirect('admin/extend/pagetypes/edit/' . $key);
     }
     Query::table(Base::table('pagetypes'))->where('key', '=', $key)->update($input);
     Notify::success(__('extend.pagetype_updated'));
     return Response::redirect('admin/extend/pagetypes');
 });
 /*
开发者ID:anchorcms,项目名称:anchor-cms,代码行数:32,代码来源:pagetypes.php

示例6: array

    return Response::redirect('admin/login');
});
/*
	Amnesia
*/
Route::get('admin/amnesia', array('before' => 'guest', 'main' => function () {
    $vars['messages'] = Notify::read();
    $vars['token'] = Csrf::token();
    return View::create('users/amnesia', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
}));
Route::post('admin/amnesia', array('before' => 'csrf', 'main' => function () {
    $email = Input::get('email');
    $validator = new Validator(array('email' => $email));
    $query = User::where('email', '=', $email);
    $validator->add('valid', function ($email) use($query) {
        return $query->count();
    });
    $validator->check('email')->is_email(__('users.email_missing'))->is_valid(__('users.email_not_found'));
    if ($errors = $validator->errors()) {
        Input::flash();
        Notify::error($errors);
        return Response::redirect('admin/amnesia');
    }
    $user = $query->fetch();
    Session::put('user', $user->id);
    $token = noise(8);
    Session::put('token', $token);
    $uri = Uri::full('admin/reset/' . $token);
    $subject = __('users.recovery_subject');
    $msg = __('users.recovery_message', $uri);
    mail($user->email, $subject, $msg);
开发者ID:Rictus,项目名称:CMS_Prod,代码行数:31,代码来源:admin.php

示例7: array

     // extended fields
     $vars['fields'] = Extend::fields('post', $id);
     $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived'));
     return View::create('publications/editPublication', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor');
 });
 Route::post('admin/publications/editPublication/(:num)', function ($id) {
     $currentPageCategoryId = getCurrentPageCategoryId('publication');
     $input = Input::get(array('title', 'slug', 'description', 'created', 'html', 'css', 'js', 'category', 'status', 'comments'));
     /** Valeurs en dur **/
     $input['comments'] = 0;
     $input['category'] = $currentPageCategoryId;
     // encode title
     $input['title'] = e($input['title'], ENT_COMPAT);
     $validator = new Validator($input);
     $validator->add('duplicate', function ($str) use($id) {
         return Post::where('slug', '=', $str)->where('id', '<>', $id)->count() == 0;
     });
     if (is_null($input['description']) || empty($input['description'])) {
         $input['description'] = " ";
     }
     if (is_null($input['css']) || empty($input['css'])) {
         $input['css'] = " ";
     }
     if (is_null($input['js']) || empty($input['js'])) {
         $input['js'] = " ";
     }
     // if there is no slug, create one from title
     if (empty($input['slug'])) {
         $input['slug'] = slug($input['title']);
     }
     // convert to ascii
开发者ID:Rictus,项目名称:CMS_Prod,代码行数:31,代码来源:publications.php

示例8: isValid

 /**
  * Runs all of the validation checks on the elements using the
  * validatiors that are stored
  *
  * @return bool
  */
 public function isValid()
 {
     if ($this->csrfToken === true && !$this->_input->checkToken()) {
         // CSRF protection failed!
         if ($this->storeErrors === true) {
             $this->_event->error(Input::csrfMsg());
         }
         return false;
     }
     foreach ($this->elements as $element) {
         try {
             $value = $this->_input->get($element['input_name'], $element['source']);
         } catch (Input_KeyNoExist $e) {
             if ($element['required'] === true) {
                 throw $e;
             } else {
                 continue;
             }
         }
         // Store the input names value correclty as a multi-dimensional array
         $tmpVal = $value;
         foreach (array_reverse(preg_split('#(?<!\\\\)/#', trim($element['input_name'], '/'))) as $v) {
             $tmpVal = array($v => $tmpVal);
         }
         $this->values = zula_merge_recursive($this->values, $tmpVal);
         $count = is_array($value) ? count($value) : strlen($value);
         if ($element['required'] === false && $count == 0) {
             continue;
         }
         // Check if it is valid
         $validator = new Validator($value, $element['title']);
         foreach (array_filter($element['validators']) as $tmpValidator) {
             $validator->add($tmpValidator);
         }
         if ($validator->validate() === false) {
             $this->valid = false;
             if ($this->storeErrors === true) {
                 // Store all errors (if any)
                 foreach ($validator->getErrors() as $error) {
                     $this->_event->error($error);
                 }
             }
         }
     }
     // Check if the antispam was successful, if enabled
     if ($this->valid && $this->antispam === true) {
         $antispam = new Antispam();
         if (!$antispam->check()) {
             $this->valid = false;
             if ($this->storeErrors === true) {
                 $this->_event->error(t('Sorry, incorrect answer to the captcha', I18n::_DTD));
             }
         }
     }
     return $this->valid;
 }
开发者ID:jinshana,项目名称:tangocms,代码行数:62,代码来源:Form.php


注:本文中的Validator::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。