Esempio n. 1
0
 /**
  * Left-curry the provided function with the provided array of arguments.
  *
  * @param callable $function
  * @param mixed[] $args
  *
  * @return Closure|mixed
  */
 public static function curryArgs(callable $function, $args)
 {
     Arguments::define(Boa::func(), Boa::arr())->check($function, $args);
     // Counts required parameters.
     $required = function () use($function) {
         return (new ReflectionFunction($function))->getNumberOfRequiredParameters();
     };
     $isFulfilled = function (callable $function, $args) use($required) {
         return count($args) >= $required($function);
     };
     if ($isFulfilled($function, $args)) {
         return static::apply($function, $args);
     }
     return function (...$funcArgs) use($function, $args, $required, $isFulfilled) {
         $newArgs = ArrayList::of($args)->append(ArrayList::of($funcArgs))->toArray();
         if ($isFulfilled($function, $newArgs)) {
             return static::apply($function, $newArgs);
         }
         return static::curryArgs($function, $newArgs);
     };
 }
Esempio n. 2
0
 /**
  * Set a key in the response.
  *
  * @param string $key
  * @param string|array $value
  *
  * @throws InvalidArgumentException
  */
 public function set($key, $value)
 {
     Arguments::define(Boa::string(), Boa::either(Boa::string(), Boa::arr()))->check($key, $value);
     if (in_array($key, static::getReservedKeys())) {
         throw new InvalidArgumentException('This response key is reserved.');
     }
     $this->content[$key] = $value;
 }
Esempio n. 3
0
 /**
  * Make a simple where query.
  *
  * @param array $fieldConditions
  * @param array $columns
  * @param array $with
  *
  * @throws InvalidArgumentException
  * @throws LackOfCoffeeException
  * @return Builder
  */
 protected function makeWhereQuery(array $fieldConditions, array $columns = ['*'], array $with = [])
 {
     Arguments::define(Boa::arr(), Boa::arrOf(Boa::string()), Boa::arrOf(Boa::string()))->check($fieldConditions, $columns, $with);
     $query = $this->makeModelInstance()->query()->where($fieldConditions);
     $this->applyWith($query, $with);
     return $query;
 }