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


PHP Validation::getLabel方法代码示例

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


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

示例1: validate

 /**
  * @param \Phalcon\Validation $validation
  * @param string              $field
  *
  * @return boolean
  *
  * @throws \Phalcon\Validation\Exception
  */
 public function validate(\Phalcon\Validation $validation, $field)
 {
     if (!is_string($field)) {
         throw new \Phalcon\Validation\Exception("Field name must be a string");
     }
     $label = $this->getOption("label");
     if (empty($label)) {
         $label = $validation->getLabel($field);
     }
     $value = $validation->getValue($field);
     if ($this->isSetOption("allowEmpty") && empty($value)) {
         return true;
     }
     // http://stackoverflow.com/questions/1418423/the-hostname-regex
     if (!preg_match('/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\\.?$/', $value)) {
         $message = $this->getOption("message");
         if (empty($message)) {
             $message = "Field :field is not a valid hostname";
         }
         $replacePairs = [":field" => $label];
         $validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Hostname"));
         return false;
     }
     return true;
 }
开发者ID:sidroberts,项目名称:phalcon-validators,代码行数:33,代码来源:Hostname.php

示例2: validate

 /**
  * Executes the validation
  *
  * @package     base-app
  * @version     2.0
  *
  * @param object $validation Phalcon\Validation
  * @param string $field field name
  *
  * @return boolean
  *
  * @throws \Phalcon\Validation\Exception
  */
 public function validate(\Phalcon\Validation $validation, $field)
 {
     $value = $validation->getValue($field);
     $model = $this->getOption("model");
     $attribute = $this->getOption("attribute");
     if (empty($model)) {
         throw new \Phalcon\Validation\Exception("Model must be set");
     }
     if (empty($attribute)) {
         $attribute = $field;
     }
     if ($except = $this->getOption('except')) {
         $number = $model::count(array($attribute . "=:value: AND " . $attribute . "!= :except:", "bind" => array("value" => $value, 'except' => $except)));
     } else {
         $number = $model::count(array($attribute . "=:value:", "bind" => array("value" => $value)));
     }
     if ($number) {
         $label = $this->getOption("label");
         if (empty($label)) {
             $label = $validation->getLabel($field);
             if (empty($label)) {
                 $label = $field;
             }
         }
         $message = $this->getOption("message");
         $replacePairs = array(":field" => $label);
         if (empty($message)) {
             $message = $validation->getDefaultMessage("Uniqueness");
         }
         $validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Uniqueness"));
         return false;
     }
     return true;
 }
开发者ID:al35mm,项目名称:Phalcon-Rocket,代码行数:47,代码来源:Uniqueness.php

示例3: validate

 /**
  * {@inheritdoc}
  *
  * @param Validation $validation
  * @param string $attribute
  *
  * @return bool
  * @throws Exception
  */
 public function validate(Validation $validation, $attribute)
 {
     $value = $validation->getValue($attribute);
     $field = $this->getOption('label');
     if (empty($field)) {
         $validation->getLabel($attribute);
     }
     if (false === $this->hasOption('places')) {
         throw new Exception('A number of decimal places must be set');
     }
     if ($this->hasOption('digits')) {
         // Specific number of digits
         $digits = '{' . (int) $this->getOption('digits') . '}';
     } else {
         // Any number of digits
         $digits = '+';
     }
     if ($this->hasOption('point')) {
         $decimal = $this->getOption('point');
     } else {
         // Get the decimal point for the current locale
         list($decimal) = array_values(localeconv());
     }
     $result = (bool) preg_match(sprintf('#^[+-]?[0-9]%s%s[0-9]{%d}$#', $digits, preg_quote($decimal), $this->getOption('places')), $value);
     if (!$result) {
         $message = $this->getOption('message');
         $replacePairs = [':field' => $field];
         if (empty($message)) {
             $message = ':field must contain valid decimal value';
         }
         $validation->appendMessage(new Message(strtr($message, $replacePairs), $attribute, 'Decimal'));
         return false;
     }
     return true;
 }
开发者ID:phalcon,项目名称:incubator,代码行数:44,代码来源:Decimal.php

示例4: validate

 /**
  * {@inheritdoc}
  *
  * @param Validation $validation
  * @param string     $attribute
  *
  * @return bool
  */
 public function validate(Validation $validation, $attribute)
 {
     $secret = $this->getOption('secret');
     $value = $validation->getValue($attribute);
     $request = $validation->getDI()->get('request');
     $remoteIp = $request->getClientAddress(false);
     if (!empty($value)) {
         $curl = curl_init(self::RECAPTCHA_URL);
         curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => ['secret' => $secret, 'response' => $value, 'remoteip' => $remoteIp]]);
         $response = json_decode(curl_exec($curl), true);
         curl_close($curl);
     }
     if (empty($response['success'])) {
         $label = $this->getOption('label');
         if (empty($label)) {
             $label = $validation->getLabel($attribute);
         }
         $message = $this->getOption('message');
         $replacePairs = [':field', $label];
         if (empty($message) && !empty($response['error-codes'])) {
             $message = $this->messages[$response['error-codes']];
         }
         if (empty($message)) {
             $message = $validation->getDefaultMessage('ReCaptcha');
         }
         $validation->appendMessage(new Message(strtr($message, $replacePairs), $attribute, 'ReCaptcha'));
         return false;
     }
     return true;
 }
开发者ID:phalcon,项目名称:incubator,代码行数:38,代码来源:ReCaptcha.php

示例5: validate

 /**
  * 校验大小
  *
  * @param Validation $validation
  * @param string     $field
  * @return bool
  */
 public function validate(Validation $validation, $field)
 {
     $value = $validation->getValue($field);
     $size = $this->getOption('size');
     //判断是否为数字
     if (is_numeric($value)) {
         if ($value != $size) {
             $label = $this->getOption("label");
             if (!$label) {
                 $label = $validation->getLabel($field);
             }
             $message = $this->getOption("message");
             $replacePairs = [':field' => $label, ':size' => $size];
             if (!$message) {
                 $message = ':field size must be equal to :size';
             }
             $validation->appendMessage(new Message(strtr($message, $replacePairs), $field, 'Size'));
         }
         return true;
     }
     //是否为字符串
     if (is_string($value)) {
         $strLen = function_exists('mb_strlen') ? mb_strlen($value) : strlen($value);
         if ($strLen != $size) {
             $label = $this->getOption("label");
             if (!$label) {
                 $label = $validation->getLabel($field);
             }
             $message = $this->getOption("message");
             $replacePairs = [':field' => $label, ':size' => $size];
             if (!$message) {
                 $message = ':field string length must be equal to :size';
             }
             $validation->appendMessage(new Message(strtr($message, $replacePairs), $field, 'Size'));
         }
     }
     return true;
 }
开发者ID:fangzhoou,项目名称:matrix,代码行数:45,代码来源:Size.php

示例6: validate

 /**
  * 校验是否在大于等于某个日期
  *
  * @param Validation $validation
  * @param string     $field
  * @return bool
  */
 public function validate(Validation $validation, $field)
 {
     $value = $validation->getValue($field);
     if (!$value && $this->getOption('allowEmpty')) {
         return true;
     }
     //判断是否为日期格式数据
     $after = $this->getOption('after');
     if (!$this->checkDate($value, $this->getOption('format')) || !$after || !$this->checkDate($after, $this->getOption('format'))) {
         if (!($label = $this->getOption("label"))) {
             $label = $validation->getLabel($field);
         }
         $after = $this->getOption("after");
         $message = $this->getOption("message");
         $replacePairs = [':field' => $label, ':after' => $after];
         if (!$message) {
             $message = ':field or :after is not a valid date format';
         }
         $validation->appendMessage(new Message(strtr($message, $replacePairs), $field, 'After'));
         return false;
     }
     //校验时间是否正确
     if (strtotime($value) < strtotime($after)) {
         if (!($label = $this->getOption("label"))) {
             $label = $validation->getLabel($field);
         }
         $after = $this->getOption("after");
         $message = $this->getOption("message");
         $replacePairs = [':field' => $label, ':after' => $after];
         if (!$message) {
             $message = 'Time :field must after :after';
         }
         $validation->appendMessage(new Message(strtr($message, $replacePairs), $field, 'After'));
     }
     return true;
 }
开发者ID:fangzhoou,项目名称:matrix,代码行数:43,代码来源:After.php

示例7: validate

 /**
  * Executes the namespaces validation
  *
  * @param Validation $validation
  * @param string     $field
  *
  * @return bool
  */
 public function validate(Validation $validation, $field)
 {
     $value = $validation->getValue($field);
     if ($this->isSetOption('allowEmpty') && empty($value)) {
         return true;
     }
     $re = '#^(?:(?:\\\\)?[a-z](?:[a-z0-9_]+)?)+(?:\\\\(?:[a-z](?:[a-z0-9_]+)?)+)*$#i';
     if (false === (bool) preg_match($re, $value)) {
         $label = $this->getOption('label') ?: $validation->getLabel($field);
         $message = $this->getOption('message') ?: 'Invalid namespace syntax!';
         $replacePairs = array(':field' => $label);
         $validation->appendMessage(new Message(strtr($message, $replacePairs), $field, 'Namespaces'));
         return false;
     }
     return true;
 }
开发者ID:seiven,项目名称:phalcon-devtools,代码行数:24,代码来源:Namespaces.php

示例8: validate

 /**
  * 校验字符串最小长度
  *
  * @param Validation $validation
  * @param string     $field
  * @return bool
  */
 public function validate(Validation $validation, $field)
 {
     $value = $validation->getValue($field);
     $strLen = function_exists('mb_strlen') ? mb_strlen($value) : strlen($value);
     $min = (int) $this->getOption('min');
     if ($strLen < $min) {
         $label = $this->getOption("label");
         if (!$label) {
             $label = $validation->getLabel($field);
         }
         $message = $this->getOption("message");
         $replacePairs = [':field' => $label, ':min' => $min];
         if (!$message) {
             $message = ':field string length must not be lesser than :min';
         }
         $validation->appendMessage(new Message(strtr($message, $replacePairs), $field, 'Min'));
     }
     return true;
 }
开发者ID:fangzhoou,项目名称:matrix,代码行数:26,代码来源:Min.php

示例9: validate

 /**
  * 验证字段类型是否为数组
  *
  * @param Validation $validation
  * @param     string $field
  * @return bool
  */
 public function validate(Validation $validation, $field)
 {
     $value = $validation->getValue($field);
     if (is_array($value)) {
         return true;
     }
     if (!($label = $this->getOption('label'))) {
         $label = $validation->getLabel($field);
     }
     if (!($message = $this->getOption('message'))) {
         $message = ':field must be an array';
     }
     $replacePairs = [':field' => $label];
     $code = $this->getOption('code');
     if (is_array($code)) {
         $code = $code[$field];
     }
     $validation->appendMessage(new Message(strtr($message, $replacePairs), $field, 'Arr', $code));
     return false;
 }
开发者ID:fangzhoou,项目名称:matrix,代码行数:27,代码来源:Arr.php

示例10: validate

 /**
  * @param \Phalcon\Validation $validation
  * @param string              $field
  *
  * @return boolean
  *
  * @throws \Phalcon\Validation\Exception
  */
 public function validate(\Phalcon\Validation $validation, $field)
 {
     if (!is_string($field)) {
         throw new \Phalcon\Validation\Exception("Field name must be a string");
     }
     $label = $this->getOption("label");
     if (empty($label)) {
         $label = $validation->getLabel($field);
     }
     $value = $validation->getValue($field);
     if ($this->isSetOption("allowEmpty") && empty($value)) {
         return true;
     }
     if (!preg_match("/^\\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[1-5][A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{12}\\}?\$/i", $value)) {
         $message = $this->getOption("message");
         if (empty($message)) {
             $message = "Field :field must be a valid UUID";
         }
         $replacePairs = [":field" => $label];
         $validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Uuid"));
         return false;
     }
     $allowedVersions = $this->getOption("allowedVersions");
     if (empty($allowedVersions)) {
         $allowedVersions = [1, 2, 3, 4, 5];
     }
     if (!in_array(substr($value, 14, 1), $allowedVersions)) {
         $message = $this->getOption("messageVersion");
         if (empty($message)) {
             $message = "Field :field must be one of the following UUID versions: :versions";
         }
         $replacePairs = [":field" => $label, ":versions" => implode(", ", $allowedVersions)];
         $validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Uuid"));
         return false;
     }
     return true;
 }
开发者ID:sidroberts,项目名称:phalcon-validators,代码行数:45,代码来源:Uuid.php

示例11: validate

 /**
  * @param \Phalcon\Validation $validation
  * @param string              $field
  *
  * @return boolean
  *
  * @throws \Phalcon\Validation\Exception
  */
 public function validate(\Phalcon\Validation $validation, $field)
 {
     if (!is_string($field)) {
         throw new \Phalcon\Validation\Exception("Field name must be a string");
     }
     $label = $this->getOption("label");
     if (empty($label)) {
         $label = $validation->getLabel($field);
     }
     $value = $validation->getValue($field);
     if ($this->isSetOption("allowEmpty") && empty($value)) {
         return true;
     }
     if (!in_array($value, \DateTimeZone::listIdentifiers())) {
         $message = $this->getOption("message");
         if (empty($message)) {
             $message = "Field :field is not a valid timezone";
         }
         $replacePairs = [":field" => $label];
         $validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Timezone"));
         return false;
     }
     return true;
 }
开发者ID:sidroberts,项目名称:phalcon-validators,代码行数:32,代码来源:Timezone.php


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