/**
  * Gets an item using the data provider. Throws a 404 error if not found.
  *
  * @param DataProviderInterface $dataProvider
  * @param ResourceInterface     $resourceType
  * @param string|int            $id
  *
  * @return object
  *
  * @throws NotFoundHttpException
  */
 private function getItem(DataProviderInterface $dataProvider, ResourceInterface $resourceType, $id)
 {
     $data = $dataProvider->getItem($resourceType, $id, true);
     if (!$data) {
         throw new NotFoundHttpException();
     }
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function getItemFromIri($iri, $fetchData = false)
 {
     try {
         $parameters = $this->router->match($iri);
     } catch (ResourceNotFoundException $e) {
         return;
     }
     if (!isset($parameters['_resource']) || !isset($parameters['id']) || !($resource = $this->resourceCollection->getResourceForShortName($parameters['_resource']))) {
         throw new \InvalidArgumentException(sprintf('No resource associated with the IRI "%s".', $iri));
     }
     return $this->dataProvider->getItem($resource, $parameters['id'], $fetchData);
 }
 /**
  * {@inheritdoc}
  */
 public function getItemFromIri($iri, $fetchData = false)
 {
     try {
         $parameters = $this->router->match($iri);
     } catch (ExceptionInterface $e) {
         throw new InvalidArgumentException(sprintf('No route matches "%s".', $iri), $e->getCode(), $e);
     }
     if (!isset($parameters['_resource']) || !isset($parameters['id']) || !($resource = $this->resourceCollection->getResourceForShortName($parameters['_resource']))) {
         throw new InvalidArgumentException(sprintf('No resource associated to "%s".', $iri));
     }
     if ($item = $this->dataProvider->getItem($resource, $parameters['id'], $fetchData)) {
         return $item;
     }
     throw new InvalidArgumentException(sprintf('Item not found for "%s".', $iri));
 }
 /**
  * Retrieves a filtered tip of the day history list. Filters by the currently logged in user by default
  *
  * @param Request $request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  *
  * @throws RuntimeException
  */
 public function __invoke(Request $request)
 {
     list($resourceType) = $this->extractAttributes($request);
     $collection = $this->dataProvider->getCollection($resourceType);
     $user = $this->userService->getUser();
     $resultCollection = array();
     foreach ($collection as $item) {
         /**
          * @var $item TipOfTheDayHistory
          */
         if ($item->getUser() == $user) {
             $resultCollection[] = $item;
         }
     }
     return $resultCollection;
 }
Example #5
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;
 }
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  *
  * @throws RuntimeException
  */
 public function __invoke(Request $request)
 {
     list($resourceType) = $this->extractAttributes($request);
     return $this->dataProvider->getCollection($resourceType);
 }