Пример #1
0
 /**
  * Sets up the backend.
  *
  * @param array $config   The configuration data for the backend.
  *
  * @return void
  *
  * @throws \YapepBase\Exception\ConfigException    On configuration errors.
  * @throws \YapepBase\Exception\StorageException   On storage errors.
  * @throws \YapepBase\Exception\File\Exception     On filesystem errors.
  */
 protected function setupConfig(array $config)
 {
     if (empty($config['path'])) {
         throw new ConfigException('Path is not set for FileStorage config (' . $this->currentConfigurationName . ')');
     }
     $this->path = $config['path'];
     if (!in_array(substr($this->path, -1, 1), array('/', '\\'))) {
         $this->path .= DIRECTORY_SEPARATOR;
     }
     $this->storePlainText = empty($config['storePlainText']) ? false : (bool) $config['storePlainText'];
     $this->filePrefix = empty($config['filePrefix']) ? '' : $config['filePrefix'];
     $this->fileSuffix = empty($config['fileSuffix']) ? '' : $config['fileSuffix'];
     $this->fileMode = empty($config['fileMode']) ? 0644 : $config['fileMode'];
     $this->hashKey = empty($config['hashKey']) ? false : (bool) $config['hashKey'];
     $this->readOnly = empty($config['readOnly']) ? false : (bool) $config['readOnly'];
     $this->debuggerDisabled = empty($config['debuggerDisabled']) ? false : (bool) $config['debuggerDisabled'];
     // If the given path does not exist
     if (!$this->fileHandler->checkIsPathExists($this->path)) {
         try {
             // Create the path
             $this->fileHandler->makeDirectory($this->path, $this->fileMode | 0111, true);
         } catch (FileException $e) {
             throw new StorageException('Can not create directory for FileStorage: ' . $this->path, 0, $e);
         }
         // If the given path is not a directory
     } elseif (!$this->fileHandler->checkIsDirectory(rtrim($this->path, '/'))) {
         throw new StorageException('Path is not a directory for FileStorage: ' . $this->path);
     }
     // If this is not a readonly storage and a given path is not writable
     if (!$this->readOnly && !$this->fileHandler->checkIsWritable($this->path)) {
         throw new StorageException('Path is not writable for FileStorage: ' . $this->path);
     }
 }