Esempio n. 1
0
 /**
  * {@inheritdoc}
  *
  * @throws \Stash\Exception\RuntimeException
  */
 public function setOptions(array $options = array())
 {
     $options += $this->getDefaultOptions();
     $this->cachePath = rtrim($options['path'], '\\/') . DIRECTORY_SEPARATOR;
     $this->filePermissions = $options['filePermissions'];
     $this->dirPermissions = $options['dirPermissions'];
     $this->busyTimeout = $options['busyTimeout'];
     $this->nesting = max((int) $options['nesting'], 0);
     Utilities::checkFileSystemPermissions($this->cachePath, $this->dirPermissions);
     $extension = isset($options['extension']) ? strtolower($options['extension']) : 'any';
     $version = isset($options['version']) ? $options['version'] : 'any';
     $subdrivers = array();
     if (Sub\SqlitePdo::isAvailable()) {
         $subdrivers['pdo'] = '\\Stash\\Driver\\Sub\\SqlitePdo';
     }
     if (Sub\Sqlite::isAvailable()) {
         $subdrivers['sqlite'] = '\\Stash\\Driver\\Sub\\Sqlite';
     }
     if (Sub\SqlitePdo2::isAvailable()) {
         $subdrivers['pdo2'] = '\\Stash\\Driver\\Sub\\SqlitePdo2';
     }
     if ($extension == 'pdo' && $version != '2' && isset($subdrivers['pdo'])) {
         $driver = $subdrivers['pdo'];
     } elseif ($extension == 'sqlite' && isset($subdrivers['sqlite'])) {
         $driver = $subdrivers['sqlite'];
     } elseif ($extension == 'pdo' && $version != '3' && isset($subdrivers['pdo2'])) {
         $driver = $subdrivers['pdo2'];
     } elseif (count($subdrivers) > 0 && $extension == 'any') {
         $driver = reset($subdrivers);
     } else {
         throw new RuntimeException('No sqlite extension available.');
     }
     $this->driverClass = $driver;
     $this->checkStatus();
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  *
  * @throws \Stash\Exception\RuntimeException
  */
 protected function setOptions(array $options = array())
 {
     $options += $this->getDefaultOptions();
     $this->cachePath = rtrim($options['path'], '\\/') . DIRECTORY_SEPARATOR;
     $this->filePermissions = $options['filePermissions'];
     $this->dirPermissions = $options['dirPermissions'];
     $this->busyTimeout = $options['busyTimeout'];
     $this->nesting = max((int) $options['nesting'], 0);
     Utilities::checkFileSystemPermissions($this->cachePath, $this->dirPermissions);
     if (static::isAvailable() && Sub\SqlitePdo::isAvailable()) {
         $this->driverClass = '\\Stash\\Driver\\Sub\\SqlitePdo';
     } else {
         throw new RuntimeException('No sqlite extension available.');
     }
     $driver = $this->getSqliteDriver(array('_none'));
     if (!$driver) {
         throw new RuntimeException('No Sqlite driver could be loaded.');
     }
 }
Esempio n. 3
0
 /**
  * Requests a list of options.
  *
  * @param array $options
  *
  * @throws \Stash\Exception\RuntimeException
  */
 protected function setOptions(array $options = array())
 {
     $options += $this->getDefaultOptions();
     if (!isset($options['path'])) {
         $options['path'] = Utilities::getBaseDirectory($this);
     }
     $this->cachePath = rtrim($options['path'], '\\/') . DIRECTORY_SEPARATOR;
     $this->filePermissions = $options['filePermissions'];
     $this->dirPermissions = $options['dirPermissions'];
     $this->directorySplit = max((int) $options['dirSplit'], 1);
     $this->memStoreLimit = max((int) $options['memKeyLimit'], 0);
     if (is_callable($options['keyHashFunction'])) {
         $this->keyHashFunction = $options['keyHashFunction'];
     } else {
         throw new RuntimeException('Key Hash Function is not callable');
     }
     if (isset($options['encoder'])) {
         $encoder = $options['encoder'];
         if (is_object($encoder)) {
             if (!$encoder instanceof EncoderInterface) {
                 throw new RuntimeException('Encoder object must implement EncoderInterface');
             }
             $this->encoder = new $encoder();
         } else {
             $encoderInterface = 'Stash\\Driver\\FileSystem\\EncoderInterface';
             $encoderClass = 'Stash\\Driver\\FileSystem\\' . $encoder . 'Encoder';
             if (class_exists($encoder) && in_array($encoderInterface, class_implements($encoder))) {
                 $this->encoder = new $encoder();
             } elseif (class_exists($encoderClass) && in_array($encoderInterface, class_implements($encoderClass))) {
                 $this->encoder = new $encoderClass();
             } else {
                 throw new RuntimeException('Invalid Encoder: ' . $encoder);
             }
         }
     }
     Utilities::checkFileSystemPermissions($this->cachePath, $this->dirPermissions);
 }
Esempio n. 4
0
 /**
  * Requests a list of options.
  *
  * @param  array                             $options
  * @throws \Stash\Exception\RuntimeException
  */
 public function setOptions(array $options = array())
 {
     $options = array_merge($this->defaultOptions, $options);
     $this->cachePath = isset($options['path']) ? $options['path'] : Utilities::getBaseDirectory($this);
     $this->cachePath = rtrim($this->cachePath, '\\/') . DIRECTORY_SEPARATOR;
     $this->filePermissions = $options['filePermissions'];
     $this->dirPermissions = $options['dirPermissions'];
     if (!is_numeric($options['dirSplit']) || $options['dirSplit'] < 1) {
         $options['dirSplit'] = 1;
     }
     $this->directorySplit = (int) $options['dirSplit'];
     if (!is_numeric($options['memKeyLimit']) || $options['memKeyLimit'] < 1) {
         $options['memKeyLimit'] = 0;
     }
     if (is_callable($options['keyHashFunction'])) {
         $this->keyHashFunction = $options['keyHashFunction'];
     } else {
         throw new RuntimeException('Key Hash Function is not callable');
     }
     $this->memStoreLimit = (int) $options['memKeyLimit'];
     Utilities::checkFileSystemPermissions($this->cachePath, $this->dirPermissions);
 }
Esempio n. 5
0
 /**
  * @expectedException Stash\Exception\InvalidArgumentException
  */
 public function testCheckFileSystemPermissionsUnwrittableException()
 {
     Utilities::checkFileSystemPermissions('/home', '0644');
 }