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


PHP Validator::validate方法代码示例

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


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

示例1: testValidator

 /**
  * @param mixed $entity
  * @param bool $valid
  * @dataProvider validatorDataProvider
  */
 public function testValidator($entity, $valid)
 {
     $errors = $this->validator->validate($entity);
     if ($valid) {
         $this->assertCount(0, $errors, 'Entity should be valid: ' . var_export($entity, true));
         $this->assertNull($entity->getId());
     } else {
         $this->assertGreaterThan(0, count($errors), 'Entity should not be valid: ' . var_export($entity, true));
     }
 }
开发者ID:cegeka,项目名称:symfony-toolkit,代码行数:15,代码来源:ValidationBase.php

示例2: save

 /**
  * sava data object to database
  *
  * @throws ValidatorException it is thrown if objects data are wrong
  */
 public function save()
 {
     self::setUpConnection();
     $this->_validator->validate($this);
     if (isset($this->_data['id']) && is_numeric($this->_data['id'])) {
         $this->update();
     } else {
         $this->insert();
     }
 }
开发者ID:pafciu17,项目名称:gsoc-os-static-maps-api,代码行数:15,代码来源:DatabaseObject.php

示例3: 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

示例4: isAllowed

 /**
  * Checks if a locale is allowed and valid
  *
  * @param string $locale
  *
  * @return bool
  */
 public function isAllowed($locale)
 {
     if ($this->validator instanceof ValidatorInterface2dot5) {
         $errorListLocale = $this->validator->validate($locale, new Locale());
         $errorListLocaleAllowed = $this->validator->validate($locale, new LocaleAllowed());
     } else {
         $errorListLocale = $this->validator->validateValue($locale, new Locale());
         $errorListLocaleAllowed = $this->validator->validateValue($locale, new LocaleAllowed());
     }
     return count($errorListLocale) == 0 && count($errorListLocaleAllowed) == 0;
 }
开发者ID:hason,项目名称:LocaleBundle,代码行数:18,代码来源:MetaValidator.php

示例5: testValidateObject

 /**
  * @dataProvider getObjectsToValidate
  */
 public function testValidateObject($object, $violationCount, $groups = array())
 {
     if (0 === count($groups)) {
         $groups = null;
     }
     if ($this->validator instanceof ValidatorInterface) {
         $this->assertEquals($violationCount, $this->validator->validate($object, null, $groups)->count());
     } else {
         $this->assertEquals($violationCount, $this->validator->validate($object, $groups)->count());
     }
 }
开发者ID:php-xapi,项目名称:validation,代码行数:14,代码来源:AbstractModelValidatorTest.php

示例6: validate

 public function validate($form, $field = NULL)
 {
     parent::validate($form, $field);
     reset($this->rules);
     $nan = key($this->rules);
     next($this->rules);
     $min = key($this->rules);
     next($this->rules);
     $max = key($this->rules);
     next($this->rules);
     $val = $field->value();
     if (isset($val) && !is_numeric($val)) {
         $this->errors[] = $this->rules[$nan];
         return FALSE;
     }
     if (isset($val) && $val < $min) {
         $this->errors[] = $this->rules[$min];
         return FALSE;
     }
     if (isset($val) && $val > $max) {
         $this->errors[] = $this->rules[$max];
         return FALSE;
     }
     return TRUE;
 }
开发者ID:seanmorris,项目名称:form,代码行数:25,代码来源:Range.php

示例7: validate

 /**
  * Processing that occurs before a form is executed.
  *
  * This includes form validation, if it fails, we redirect back
  * to the form with appropriate error messages.
  * Always return true if the current form action is exempt from validation
  *
  * Triggered through {@link httpSubmission()}.
  *
  * Note that CSRF protection takes place in {@link httpSubmission()},
  * if it fails the form data will never reach this method.
  *
  * @return boolean
  */
 public function validate()
 {
     $buttonClicked = $this->buttonClicked();
     if ($buttonClicked && in_array($buttonClicked->actionName(), $this->getValidationExemptActions())) {
         return true;
     }
     if ($this->validator) {
         $errors = $this->validator->validate();
         if ($errors) {
             // Load errors into session and post back
             $data = $this->getData();
             // Encode validation messages as XML before saving into session state
             // As per Form::addErrorMessage()
             $errors = array_map(function ($error) {
                 // Encode message as XML by default
                 if ($error['message'] instanceof DBField) {
                     $error['message'] = $error['message']->forTemplate();
                 } else {
                     $error['message'] = Convert::raw2xml($error['message']);
                 }
                 return $error;
             }, $errors);
             Session::set("FormInfo.{$this->FormName()}.errors", $errors);
             Session::set("FormInfo.{$this->FormName()}.data", $data);
             return false;
         }
     }
     return true;
 }
开发者ID:XDdesigners,项目名称:silverstripe-framework,代码行数:43,代码来源:Form.php

示例8: sendEmail

 public function sendEmail()
 {
     try {
         $emails = explode(',', $this->_correo);
         $to = [];
         foreach ($emails as $email) {
             $params = ['mail' => ['requerido' => 1, 'validador' => 'esEmail', 'mensaje' => utf8_encode('El correo no es v&aacute;lido.')]];
             $destinatario = ['name' => $email, 'mail' => $email];
             $form = new Validator($destinatario, $params);
             if ($form->validate() === false) {
                 throw new Exception('El correo ' . $email . ' no es v&aacute;lido.');
             }
             $to[] = $destinatario;
         }
         $this->_template = ParserTemplate::parseTemplate($this->_template, $this->_info);
         // $subject = '', $body = '', $to = array(), $cc = array(), $bcc = array(), $att = array()
         if (Mailer::sendMail($this->_subject, $this->_template, $to, $this->_cc)) {
             return true;
         } else {
             return false;
         }
     } catch (phpmailerException $e) {
         $this->_PDOConn->rollBack();
         return false;
     }
 }
开发者ID:alfabrad,项目名称:kidzania-coupon,代码行数:26,代码来源:Contact.php

示例9: edit

 public static function edit($data)
 {
     $p = array('title' => array('required' => true, 'type' => 'string', 'maxlength' => 140, 'label' => 'Titulo'), 'text' => array('required' => true, 'type' => 'string', 'label' => 'Texto'), 'image' => array('required' => false, 'type' => 'thumbnail', 'label' => 'Imagen'), 'tags' => array('required' => false, 'type' => 'string', 'label' => 'Tags'));
     $v = new Validator();
     $response = $v->validate($data, $p);
     if (!$response['success']) {
         return M::cr(false, $data, $response['msg']);
     }
     PDOSql::$pdobj = pdoConnect();
     if (isset($_FILES['image']['name'])) {
         $response = File::up2Web($_FILES['image']);
         if ($response->success) {
             // remove old image...
             if (isset($data['old_image'])) {
                 File::unlinkWeb($data['old_image']);
             }
             $image = $response->data[0];
         } else {
             return M::cr(false, $data, $response->msg);
         }
     } else {
         $image = '';
     }
     $params = array($data['title'], $data['text'], $image, $data['tags'], $data['id'], $_SESSION['userNAME']);
     $where = array(' id = ?', 'author = ?');
     $query = "UPDATE entries SET title = ?, text = ?, image = ?, tags = ? {%WHERE%}";
     PDOSql::update($query, $params, $where);
     return M::cr(true, array(), 'Se han actualizado los datos correctamente');
 }
开发者ID:scabros,项目名称:scabrosfw,代码行数:29,代码来源:Entries.php

示例10: validate

 static function validate(&$values, $validators, $defaults = array(), $names = array())
 {
     $filtered_values = array();
     foreach ($validators as $name => $options) {
         if (!isset($values[$name])) {
             $values[$name] = null;
         }
         if (!$options) {
             $options = array();
         }
         $validator = new Validator($options);
         $validator->setOption('required', true);
         if (!isset($options['array']) || $options['array'] === false) {
             $valid = !is_array($values[$name]) && $validator->validate($values[$name]);
         } else {
             $valid = is_array($values[$name]) && $validator->validateArray($values[$name]);
         }
         $key_name = isset($names[$name]) ? $names[$name] : $name;
         if ($valid) {
             $filtered_values[$key_name] = $values[$name];
         } else {
             if (isset($defaults[$name])) {
                 $filtered_values[$key_name] = $defaults[$name];
             } else {
                 $filtered_values[$key_name] = null;
             }
         }
     }
     return $values = $filtered_values;
 }
开发者ID:RNKushwaha022,项目名称:orange-php,代码行数:30,代码来源:filter.helper.php

示例11: getLabel

 /**
  * Get a delivery label for a parcel and a recipient
  *
  * @param array   $parcel
  * @param array   $recipient
  * @param array   $sender
  * @param boolean $validate
  *
  * @throws InvalidRequestException
  * @throws FailedRequestException
  * @throws \SoapFault
  *
  * @return ReturnLetter
  */
 public function getLabel(array $parcel, array $recipient, array $sender = array(), $validate = true)
 {
     $request = $this->buildLetterColissimoRequest($parcel, $recipient, $sender);
     if ($validate) {
         $violations = $this->validator->validate($request->getLetter());
         if ($violations->count() > 0) {
             $exception = new InvalidRequestException('The request is not valid, please check the violations list');
             $exception->setViolations($violations);
             throw $exception;
         }
     }
     $response = $this->client->getLetterColissimo($request);
     if (!$response->isSuccess()) {
         throw new FailedRequestException($response->getErrorMessage());
     }
     return $response->getReturnLetter();
 }
开发者ID:nopr0n,项目名称:LexikColissimoBundle,代码行数:31,代码来源:WSColiPosteLetterService.php

示例12: validate

 public function validate($form, $field = NULL)
 {
     parent::validate($form, $field);
     $value = $field->value();
     if (isset($value) && !filter_var($value, FILTER_VALIDATE_EMAIL)) {
         $this->errors[] = $this->errorMessage;
     }
     return !$this->errors;
 }
开发者ID:seanmorris,项目名称:form,代码行数:9,代码来源:Email.php

示例13: isValid

 public function isValid()
 {
     $validator = new Validator($this->getData());
     $check = $validator->validate($this->getRules());
     if (!$check) {
         $this->setErrors($validator->errors);
     }
     return $check;
 }
开发者ID:AlexSmerw,项目名称:domino,代码行数:9,代码来源:Form.class.php

示例14: form_handler

 public function form_handler()
 {
     $validator = new Validator($_POST);
     $validator->setRules('name', 'Name', 'minLength[4]|maxLength[8]');
     $validator->setRules('date', 'Date', 'dateRange[ 12/27/10, 12/28/10 ]');
     if ($validator->validate()) {
         $validator->storeSuccessMessage('Success!');
     }
     Util::redirect('admin', true);
 }
开发者ID:karthikv,项目名称:silent-boss,代码行数:10,代码来源:admin.php

示例15: validate

 public function validate($form, $field = NULL)
 {
     parent::validate($form, $field);
     $value = $field->value();
     foreach ($this->rules as $rule => $error) {
         if (isset($value) && !preg_match($rule, $value)) {
             $this->errors[] = $error;
         }
     }
     return !$this->errors;
 }
开发者ID:seanmorris,项目名称:form,代码行数:11,代码来源:Regex.php


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