示例#1
0
 /**
  * Get status code from response
  * @param string $response Response
  * @return string Status message
  */
 public function getMessage($response)
 {
     if ($response == 'OK') {
         return 'OK';
     } else {
         if (Strings::startsWith($response, 'ERROR ') && Validators::isInRange(explode(' ', $response)[1], [1, 18])) {
             return explode(';', $response)[1];
         } else {
             throw new \InvalidArgumentException('Invalid response');
         }
     }
 }
示例#2
0
 /**
  * @throws ImageStorageException
  * @return array
  */
 public function getSettings()
 {
     if (!$this->settings) {
         $config = $this->validateConfig($this->defaults);
         $config['wwwDir'] = Nette\DI\Helpers::expand($config['wwwDir'], $this->getContainerBuilder()->parameters);
         // Validation
         $quality = $config['quality'];
         if (!is_int($quality) || !Validators::isInRange($quality, [0, 100])) {
             throw new ImageStorageException('Quality must be an integer from 0 to 100.');
         }
         foreach ($config['events'] as $name => &$array) {
             Validators::assert($array, 'array');
         }
         foreach ($config['helpers'] as $name => $class) {
             if (!class_exists($class) || $class instanceof IHelper) {
                 throw new ImageStorageException("Helper {$name} must be instance of " . IHelper::class);
             }
         }
         $this->settings = $config;
     }
     return $this->settings;
 }
示例#3
0
 /**
  * Count/length validator. Range is array, min and max length pair.
  * @return bool
  */
 public static function validateLength(IControl $control, $range)
 {
     if (!is_array($range)) {
         $range = array($range, $range);
     }
     $value = $control->getValue();
     return Validators::isInRange(is_array($value) ? count($value) : Strings::length($value), $range);
 }
示例#4
0
 /**
  * Rangle validator: is a control's value number in specified range?
  * @param  TextBase
  * @param  array  min and max value pair
  * @return bool
  */
 public static function validateRange(TextBase $control, $range)
 {
     return Validators::isInRange($control->getValue(), $range);
 }
示例#5
0
 /**
  * Rangle validator: is a control's value number in specified range?
  * @param  Nette\Forms\IControl
  * @param  array  min and max value pair
  * @return bool
  */
 public static function validateRange(IControl $control, $range)
 {
     return Nette\Utils\Validators::isInRange($control->getValue(), $range);
 }
 /**
  * @param UploadControl $control
  * @param $range
  * @return bool
  */
 public static function validateRange(UploadControl $control, $range)
 {
     $files = count($control->getValue());
     return Validators::isInRange($files, $range);
 }
示例#7
0
文件: Core.php 项目: geniv/goodflow
 /**
  * kontrola datumu v rozsahu
  * @param  [type]  $from  od
  * @param  [type]  $to    do
  * @param  [type]  $value now
  * @return boolean        [description]
  */
 public static function isDateInRange($from, $to, $value = null)
 {
     $d1 = new \DateTime($from);
     $d2 = new \DateTime($to);
     $now = new \DateTime($value);
     if ($from && $to) {
         return \Nette\Utils\Validators::isInRange($now, array($d1, $d2));
     }
     return false;
 }
示例#8
0
 public static function isLengthBetween($string, $minLength, $maxLength)
 {
     return Validators::isInRange(Strings::length($string), array($minLength, $maxLength));
 }
示例#9
0
Validators::isNumeric(static::filterFloat($control->getValue()));}static
function
validateRange(TextBase$control,$range){return
Validators::isInRange($control->getValue(),$range);}static
示例#10
0
 /**
  * @param int $quality
  * @return PropertyAccess
  * @throws WebChemistry\Images\ImageStorageException
  */
 public function setQuality($quality)
 {
     if (!is_int($quality)) {
         throw new WebChemistry\Images\ImageStorageException(printf('Parameter quality must be integer, %s given.', gettype($quality)));
     } else {
         if (!Nette\Utils\Validators::isInRange($quality, [0, 100])) {
             throw new WebChemistry\Images\ImageStorageException('Quality must be value in range 0 - 100.');
         }
     }
     $this->quality = $quality;
     return $this;
 }
示例#11
0
 /**
  * Length validator: is control's value length in range?
  * @param  TextBase
  * @param  array  min and max length pair
  * @return bool
  */
 public static function validateLength(TextBase $control, $range)
 {
     if (!is_array($range)) {
         $range = array($range, $range);
     }
     return Validators::isInRange(Strings::length($control->getValue()), $range);
 }
 public static function validateLength(IControl $control, $range)
 {
     if (!is_array($range)) {
         $range = array($range, $range);
     }
     return Validators::isInRange(count($control->getValue()), $range);
 }