Exemplo n.º 1
0
 protected function action()
 {
     $headers = ['Content-Type' => $this->resourceDO->getMimeType()];
     $filePath = $this->resourceDO->getFilePath();
     $fileExists = is_file($filePath);
     $recreate = PrepareResourceMiddlewareAbstract::getParamFromRequest(static::RECREATE_COMMAND, $this->request);
     $uri = PrepareResourceMiddlewareAbstract::getParamFromRequest(static::URI_COMMAND, $this->request);
     $recreate = $fileExists && $recreate;
     $this->resourceDO->setNew(!$fileExists);
     if (!$fileExists || $recreate) {
         $this->resourceDO->setRecreate($recreate);
         $upload = $this->upload();
         // Upload must be with high priority
         if ($upload) {
             /** @see \Zend\Diactoros\Response::$phrases */
             return new FileUploadedResponse($upload, 201, $headers);
         } elseif ($uri) {
             $upload = $this->download($this->resourceDO, $uri);
             /** @see \Zend\Diactoros\Response::$phrases */
             return new FileUploadedResponse($upload, 201, $headers);
         } else {
             $body = $this->generate($this->resourceDO);
             /** @see \Zend\Diactoros\Response::$phrases */
             return new FileContentResponse($body, 201, $headers);
         }
     }
     /** @see \Zend\Diactoros\Response::$phrases */
     return new EmptyResponse(304, $headers);
 }
 /**
  * @return int
  */
 protected function getCursor()
 {
     $allowCursor = $this->config->get('staticus.search.allow_cursor_for_users', false);
     $roles = $this->user->getRoles();
     if ($allowCursor || in_array(Roles::ADMIN, $roles, true)) {
         $cursor = (int) PrepareResourceMiddlewareAbstract::getParamFromRequest('cursor', $this->request);
         return $cursor;
     }
     return self::DEFAULT_CURSOR;
 }
 protected function action()
 {
     $headers = ['Content-Type' => $this->resourceDO->getMimeType()];
     $destroy = PrepareResourceMiddlewareAbstract::getParamFromRequest('destroy', $this->request);
     if ($destroy) {
         $command = new DestroyResourceCommand($this->resourceDO, $this->filesystem);
         $command();
     } else {
         $command = new DeleteSafetyResourceCommand($this->resourceDO, $this->filesystem);
         $command();
     }
     /** @see \Zend\Diactoros\Response::$phrases */
     return new EmptyResponse(204, $headers);
 }
Exemplo n.º 4
0
 /**
  * @param ServerRequestInterface $request
  * @return string
  */
 protected function getAction(ServerRequestInterface $request)
 {
     if (PrepareResourceMiddlewareAbstract::getParamFromRequest(Actions::ACTION_SEARCH, $request)) {
         return Actions::ACTION_SEARCH;
     }
     if (PrepareResourceMiddlewareAbstract::getParamFromRequest(Actions::ACTION_LIST, $request)) {
         return Actions::ACTION_LIST;
     }
     $method = $request->getMethod();
     switch ($method) {
         case 'GET':
             $action = Actions::ACTION_READ;
             break;
         case 'POST':
             $action = Actions::ACTION_WRITE;
             break;
         case 'DELETE':
             $action = Actions::ACTION_DELETE;
             break;
         default:
             throw new WrongRequestException('Unknown access control action');
     }
     return $action;
 }
 public function __construct(ResourceDO $resourceDO, ConfigInterface $config)
 {
     parent::__construct($resourceDO, $config);
 }