Пример #1
0
 /**
  * @param array|\Traversable $subject
  * @param mixed $value
  *
  * @return bool
  */
 public static function contain($subject, $value)
 {
     if (is_array($subject)) {
         return in_array($value, $subject, true);
     }
     if ($subject instanceof \Traversable) {
         foreach ($subject as $entry) {
             if ($entry === $value) {
                 return true;
             }
         }
         return false;
     }
     throw new \InvalidArgumentException(sprintf('Subject of type "%s" is not iterable.', TypeHelper::getType($subject)));
 }
Пример #2
0
 /**
  * @param mixed $key
  *
  * @return mixed
  * @throws InvalidKeyTypeException
  */
 private function convertKeyToHash(&$key)
 {
     if (is_scalar($key)) {
         return $key;
     }
     if (is_object($key) && method_exists($key, '__toString')) {
         return (string) $key;
     }
     throw new InvalidKeyTypeException(TypeHelper::getType($key));
 }
Пример #3
0
 /**
  * @param string    $var
  * @param string    $expectedType
  * @param int       $code
  * @param Exception $previous
  */
 public function __construct($var, $expectedType, $code = 0, Exception $previous = null)
 {
     parent::__construct(sprintf('Expected type "%s", but "%s" given.', $expectedType, TypeHelper::getType($var)), $code, $previous);
 }
Пример #4
0
 /**
  * @param mixed $element
  *
  * @return bool
  */
 private function isValidType($element)
 {
     return TypeHelper::isOfType($element, $this->type);
 }