public function onKernelController(FilterControllerEvent $event) { $request = $event->getRequest(); $controller = $event->getController(); if (is_array($controller)) { if (!$controller[0] instanceof RestServiceInterface) { return; } $reflection = new \ReflectionMethod($controller[0], $controller[1]); } elseif (is_object($controller) && !$controller instanceof \Closure) { if (!$controller instanceof RestServiceInterface) { return; } $reflection = new \ReflectionObject($controller); $reflection = $reflection->getMethod('__invoke'); } else { return; } $request->attributes->set('_diamante_rest_service', true); if ($request->getMethod() == 'GET') { $pagingContext = PagingContext::fromRequest($request); $pagingContext->setHeaderContainer($this->container->get('diamante.api.headers.container')); $this->container->get('diamante.api.paging.provider')->setContext($pagingContext); } $methodParameters = new MethodParameters($reflection, $this->validator); if ($request->request->count()) { $request->attributes->set('properties', $request->request->all()); } $methodParameters->addParameterBag($request->request); $methodParameters->addParameterBag($request->attributes); $methodParameters->addParameterBag($request->query); $methodParameters->putIn($request->attributes); }
/** * @test * @expectedException \InvalidArgumentException * @expectedExceptionMessage Not all properties set correctly */ public function thatPutInThrowsValidatorException() { $reflection = new \ReflectionMethod('Diamante\\ApiBundle\\Tests\\Handler\\Fixtures\\Object', 'getParts'); $dummyBagFirst = new ParameterBag(['id' => '1']); $this->validator->expects($this->once())->method('validate')->will($this->returnValue(new ConstraintViolationList([new ConstraintViolation('Not all properties set correctly', 'Not all properties set correctly', [], '', '', '')]))); $methodParameters = new MethodParameters($reflection, $this->validator); $methodParameters->putIn($dummyBagFirst); }