Пример #1
0
 /**
  * @param \ReflectionMethod $method
  * @param array $args
  * @param callable $parameterFilter
  * @return array Of the injected arguments
  * @throws InjectionException
  */
 public function injectMethodArguments(\ReflectionMethod $method, array $args, $parameterFilter)
 {
     $analyzer = new MethodAnalyzer($method);
     try {
         return $analyzer->fillParameters($args, $this->injector, $parameterFilter);
     } catch (\InvalidArgumentException $e) {
         throw new InjectionException("Cannot inject method [{$method->getDeclaringClass()->getName()}" . "::{$method->getName()}]: " . $e->getMessage(), 0, $e);
     }
 }
Пример #2
0
 private function filter(\ReflectionMethod $method, $arguments)
 {
     $filters = new DefaultFilterRegistry();
     $analyzer = new MethodAnalyzer($method);
     $args = $analyzer->normalize($arguments);
     foreach ($args as $name => $value) {
         $type = $analyzer->getTypeHint($analyzer->getParameter($name));
         if ($type) {
             $args[$name] = $filters->getFilter($type)->filter($args[$name]);
         }
     }
     return $args;
 }
Пример #3
0
 /**
  * @return string|null
  */
 public function comment()
 {
     if ($this->getter) {
         $analyzer = new MethodAnalyzer($this->getter);
         return $analyzer->getReturnComment();
     } else {
         if ($this->setter) {
             $analyzer = new MethodAnalyzer($this->setter);
             $comments = array_values($analyzer->getComments());
             return $comments[0];
         }
     }
     return null;
 }
Пример #4
0
 /**
  * @param mixed[] $parameters Values indexed by name
  * @return mixed the result of the execution
  * @throws \Exception if Action cannot be executed
  */
 public function execute(array $parameters)
 {
     $injector = function () {
     };
     $filter = function () {
         return true;
     };
     $analyzer = new MethodAnalyzer($this->method);
     $arguments = $analyzer->fillParameters($parameters, $injector, $filter);
     return $this->method->invokeArgs($this->object, $arguments);
 }
Пример #5
0
 function testReadComment()
 {
     $method = new MethodAnalyzer(new \ReflectionMethod(MethodAnalyzerTest_Foo::$CLASS, 'fourth'));
     $this->assertEquals($method->getComments(), array('one' => null, 'two' => 'With Comment'));
 }
Пример #6
0
 /**
  * @return string|null
  */
 public function comment()
 {
     $analyzer = new MethodAnalyzer($this->constructor);
     return $analyzer->getComment($this->parameter);
 }
Пример #7
0
 private function filter(MethodAnalyzer $analyzer, $arguments)
 {
     $args = $analyzer->normalize($arguments);
     foreach ($args as $name => $value) {
         $type = $analyzer->getTypeHint($analyzer->getParameter($name));
         if ($type) {
             $args[$name] = $this->filters->getFilter($type)->filter($args[$name]);
         }
     }
     return $args;
 }