/** * {@inheritdoc} * * @return void */ public function beforeSave() { // nickname validator $this->addValidator('nickname', v::required()); // group validator $this->addValidator('group', v::required()); // types validator $this->types = explode(',', $this->types); $this->addValidator('types', v::callback(function ($input) { foreach ($input as &$type) { $type = trim($type); } $length = sizeof($input); $types = \Application\MusicTypes\Table::select()->select('type')->where('type IN (?)', $input)->execute(); if (sizeof($types) == $length) { return true; } })->setError('Types does not exist')); // concert_date validator $this->addValidator('concertDate', v::required(), v::date('Y-m-d')); $this->addValidator('alias', v::required(), v::length(2, 64), v::slug(), v::callback(function ($input) { $select = $this->getTable()->select()->where('alias = ?', $input); if ($this->id) { $select->andWhere('id != ?', $this->id); } return !sizeof($select->execute()); })->setError('Musician with alias "{{input}}" already exists')); }
/** * {@inheritdoc} */ protected function beforeInsert() { // unique validator $this->addValidator('key', v::callback(function () { return !$this->getTable()->findRowWhere(['key' => $this->key, 'namespace' => $this->namespace]); })->setError('Key name "{{input}}" already exists')); }
/** * Before Insert/Update * @return void */ protected function beforeSave() { // name validator $this->addValidator('name', v::required()->latin(' ')); // email validator $this->addValidator('email', v::required()->email()); }
/** * Before Update * @return void */ protected function beforeUpdate() { $this->addValidator('name', v::required()->latin(), v::callback(function ($name) { return !in_array(strtolower($name), Table::getInstance()->getBasicRoles()); })->setError('Role "{{input}}" is basic and can\'t be editable'), v::callback(function ($name) { return $this->clean['name'] != $name; })->setError('Role name "{{input}}" the same as original'), v::callback(function ($name) { return !Table::getInstance()->findRowWhere(['name' => $name]); })->setError('Role name "{{input}}" already exists')); }
/** * {@inheritdoc} * * @return void */ public function beforeSave() { // title validator $this->addValidator('title', v::required(), v::length(2, 128)); //description validator $this->addValidator('description', v::required(), v::length(2, 250), v::string()); //category validator $this->addValidator('categoryId', v::required(), v::integer()); //cost validator $this->addValidator('cost', v::required(), v::float(), v::min(0.01, true)); }
/** * @return void */ public function beforeSave() { $this->email = strtolower($this->email); $this->addValidator('login', v::required()->latin()->length(3, 255), v::callback(function ($login) { $user = $this->getTable()->select()->where('login = ?', $login)->andWhere('id != ?', $this->id)->execute(); return !$user; })->setError('User with login "{{input}}" already exists')); $this->addValidator('email', v::required()->email(true), v::callback(function ($email) { $user = $this->getTable()->select()->where('email = ?', $email)->andWhere('id != ?', $this->id)->execute(); return !$user; })->setError('User with email "{{input}}" already exists')); }
/** * {@inheritdoc} * * @return void */ public function beforeSave() { // nickname validator $this->addValidator('nickname', v::required()); // music_type validator $this->addValidator('music_type', v::required()); // group validator $this->addValidator('group', v::required()); // concert_date validator $this->addValidator('concert_date', v::required()); // image validator $this->addValidator('image', v::required()); }
/** * @return void */ public function beforeSave() { $this->addValidator('name', v::required(), v::length(2, 128)); $this->addValidator('alias', v::required(), v::length(2, 64), v::slug(), v::callback(function ($input) { $select = $this->getTable()->select()->where('alias = ?', $input); if ($this->id) { $select->andWhere('id != ?', $this->id); } if ($this->parentId) { $select->andWhere('parentId = ?', $this->parentId); } else { $select->andWhere('parentId IS NULL'); } return !sizeof($select->execute()); })->setError('Category with alias "{{input}}" already exists')); }
/** * {@inheritdoc} * * @return void */ public function beforeSave() { // title validator $this->addValidator('title', v::required()); // alias validator $this->addValidator('alias', v::required(), v::slug(), v::callback(function ($input) { if ($row = $this->getTable()->findRowWhere(['alias' => $input])) { if ($row->id != $this->id) { return false; } } return true; })->setError('Alias "{{input}}" already exists')); // content validator $this->addValidator('content', v::callback(function ($input) { if (empty($input) or trim(strip_tags($input, '<img>')) == '') { return false; } return true; })->setError('Content can\'t be empty')); }
/** * {@inheritdoc} */ protected function beforeSave() { $this->addValidator('title', v::required()->latinNumeric(' -_')); }
/** * beforeInsert * * @return void */ public function beforeSave() { $this->addValidator('name', v::required()->notEmpty()->latin()); $this->addValidator('email', v::required()->notEmpty()->email()); }
/** * Setup multi builder for empty object * @expectedException \Bluz\Validator\Exception\ValidatorException */ public function testValidatorBuilderForEmptySet() { $validator = new ValidatorBuilder(); $validator->add('foo', Validator::required()); $validator->add('bar', Validator::numeric()); $this->assertFalse($validator->validate([])); $this->assertFalse($validator->assert([])); }
/** * {@inheritdoc} * * @return string */ public function beforeSave() { $this->addValidator('type', v::equals('image')); }
/** * Complex test with exception * * @expectedException \Bluz\Validator\Exception\ValidatorException */ public function testAssertComplexRuleValidation() { $validator = Validator::alphaNumeric('_')->length(1, 15)->noWhitespace(); $validator->assert('invalid user name'); }