コード例 #1
0
ファイル: AbstractListener.php プロジェクト: koolkode/event
 /**
  * Populates arguments assembled from the event and the given target function.
  * 
  * @param \ReflectionFunctionAbstract $ref
  * @param EventParamResolverInterface $resolver
  * @return array
  */
 protected function loadArguments(\ReflectionFunctionAbstract $ref, EventParamResolverInterface $resolver)
 {
     $args = [];
     if ($ref->getNumberOfParameters() > 1) {
         foreach (array_slice($ref->getParameters(), 1) as $param) {
             $args[] = $resolver->resolve($param->getClass(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : false);
         }
     }
     return $args;
 }
コード例 #2
0
 /**
  * Resolves function arguments.
  *
  * @param array $parameters
  *
  * @return array
  *
  * @throws UnresolvableArgumentException
  */
 public function resolve(array $parameters)
 {
     if (!($number = $this->reflection->getNumberOfParameters())) {
         return [];
     }
     $arguments = array_fill(0, $number, null);
     foreach ($this->getParameters() as $pos => $parameter) {
         $result = $this->match($parameter, $parameters);
         if ($result) {
             $arguments[$pos] = $result[1];
             unset($parameters[$result[0]]);
             continue;
         }
         if ($parameter->isDefaultValueAvailable()) {
             $arguments[$pos] = $parameter->getDefaultValue();
             continue;
         }
         throw new UnresolvableArgumentException($parameter);
     }
     return $arguments;
 }
コード例 #3
0
ファイル: Container.php プロジェクト: Jaymon/Montage
 /**
  *  normalize the params of the $rmethod to allow a valid call
  *
  *  @example
  *    // method signature: foo($bar = '',$baz = '',SomeClass $che);
  *    $rmethod = new ReflectionMethod($instance,'foo');
  *    $this->normalizeParams($rmethod,array('che','cha')) // retuns array('che','cha',automatically created SomeClass Instance)
  *    $this->normalizeParams($rmethod,array('che')) // retuns array('che','',automatically created SomeClass Instance)
  *    $this->normalizeParams($rmethod,array('che' => new SomeClass(),'bar' => '')) // retuns array('','',passed in SomeClass Instance)       
  *        
  *  @param  ReflectionFunctionAbstract  $rfunc  the reflection of the method/function
  *  @param  array $params any params you want to pass to override any magically
  *                        discovered params
  *  @return array the params ready to be passed to the method using something like call_user_func_array
  */
 public function normalizeParams(\ReflectionFunctionAbstract $rfunc, array $params = array())
 {
     // canary...
     if ($rfunc->getNumberOfParameters() <= 0) {
         return $params;
     }
     //if
     $ret_params = array();
     $rparams = $rfunc->getParameters();
     foreach ($rparams as $rparam) {
         $ret_params[] = $this->normalizeParam($rparam, $params);
     }
     //foreach
     return $ret_params;
 }
コード例 #4
0
ファイル: docblock_tools.php プロジェクト: rchavik/infinitas
 /**
  * Create a string representation of the method signature.
  *
  * @param ReflectionFunctionAbstract $func The function you want a signature for.
  * @return void
  **/
 public static function makeFunctionSignature(ReflectionFunctionAbstract $func)
 {
     $signature = $func->getName() . '( ';
     foreach ($func->getParameters() as $param) {
         $signature .= '$' . $param->getName();
         if ($param->isDefaultValueAvailable()) {
             $signature .= ' = ' . var_export($param->getDefaultValue(), true);
         }
         $signature .= ', ';
     }
     if ($func->getNumberOfParameters() > 0) {
         $signature = substr($signature, 0, -2);
     }
     $signature .= ' )';
     return $signature;
 }
コード例 #5
0
ファイル: DependencyChecker.php プロジェクト: nette/di
 private static function hashParameters(\ReflectionFunctionAbstract $method)
 {
     $res = [];
     if (PHP_VERSION_ID < 70000 && $method->getNumberOfParameters() && $method->getFileName()) {
         $res[] = file($method->getFileName())[$method->getStartLine() - 1];
     }
     foreach ($method->getParameters() as $param) {
         $res[] = [$param->getName(), PHP_VERSION_ID >= 70000 ? PhpReflection::getParameterType($param) : NULL, $param->isVariadic(), $param->isDefaultValueAvailable() ? $param->isDefaultValueConstant() ? $param->getDefaultValueConstantName() : [$param->getDefaultValue()] : NULL];
     }
     return $res;
 }
コード例 #6
0
ファイル: ReflectionUtils.php プロジェクト: xxoxx/php-waf
 /**
  * @param \ReflectionFunctionAbstract $func
  * @param integer                     $num
  * @return boolean
  */
 public static function matchesNumberOfArguments(\ReflectionFunctionAbstract $func, $num)
 {
     return $func->getNumberOfRequiredParameters() <= $num && $func->getNumberOfParameters() >= $num;
 }