Esempio n. 1
0
 public function __construct(ConfigInterface $config, AclInterface $acl)
 {
     $this->config = $config->get('acl');
     $this->acl = $acl;
     $this->fillRoles($this->config[self::ROLES]);
     $this->fillResources($this->config[self::RESOURCES]);
 }
Esempio n. 2
0
 public function __invoke($error, Request $request, Response $response, callable $next)
 {
     /*
     If $error is not an exception, it will use the response status if it already indicates an error
     (ie., >= 400 status), or will use a 500 status, and return the response directly with the reason phrase.
     */
     if ($error instanceof \Exception) {
         $className = $error->getTrace();
         if (isset($className[0]['class'])) {
             $className = $className[0]['class'];
         }
         if ($error instanceof ResourceNotFoundException) {
             $error = $this->getErrorArray($error->getMessage(), $this->getErrorCode($error, $className), $error->getResourceDO());
             return new NotFoundResponse($error);
         } else {
             if ($error instanceof WrongRequestException) {
                 /** @see \Zend\Diactoros\Response::$phrases */
                 return $this->response(400, $error->getMessage(), ExceptionCodes::code($className) . '.' . $error->getCode());
             } else {
                 $message = $this->config->get('error_handler', false) ? $error->getMessage() : 'Internal error';
                 /** @see \Zend\Diactoros\Response::$phrases */
                 return $this->response(503, $message, $this->getErrorCode($error, $className));
             }
         }
     } else {
         $next($request, $response, $next);
     }
 }
 /**
  * @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;
 }
 public function resizeImage($sourcePath, $destinationPath, $width, $height)
 {
     if (!$this->filesystem->has($sourcePath)) {
         throw new NotFoundException('Can not resize. Resource is not found');
     }
     $this->createDirectory(dirname($destinationPath));
     $imagick = $this->getImagick($sourcePath);
     if ($this->config->get('staticus.images.resize.autocrop', false)) {
         $imagick->cropThumbnailImage($width, $height);
     } else {
         $imagick->adaptiveResizeImage($width, $height, true);
     }
     $imagick->writeImage($destinationPath);
     $imagick->clear();
     $imagick->destroy();
 }
 /**
  * @param ResourceDOInterface $resourceDO
  * @param string|resource|Stream $content
  * @return ResourceDOInterface
  * @throws \RuntimeException if the upload was not successful.
  * @throws \InvalidArgumentException if the $path specified is invalid.
  * @throws \RuntimeException on any error during the move operation, or on
  */
 protected function save(ResourceDOInterface $resourceDO, $content)
 {
     $backupResourceVerDO = null;
     $filePath = $resourceDO->getFilePath();
     $this->createDirectory(dirname($filePath));
     // backups don't needs if this is a 'new creation' command
     if ($resourceDO->isRecreate()) {
         $backupResourceVerDO = $this->backup($resourceDO);
     }
     if ($content instanceof UploadedFileInterface) {
         $this->uploadFile($content, $resourceDO->getMimeType(), $filePath);
     } else {
         $this->writeFile($filePath, $content);
     }
     $responseDO = $resourceDO;
     if ($backupResourceVerDO instanceof ResourceDOInterface && $backupResourceVerDO->getVersion() !== ResourceDOInterface::DEFAULT_VERSION) {
         // If the newly created file is the same as the previous version, remove backup immediately
         $responseDO = $this->destroyEqual($resourceDO, $backupResourceVerDO);
     }
     if ($responseDO === $resourceDO) {
         // cleanup postprocessing cache folders
         // - if it is a new file creation (remove possible garbage after other operations)
         // - or if the basic file is replaced and not equal to the previous version
         $this->afterSave($resourceDO);
     }
     if ($this->config->get('staticus.magic_defaults.allow')) {
         $this->copyFileToDefaults($resourceDO);
     }
     return $resourceDO;
 }
Esempio n. 6
0
 /**
  * @return \AudioManager\Adapter\AdapterInterface
  * @throws RuntimeException
  */
 public function __invoke()
 {
     $adapterName = strtolower($this->config->get('voice.provider', self::VOICE_PROVIDER_GOOGLE));
     switch ($adapterName) {
         case self::VOICE_PROVIDER_GOOGLE:
             $adapter = new Google();
             $adapter->getOptions()->setLanguage('en');
             $adapter->getOptions()->setEncoding('UTF-8');
             break;
         case self::VOICE_PROVIDER_IVONA:
             $secretKey = $this->config->get('voice.' . $adapterName . '.secret_key', '');
             $accessKey = $this->config->get('voice.' . $adapterName . '.access_key', '');
             $adapter = new Ivona();
             $adapter->getOptions()->setSecretKey($secretKey);
             $adapter->getOptions()->setAccessKey($accessKey);
             break;
         default:
             throw new ErrorException('Not implemented functionality for voice provider: ' . $adapterName);
     }
     return $adapter;
 }
 /**
  * @param string $namespace
  * @return bool
  */
 protected function namespaceValidator($namespace)
 {
     $allowed = $this->config->get('staticus.namespaces');
     if ($namespace && !in_array($namespace, $allowed, true)) {
         foreach ($allowed as $item) {
             if (false !== strpos($item, '*') && fnmatch($item, $namespace)) {
                 // TODO: limitations for nested namespaces
                 return true;
             }
         }
         return false;
     }
     return true;
 }
 public function __construct(ConfigInterface $config, UserInterface $user)
 {
     $this->config = $config->get('auth.basic');
     $this->user = $user;
 }
 public function __invoke()
 {
     $adapter = new Local($this->config->get('filesystem.adapters.' . Local::class . '.options.root'));
     return $adapter;
 }
 public function __construct(FilesystemInterface $filesystem, ConfigInterface $config)
 {
     $this->config = $config->get('staticus.fractal_templates');
     $this->filesystem = $filesystem;
 }
 public function __construct(ConfigInterface $config)
 {
     $this->config = $config->get('auth.session');
 }
 public function __construct(ConfigInterface $config)
 {
     $this->config = $config->get('api.google');
 }
 /**
  * @return bool
  */
 protected function mustBeStripped()
 {
     return $this->config->get('staticus.images.exif.strip', false) && ($this->resourceDO->isNew() || $this->resourceDO->isRecreate()) && $this->filesystem->has($this->resourceDO->getFilePath());
 }
 /**
  * @return bool
  */
 protected function isAllowed()
 {
     return $this->config->get('staticus.images.compress.compress', false) && ($this->resourceDO->isNew() || $this->resourceDO->isRecreate()) && $this->filesystem->has($this->resourceDO->getFilePath());
 }
Esempio n. 15
0
 public function __construct(ConfigInterface $config, AclServiceInterface $service, UserInterface $user)
 {
     $this->config = $config->get('acl');
     $this->service = $service;
     $this->user = $user;
 }
 public function __construct(ConfigInterface $config, ManagerInterface $manager, UserInterface $user)
 {
     $this->config = $config->get('auth.session');
     $this->manager = $manager;
     $this->user = $user;
 }