コード例 #1
0
 /**
  * {@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);
 }
コード例 #2
0
 /**
  * Does the conversion.
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->has('_resource')) {
         return;
     }
     $shortName = $request->attributes->get('_resource');
     $resourceType = $this->resourceTypeCollection->getResourceForShortName($shortName);
     if (!$resourceType) {
         throw new InvalidArgumentException(sprintf('The resource "%s" cannot be found.', $shortName));
     }
     $request->attributes->set('_resource_type', $resourceType);
 }
コード例 #3
0
 /**
  * {@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));
 }
コード例 #4
0
 /**
  * Generates a context according to the type requested.
  *
  * @param Request $request
  * @param $shortName
  *
  * @return array
  */
 public function __invoke(Request $request, $shortName)
 {
     $request->attributes->set('_api_format', 'jsonld');
     if ('Entrypoint' === $shortName) {
         return ['@context' => $this->contextBuilder->getEntrypointContext()];
     }
     if (isset(self::$reservedShortNames[$shortName])) {
         $resource = null;
     } else {
         $resource = $this->resourceTypeCollection->getResourceForShortName($shortName);
         if (!$resource) {
             throw new NotFoundHttpException();
         }
     }
     return ['@context' => $this->contextBuilder->getContext($resource)];
 }