Beispiel #1
0
 public function serialize($data, Version $version = null)
 {
     if ($version !== null) {
         $context = SerializationContext::create()->setVersion($version->getVersion());
         $response = $this->serializer->serialize($data, SerializationVisitor::NAME, $context);
     } else {
         $response = $this->serializer->serialize($data, SerializationVisitor::NAME);
     }
     return $response;
 }
Beispiel #2
0
 /**
  * Returns the resource from the documentation for the given version.
  *
  * @param \PSX\Api\DocumentationInterface $doc
  * @param \PSX\Api\Version $version
  * @return \PSX\Api\Resource
  */
 protected function getResource(DocumentationInterface $doc, Version $version)
 {
     if (!$doc->hasResource($version->getVersion())) {
         throw new StatusCode\NotAcceptableException('Version is not available');
     }
     $resource = $doc->getResource($version->getVersion());
     if ($resource->isActive()) {
     } elseif ($resource->isDeprecated()) {
         $this->response->addHeader('Warning', '199 PSX "Version v' . $version->getVersion() . ' is deprecated"');
     } elseif ($resource->isClosed()) {
         throw new StatusCode\GoneException('Version v' . $version->getVersion() . ' is not longer supported');
     } elseif ($resource->isDevelopment()) {
         $this->response->addHeader('Warning', '199 PSX "Version v' . $version->getVersion() . ' is in development"');
     }
     return $resource;
 }