本文整理汇总了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));
}
}
示例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();
}
}
示例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);
}
示例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;
}
示例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());
}
}
示例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;
}
示例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;
}
示例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álido.')]];
$destinatario = ['name' => $email, 'mail' => $email];
$form = new Validator($destinatario, $params);
if ($form->validate() === false) {
throw new Exception('El correo ' . $email . ' no es vá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;
}
}
示例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');
}
示例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;
}
示例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();
}
示例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;
}
示例13: isValid
public function isValid()
{
$validator = new Validator($this->getData());
$check = $validator->validate($this->getRules());
if (!$check) {
$this->setErrors($validator->errors);
}
return $check;
}
示例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);
}
示例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;
}