예제 #1
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)];
 }
예제 #2
0
 /**
  * Builds the JSON-LD context for the given resource.
  *
  * @param ResourceInterface|null $resource
  *
  * @return array
  */
 public function getContext(ResourceInterface $resource = null)
 {
     $context = parent::getContext($resource);
     if ($resource) {
         $normalizedOutput = $this->documentationHelper->normalizeClassParameter($resource->getEntityClass(), $resource);
         $data = $this->documentationHelper->getParametersParser($normalizedOutput, $resource);
         $embeds = $this->documentationHelper->transformerHelper->getAvailableIncludes($resource->getShortName());
         $context['@embed'] = implode(',', $embeds);
         foreach ($data as $key => $value) {
             $context[$key] = '#' . $resource->getShortName() . '/' . $key;
         }
     }
     return $context;
 }
 /**
  * Builds the JSON-LD context for the API documentation.
  *
  * @return array
  */
 private function getContext()
 {
     return array_merge($this->contextBuilder->getContext(), ['rdf' => ContextBuilder::RDF_NS, 'rdfs' => ContextBuilder::RDFS_NS, 'xmls' => ContextBuilder::XML_NS, 'owl' => ContextBuilder::OWL_NS, 'domain' => ['@id' => 'rdfs:domain', '@type' => '@id'], 'range' => ['@id' => 'rdfs:range', '@type' => '@id'], 'subClassOf' => ['@id' => 'rdfs:subClassOf', '@type' => '@id'], 'expects' => ['@id' => 'hydra:expects', '@type' => '@id'], 'returns' => ['@id' => 'hydra:returns', '@type' => '@id']]);
 }