Example #1
0
 /**
  * Parse the given string as a function call.  That is, it has the format 'functionName(arg1, arg2, ...)' where
  * the argument list is parsed by the parseArguments() method.
  *
  * @param string $call Function call to parse.
  *
  * @return array
  * @throws \InvalidArgumentException
  */
 public static function parseFunctionCall($call)
 {
     $matches = array();
     if (preg_match(self::REGEX_FUNCTION_CALL, $call, $matches) && sizeof($matches) > 1) {
         return array('name' => $matches[1], 'arguments' => sizeof($matches) > 2 ? self::parseArguments($matches[2]) : array());
     } else {
         throw new \InvalidArgumentException(sprintf('Cannot parse function call [%s] not of the format name(arg1, arg2, ..)', TypeUtilities::describe($call)));
     }
 }
Example #2
0
 /**
  * Call the given callable, using arguments determined from the given values using the getArguments() method.
  *
  * @param callable $callable Method or function reference, name or reflection object.
  * @param array|null $fixedValues Values that are required at the start of the argument list.  These will be used
  *   before any other values in determining the argument list.  If there are more elements than the number of
  *   arguments specified by the callable, then not all elements will be used.
  * @param array|null $typedValues Values that are detected by type hinting.  Not all these values are necessarily
  *   used, only those that are matched by type against the callable's argument list.
  * @param array|null $remainingValues Values that are used when all the fixed values are used, and there are no
  *   matching typed values.  Remaining values are used in preference to the parameter default values.
  *
  * @return mixed Result of invoking the given callable using the arguments as determined using supplied values.
  *
  * @throws \RuntimeException If there are insufficient matching values provided to pass for all required arguments.
  */
 public static function invokeCallable($callable, array $fixedValues = null, array $typedValues = null, array $remainingValues = null)
 {
     return call_user_func_array($callable, TypeUtilities::getArguments($callable, $fixedValues, $typedValues, $remainingValues));
 }