Esempio n. 1
0
 /**
  * Short lambda expression
  * ex:
  *   ['x,y'=>'x+y+z', 'z'=>$z]
  * it means
  *   function ($x,$y) use ($z) {return $x+$y+$z;}
  * @see http://symfony.com/doc/current/components/expression_language/syntax.html
  * @param callable|array $lambda
  * @return callable
  */
 public static function fun($lambda)
 {
     if (is_callable($lambda)) {
         return $lambda;
     }
     return Lambda::fun($lambda);
 }
Esempio n. 2
0
 /**
  * @param callable|string|array|Predicate $src
  * @throws \InvalidArgumentException
  * @return Predicate
  */
 public static function resolve($src)
 {
     if (is_callable($src)) {
         return new DelegatePredicate($src);
     }
     if (is_string($src)) {
         return new PropertyPredicate($src);
     }
     if (is_array($src)) {
         return new DelegatePredicate(Lambda::fun($src));
     }
     if ($src instanceof Predicate) {
         return $src;
     }
     $type = gettype($src);
     throw new \InvalidArgumentException("Invalid predicate, got {$type}");
 }
Esempio n. 3
0
 /**
  * @param \Closure|Comparer $src
  * @param Comparer $default
  * @throws \InvalidArgumentException
  * @return \Ginq\Core\Comparer
  */
 public static function resolve($src, $default)
 {
     if (is_null($src)) {
         return $default;
     }
     if (is_callable($src)) {
         return new DelegateComparer($src);
     }
     if (is_array($src)) {
         return new DelegateComparer(Lambda::fun($src));
     }
     if ($src instanceof Comparer) {
         return $src;
     }
     $type = gettype($src);
     throw new \InvalidArgumentException("'comparer' Closure expected, got {$type}");
 }
Esempio n. 4
0
 /**
  * @param \Closure|JoinSelector|int $src
  * @param $default
  * @throws \InvalidArgumentException
  * @return JoinSelector
  */
 public static function resolve($src, $default)
 {
     if (is_null($src)) {
         return $default;
     }
     if (is_callable($src)) {
         return new DelegateJoinSelector($src);
     }
     if (is_array($src)) {
         return new DelegateJoinSelector(Lambda::fun($src));
     }
     if ($src instanceof JoinSelector) {
         return $src;
     }
     $type = gettype($src);
     throw new \InvalidArgumentException("Invalid selector, got {$type}");
 }