Ejemplo n.º 1
0
 private function applyScriptFromController(View\ScriptAwareInterface $renderer, callable $controller)
 {
     $controller = new Reflection\CallableReflector($controller);
     if ($controller->getReflector() instanceof Reflection\MethodReflector) {
         $renderer->setScript($this->formatScript($controller->getReflector()));
     }
 }
Ejemplo n.º 2
0
 private function resolveCommand($command, $controller)
 {
     $controller = new Reflection\CallableReflector($controller);
     $docblock = $controller->getReflector()->getDocBlock();
     if (!$docblock->hasTag($this->config['tag'])) {
         return;
     }
     $params = [];
     foreach ($docblock->getTags('param') as $tag) {
         $params[] = ['name' => $tag->getName(), 'type' => $tag->getType(), 'description' => $tag->getDescription()];
     }
     return ['command' => $command, 'description' => $docblock->getDescription(), 'params' => $params];
 }
Ejemplo n.º 3
0
 public function __invoke(callable $controller)
 {
     $parameters = [];
     $controller = new Reflection\CallableReflector($controller);
     $instance = $controller->getInstance();
     // If the controller is an instance, we have already injected
     // dependencies into it's constructor. To give the user the most from
     // the caller, we now inject named parameters into the method being
     // called.
     //
     // If the controller is just a callable, we simply inject dependencies
     // matching the parameter names into the callable since this is the
     // only chance it will have access to dependencies in the container.
     foreach ($controller->getReflector()->getParameters() as $parameter) {
         if ($instance && $this->request) {
             if ($this->request->hasParam($parameter->getName())) {
                 $parameters[] = $this->request->getParam($parameter->getName());
             }
         } elseif ($container = $this->container) {
             $parameters[] = $container($parameter->getName());
         }
     }
     return $controller->invokeArgs($parameters) ?: [];
 }
Ejemplo n.º 4
0
 public function testClosureDetection()
 {
     $callable = CallableReflector::detect(function () {
     });
     $this->assert($callable instanceof \ReflectionFunction, "A Closure was not detected");
 }