Exemplo n.º 1
0
 /**
  * Returns true, if a given value meets the validation requirements.
  *
  * @param   mixed  The value to validate.
  * @return  bool
  */
 public function isValid($value)
 {
     $haystack = $this->getOption('haystack');
     $strict = $this->getOption('strict');
     if (static::$PREVENT_STR_TO_LONG_VULNERABILITY) {
         foreach ($haystack as &$h) {
             $type = Util\ZendValUtils::getType($h);
             if (in_array($type, [IS_LONG, IS_DOUBLE])) {
                 Util\ZendValUtils::convertToString($h);
             }
         }
         unset($h);
     }
     $result = in_array($value, $haystack, $strict);
     if (!$result) {
         $this->reportError(self::IS_ERR_NOT_IN_ARRAY);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Returns true, if a given value meets the validation requirements.
  *
  * @param   mixed  The value to validate.
  * @return  bool
  */
 public function isValid($value)
 {
     try {
         Util\ZendValUtils::convertToString($value, $strict = true);
     } catch (\Exception $ex) {
         $this->reportError(self::IS_ERR_INVALID, $value);
         return false;
     }
     Util\ErrorHandlerUtils::start();
     $status = preg_match($this->getOption('pattern'), $value);
     Util\ErrorHandlerUtils::stop();
     if ($status === false) {
         $this->reportError(self::IS_ERR_INTERNAL, $value);
         return false;
     }
     if ($status < 1) {
         $this->reportError(self::IS_ERR_NOT_MATCH, $value);
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Returns true, if a given value meets the validation requirements.
  *
  * @param   mixed  The value to validate.
  * @return  bool
  */
 public function isValid($value)
 {
     $length = strlen($value);
     $min = $this->getOption('min');
     $max = $this->getOption('max');
     try {
         Util\ZendValUtils::convertToString($value, $strict = true);
     } catch (\Exception $ex) {
         $this->reportError(self::IS_ERR_INVALID, $value);
         return false;
     }
     if ($length < $min) {
         $this->reportError(self::IS_ERR_SHORT);
         return false;
     }
     if ($max !== null && $max < $length) {
         $this->reportError(self::IS_ERR_LONG);
         return false;
     }
     return true;
 }
Exemplo n.º 4
0
 /**
  * Returns a parsable string representation of a variable
  *
  * @param   mixed   The variable you want to export.
  * @param   int     How deep to browse.
  * @return  string  Return the variable representation.
  */
 public static function export($expression, $maxDepth = 5)
 {
     // Declare internal closure to export given parameter.
     $currentDepth = 0;
     $featureFunc = function ($expression) use($maxDepth, $currentDepth, &$featureFunc) {
         if ($maxDepth < ++$currentDepth) {
             return '...';
         }
         switch (ZendValUtils::getType($expression)) {
             case IS_OBJECT:
                 $str = method_exists($expression, '__toString') ? (string) $expression : (method_exists($expression, 'getMessage') ? $expression->getMessage() : sprintf('object(%s)', get_class($expression)));
                 break;
             case IS_ARRAY:
                 $str = '';
                 foreach ($expression as $key => $val) {
                     if (isset($str[0])) {
                         $str .= ', ';
                     }
                     $str .= is_array($val) ? sprintf("'%s' => [%s]", $key, $featureFunc($val, $maxDepth)) : sprintf("'%s' => '%s'", $key, $featureFunc($val, $maxDepth));
                 }
                 $str = "[{$str}]";
                 break;
             case IS_NULL:
                 $str = 'null';
                 break;
             default:
                 $str = $expression;
                 ErrorHandlerUtils::start();
                 ZendValUtils::convertToString($str);
                 ErrorHandlerUtils::stop();
                 break;
         }
         return $str;
     };
     // Invoke the internal closure.
     return $featureFunc($expression, $maxDepth);
 }