Exemplo n.º 1
0
 /** @test */
 public function itShouldReturnRightReflector()
 {
     $r = new Reflector([$this, 'testMethod']);
     $this->assertInstanceof('ReflectionMethod', $r->getReflector());
     $r = new Reflector('array_map');
     $this->assertInstanceof('ReflectionFunction', $r->getReflector());
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  *
  * @throws UnexpectedValueException if required type cannot be mapped.
  * @throws UnexpectedValueException if a none optional parameter is
  * missing
  *
  * @return array
  */
 public function map(Reflector $handler, array $parameters)
 {
     $params = [];
     foreach ($handler->getReflector()->getParameters() as $param) {
         if (null !== ($class = $param->getClass())) {
             if (!$this->types->has($class = $class->getName())) {
                 throw new MissingValueException(sprintf('Cannot map class "%s" to parameter "{$%s}".', $class, $param->getName()));
             }
             $params[$param->getName()] = $this->types->get($class);
             continue;
         }
         if (array_key_exists($param->getName(), $parameters)) {
             $params[$param->getName()] = $parameters[$param->getName()];
             continue;
         }
         if (!$param->isOptional()) {
             throw new MissingValueException(sprintf('Missing non optional parameter "{$%s}".', $param->getName()));
         }
         $params[$param->getName()] = null;
     }
     return array_values($params);
 }