Esempio n. 1
0
 public function testManagerWillApplyConvertersSuccessfully()
 {
     $request = new Request();
     $parameter = $this->getReflectionParameter();
     $converter = $this->getConverterInterfaceMock();
     $converter->expects($this->once())->method('supports')->with($parameter->getClass())->will($this->returnValue(true));
     $converter->expects($this->once())->method('apply')->with($request, $parameter)->will($this->returnValue(null));
     $manager = new ConverterManager();
     $manager->add($converter);
     $manager->apply($request, $parameter);
 }
 /**
  * @param  Event $event
  * @param  mixed $controller
  *
  * @return mixed
  *
  * @throws NotFoundHttpException
  */
 public function filterController(Event $event, $controller)
 {
     if (!is_array($controller)) {
         return $controller;
     }
     $request = $event->get('request');
     $method = new \ReflectionMethod($controller[0], $controller[1]);
     foreach ($method->getParameters() as $param) {
         if (null !== $param->getClass() && false === $request->attributes->has($param->getName())) {
             try {
                 $this->manager->apply($request, $param);
             } catch (\InvalidArgumentException $e) {
                 if (false === $param->isOptional()) {
                     throw new NotFoundHttpException(sprintf('Unable to convert parameter "%s".', $param->getName()), $e);
                 }
             }
         }
     }
     return $controller;
 }