/**
  * @dataProvider dataTestApiDeclaration
  */
 public function testApiDeclaration($resource, $expected)
 {
     set_error_handler(array($this, 'handleDeprecation'));
     $data = $this->extractor->all();
     restore_error_handler();
     $actual = $this->formatter->format($data, $resource);
     $this->assertEquals($expected, $actual);
 }
 /**
  * {@inheritdoc}
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     if (!$request->query->has($this->parameter)) {
         return;
     }
     $controller = $request->attributes->get('_controller');
     $route = $request->attributes->get('_route');
     if (null !== ($annotation = $this->extractor->get($controller, $route))) {
         $result = $this->formatter->formatOne($annotation);
         $event->setResponse(new Response($result, 200, array('Content-Type' => 'text/html')));
     }
 }
Exemple #3
0
 /**
  * Returns the ReflectionMethod for the given controller string.
  *
  * @param  \ReflectionMethod|string $controller
  * @return \ReflectionMethod|null
  */
 public function getReflectionMethod($controller)
 {
     if ($controller instanceof \ReflectionMethod) {
         return $controller;
     } else {
         return parent::getReflectionMethod($controller);
     }
 }
 public function all($view = ApiDoc::DEFAULT_VIEW)
 {
     if ($this->cache->isFresh() === false) {
         $resources = array();
         foreach ($this->getRoutes() as $route) {
             if (null !== ($method = $this->getReflectionMethod($route->getDefault('_controller'))) && null !== ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS))) {
                 $file = $method->getDeclaringClass()->getFileName();
                 $resources[] = new FileResource($file);
             }
         }
         $resources = array_merge($resources, $this->router->getRouteCollection()->getResources());
         $data = parent::all($view);
         $this->cache->write(serialize($data), $resources);
         return $data;
     }
     return unserialize(file_get_contents($this->cacheFile));
 }
 /**
  * {@inheritdoc}
  */
 public function getRoutes()
 {
     return RouteCollectionUtil::filterHidden(parent::getRoutes());
 }
 protected function normalizeClassParameter($input, DunglasResource $resource = null)
 {
     $dataResponse = [];
     if (in_array(strtolower($this->versionApi), $this->nelmioDocStandardVersion)) {
         return parent::normalizeClassParameter($input);
     }
     $dataResponse = parent::normalizeClassParameter($input);
     $dataResponse['groups'] = $resource->getValidationGroups();
     return $dataResponse;
 }