Beispiel #1
0
 /**
  * @param RouterInterface $router
  * @param array $validationErrors
  */
 public function __construct(RouterInterface $router, ResourceInterface $resource)
 {
     parent::__construct($router);
     //$contentType = 'application/' . strtolower(str_replace('\\', '.', get_class($resource))) . '+json';
     //$contentType = 'application/vnd.uebb.hateoas.resource+json';
     //$this->setHeader('Content-Type', $contentType);
     $this->setData($resource);
     /*
             // Disable the caching mechanism
                     $ifModifiedSince = new \DateTime($request->headers->get('If-Modified-Since', '1900-01-01 00:00:00'));
                     $lastModified = $resource->getUpdatedAt;
             $response = new Response();
                     $response->setMaxAge(10);
                     $response->headers->addCacheControlDirective('must-revalidate');
                     $response->setLastModified(($lastModified ? $lastModified : new \DateTime()));
     
             $this->setResponse($response);
             if (!($lastModified && $ifModifiedSince) || $ifModifiedSince < $lastModified) {
                         $this->setData($resource);
                         $this->setHeader('Content-Type', $contentType);
                     } else {
                         $this->setStatusCode(304);
                     }
     */
 }
 /**
  * Get a view for a resource collection
  *
  * @param Request $request - The http request
  * @param QueryBuilder $queryBuilder - The query builder for the collection
  * @return View
  */
 public function __construct(RouterInterface $router, Request $request, QueryBuilder $queryBuilder)
 {
     parent::__construct($router);
     $this->setData($this->getPagerfantaRepresentation($request, new DoctrineORMAdapter($queryBuilder)));
     //$this->setHeader('Content-Type', 'application/vnd.uebb.hateoas.collection+json');
     /**
      * @var \DateTime $lastModified
      */
     //        $lastModified = $this->getLastModifiedDateForQuery($queryBuilder);
     //
     //        $ifModifiedSince = $request->headers->get('If-Modified-Since', false);
     //        if ($ifModifiedSince !== false) {
     //            $ifModifiedSince = new \DateTime($ifModifiedSince);
     //        }
     //
     //        $response = new Response();
     //        $response->setMaxAge(10);
     //        $response->headers->addCacheControlDirective('must-revalidate');
     //        $response->setLastModified(($lastModified ? $lastModified : new \DateTime()));
     //
     //        $this->setResponse($response);
     //        if (true || !($lastModified && $ifModifiedSince) || $lastModified > $ifModifiedSince
     //        ) {
     //            $this->setData($this->getPagerfantaRepresentation(new DoctrineORMAdapter($queryBuilder)));
     //            $this->setHeader('Content-Type', 'application/vnd.uebb.hateoas.collection+json');
     //
     //        } else {
     //            $this->setStatusCode(304);
     //        }
     return $this;
 }
 /**
  * @param RouterInterface $router
  * @param array $validationErrors
  */
 public function __construct(RouterInterface $router, ResourceInterface $resource, array $patch)
 {
     parent::__construct($router);
     $this->setStatusCode(201);
     $routeName = 'get_' . strtolower(basename(str_replace('\\', '//', get_class($resource))));
     // set the `Location` header when creating new resources
     $this->setHeader('Location', $this->generateUrl($routeName, array('id' => $resource->getId()), true));
     $this->setData($patch);
 }
 /**
  * @param RouterInterface $router
  * @param ConstraintViolationListInterface $validationErrors
  */
 public function __construct(RouterInterface $router, ConstraintViolationListInterface $validationErrors)
 {
     parent::__construct($router);
     $errors = array();
     foreach ($validationErrors as $violation) {
         /** @var ConstraintViolation $violation */
         $violation = $violation;
         if (!isset($errors[$violation->getPropertyPath()])) {
             $errors[$violation->getPropertyPath()] = array();
         }
         $errors[$violation->getPropertyPath()][] = array('message' => $violation->getMessage(), 'parameters' => $violation->getMessageParameters());
     }
     $this->setData(array('code' => 400, 'message' => 'Validation Failed', 'errors' => $errors));
     $this->setStatusCode(400);
 }
 public function __construct(RouterInterface $router)
 {
     parent::__construct($router);
     $this->setStatusCode(204);
 }