Пример #1
0
 /**
  * {@inheritdoc}
  */
 protected function renderOne(array $data)
 {
     $path = $data['methodePath'];
     $markdown = sprintf("### `%s` %s ###\n", $data['method'], $data['uri']);
     if (isset($data['deprecated']) && false !== $data['deprecated']) {
         $markdown .= "### This method is deprecated ###";
         $markdown .= "\n\n";
     }
     if (isset($data['description'])) {
         $markdown .= sprintf("\n_%s_", $data['description']);
     }
     $markdown .= "\n\n";
     if (isset($data['documentation']) && !empty($data['documentation'])) {
         if (isset($data['description']) && 0 === strcmp($data['description'], $data['documentation'])) {
             $markdown .= $data['documentation'];
             $markdown .= "\n\n";
         }
     }
     if (isset($data['requirements']) && !empty($data['requirements']) && !$this->fs->exists($path . '/requirements.html')) {
         $dataFilters = $this->engine->render('ElibertyApiBundle:nelmio:requirements.html.twig', ['data' => $data]);
         $this->fs->dumpFile($path . '/requirements.html', $dataFilters);
     }
     if (isset($data['filters']) && !$this->fs->exists($path . '/filters.html')) {
         $dataFilters = $this->engine->render('ElibertyApiBundle:nelmio:filters.html.twig', ['data' => $data]);
         $this->fs->dumpFile($path . '/filters.html', $dataFilters);
     }
     if (isset($data['parameters']) && !$this->fs->exists($path . '/parameters.html')) {
         $dataFilters = $this->engine->render('ElibertyApiBundle:nelmio:parameters.html.twig', ['data' => $data]);
         $this->fs->dumpFile($path . '/parameters.html', $dataFilters);
     }
     if (isset($data['statusCodes']) && !$this->fs->exists($path . '/statusCodes.html')) {
         $dataFilters = $this->engine->render('ElibertyApiBundle:nelmio:statusCodes.html.twig', ['data' => $data]);
         $this->fs->dumpFile($path . '/statusCodes.html', $dataFilters);
     }
     if (isset($data['response'])) {
         if (!$this->fs->exists($path . '/responses.html')) {
             $dataFilters = $this->engine->render('ElibertyApiBundle:nelmio:responses.html.twig', ['data' => $data, 'enums' => $this->enums, 'entityName' => strtolower($this->apiResource->getShortName())]);
             $this->fs->dumpFile($path . '/responses.html', $dataFilters);
         }
         $dataToSerialize = $this->dataProvider->getCollection($this->apiResource, new Request());
         if (!isset($data['tags']['collection']) && $dataToSerialize instanceof Paginator) {
             $dataToSerialize = $dataToSerialize->getIterator()->current();
         }
         if (!$this->fs->exists($path . '/json/responses.json')) {
             try {
                 if (isset($data['tags']['embed']) && in_array(strtolower($this->apiResource->getShortName()), ['option', 'orderitem'])) {
                     $this->setEmbed($data, $dataToSerialize);
                 }
                 $dataJson = $this->normalizer->normalize($dataToSerialize, 'json-ld', $this->apiResource->getNormalizationContext(), false);
                 $this->fs->dumpFile($path . '/json/responses.json', json_encode($dataJson, JSON_PRETTY_PRINT));
             } catch (\Exception $ex) {
                 return $markdown;
             }
         }
     }
     return $markdown;
 }
 /**
  * Normalizes data using the Symfony Serializer.
  *
  * @param ResourceInterface $resource
  * @param array|object      $data
  * @param int               $status
  * @param array             $headers
  * @param array             $additionalContext
  *
  * @return Response
  */
 protected function getSuccessResponse(ResourceInterface $resource, $data, $status = 200, array $headers = [], array $additionalContext = [])
 {
     return new Response($this->get('serializer')->normalize($data, 'json-ld', $resource->getNormalizationContext() + $additionalContext), $status, $headers);
 }