private function getFunctionName(\ReflectionFunctionAbstract $reflectionFunction)
 {
     if ($reflectionFunction->isClosure()) {
         return sprintf('closure defined in %s at line %d', $reflectionFunction->getFileName(), $reflectionFunction->getStartLine());
     } elseif ($reflectionFunction instanceof \ReflectionMethod) {
         return sprintf('%s::%s', $reflectionFunction->getDeclaringClass()->getName(), $reflectionFunction->getName());
     }
     return $reflectionFunction->getName();
 }
 /**
  * Print the signature of the target action.
  * 
  * @return string
  */
 public function __toString()
 {
     if ($this->target instanceof \ReflectionMethod) {
         return sprintf('%s->%s()', $this->target->getDeclaringClass()->name, $this->target->name);
     }
     if ($this->target instanceof \ReflectionFunction && !$this->target->isClosure()) {
         return $this->target->getName() . '()';
     }
     return '*closure*';
 }
Exemple #3
0
 /**
  * Creates a function scope instance from the supplied reflection and callable.
  *
  * @param \ReflectionFunctionAbstract $reflection
  * @param callable                    $callable
  *
  * @return self
  */
 public static function fromReflection(\ReflectionFunctionAbstract $reflection, callable $callable)
 {
     if (is_array($callable)) {
         /** @var $reflection \ReflectionMethod */
         $thisObject = is_object($callable[0]) ? $callable[0] : null;
         $scopeType = $reflection->getDeclaringClass()->getName();
     } elseif (is_object($callable) && !$callable instanceof \Closure) {
         /** @var $reflection \ReflectionMethod */
         $thisObject = $callable;
         $scopeType = $reflection->getDeclaringClass()->getName();
     } elseif ($reflection->isClosure()) {
         $thisObject = $reflection->getClosureThis();
         $scopeClass = $reflection->getClosureScopeClass();
         $scopeType = $scopeClass === null ? null : $scopeClass->getName();
     } else {
         $thisObject = null;
         $scopeType = null;
     }
     $variableTable = $reflection->getStaticVariables();
     return new self($thisObject, $scopeType, $variableTable);
 }
 /**
  * Get called method from abstract reflection function
  *
  * @param \ReflectionFunctionAbstract $method
  * @param bool                        $closureInfo
  *
  * @return string
  */
 public static function getCalledMethod(\ReflectionFunctionAbstract $method, $closureInfo = true)
 {
     if ($method->isClosure()) {
         if ($closureInfo) {
             return sprintf('Closure [%s:%d]', $method->getFileName(), $method->getStartLine());
         }
         return 'Closure';
     }
     if ($method instanceof \ReflectionMethod) {
         return sprintf('%s::%s', $method->getDeclaringClass()->getName(), $method->getName());
     }
     return $method->getName();
 }
Exemple #5
0
 function it_returns_its_line_number_as_zero_if_constructed_with_closure(\ReflectionFunctionAbstract $function)
 {
     $function->isClosure()->willReturn(true);
     $this->getLineNumber()->shouldReturn(0);
 }
 /**
  * Merges found arguments with multiliners and maps them to the function callback signature.
  *
  * @param ContextInterface            $context   context instance
  * @param \ReflectionFunctionAbstract $refl      callback reflection
  * @param array                       $arguments found arguments
  * @param array                       $multiline multiline arguments of the step
  *
  * @return array
  */
 private function prepareCallbackArguments(ContextInterface $context, \ReflectionFunctionAbstract $refl, array $arguments, array $multiline)
 {
     $parametersRefl = $refl->getParameters();
     if ($refl->isClosure()) {
         array_shift($parametersRefl);
     }
     $resulting = array();
     foreach ($parametersRefl as $num => $parameterRefl) {
         if (isset($arguments[$parameterRefl->getName()])) {
             $resulting[] = $arguments[$parameterRefl->getName()];
         } elseif (isset($arguments[$num])) {
             $resulting[] = $arguments[$num];
         }
     }
     foreach ($multiline as $argument) {
         $resulting[] = $argument;
     }
     return $resulting;
 }
Exemple #7
0
 protected function getCallbackSignature(\ReflectionFunctionAbstract $ref)
 {
     if ($ref instanceof \ReflectionMethod) {
         return $ref->getDeclaringClass()->name . '->' . $ref->name . '()';
     }
     if ($ref->isClosure()) {
         return '*closure*';
     }
     return $ref->name . '()';
 }
Exemple #8
0
 /**
  * @return int
  */
 public function getLineNumber()
 {
     return $this->function->isClosure() ? 0 : $this->function->getStartLine();
 }