Пример #1
0
 /**
  * @depends testArrayFormat
  */
 public function testValidate()
 {
     $validator = new EachValidator(['rule' => ['integer']]);
     $this->assertTrue($validator->validate([1, 3, 8]));
     $this->assertFalse($validator->validate([1, 'text', 8]));
 }
Пример #2
0
 /**
  * @return array
  */
 public function rules()
 {
     return [[['name', 'shortName'], 'required'], ['companyId', 'exist', 'targetClass' => Company::className(), 'targetAttribute' => '_id'], ['ahuConfirmation', 'boolean'], ['ahuConfirmation', 'filter', 'filter' => function ($value) {
         return boolval($value);
     }], ['confirmPersonId', 'exist', 'targetClass' => User::className(), 'targetAttribute' => '_id'], ['supportEmailsInput', function ($attribute) {
         if ($this->{$attribute} === "") {
             $this->supportEmails = [];
             return;
         }
         $value = explode(';', trim($this->{$attribute}, ';'));
         $validator = new EachValidator(['rule' => ['email']]);
         if ($validator->validate($value)) {
             $this->supportEmails = $value;
         } else {
             $this->addError($attribute, "Неверный формат");
         }
     }, 'skipOnEmpty' => false], ['ipAddress', 'match', 'pattern' => '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'], [['phone', 'contact', 'model', 'gatekeeperNumber', 'note'], 'safe'], [['companyId', 'confirmPersonId'], MongoIdValidator::className(), 'forceFormat' => 'object']];
 }