Пример #1
0
 /**
  * Class constructor.
  *
  * @param array                    $options Initial options for the cache adapter:
  *                                          - cachedir string The cache directory
  * @param string                   $context An optional cache context
  * @param \Psr\Log\LoggerInterface $logger  An optional logger
  *
  * @throws \BackBee\Cache\Exception\CacheException Occurs if the cache directory doesn't exist, can not
  *                                                 be created or is not writable.
  */
 public function __construct(array $options = array(), $context = null, LoggerInterface $logger = null)
 {
     parent::__construct($options, $context, $logger);
     $this->cachedir = $this->_instance_options['cachedir'];
     if (null !== $this->getContext()) {
         $this->cachedir .= DIRECTORY_SEPARATOR . StringUtils::toPath($this->getContext());
     }
     if (true === $this->_instance_options['cacheautogenerate'] && false === is_dir($this->cachedir) && false === @mkdir($this->cachedir, 0755, true)) {
         throw new CacheException(sprintf('Unable to create the cache directory `%s`.', $this->cachedir));
     }
     if (true === $this->_instance_options['cacheautogenerate'] && false === is_writable($this->cachedir)) {
         throw new CacheException(sprintf('Unable to write in the cache directory `%s`.', $this->cachedir));
     }
     $this->log('info', sprintf('File cache system initialized with directory set to `%s`.', $this->cachedir));
 }
Пример #2
0
 public function testToPath()
 {
     $options1 = array('extension' => '.txt', 'spacereplace' => '_');
     $this->assertEquals('test_path.txt', StringUtils::toPath('test path', $options1));
     $options2 = array('extension' => '.txt', 'spacereplace' => '_', 'lengthlimit' => 5);
     $this->assertEquals('test_.txt', StringUtils::toPath('test path', $options2));
     $options3 = array();
     $this->assertEquals('testpath', StringUtils::toPath('test path', $options3));
     $options4 = array('extension' => '.jpg');
     $this->assertEquals('testpath.jpg', StringUtils::toPath('test path', $options4));
     $options5 = array('spacereplace' => '+');
     $this->assertEquals('test+path', StringUtils::toPath('test path', $options5));
     $options6 = array('lengthlimit' => 3);
     $this->assertEquals('tes', StringUtils::toPath('test path', $options6));
     $options7 = array('new' => 'aaa');
     $this->assertEquals('testpath', StringUtils::toPath('test path', $options7));
     $this->assertEquals('foodefaut.yml', StringUtils::toPath('foo/défaut.yml'));
 }
Пример #3
0
 /**
  * Return the file path to current layout, try to create it if not exists.
  *
  * @param Layout $layout
  *
  * @return string the file path
  *
  * @throws RendererException
  */
 protected function getLayoutFile(Layout $layout)
 {
     $layoutfile = $layout->getPath();
     if (null === $layoutfile && 0 < count($this->_includeExtensions)) {
         $ext = reset($this->_includeExtensions);
         $layoutfile = StringUtils::toPath($layout->getLabel(), array('extension' => $ext));
         $layout->setPath($layoutfile);
     }
     return $layoutfile;
 }
Пример #4
0
 /**
  * Return the file path to current layout, try to create it if not exists.
  *
  * @param Layout $layout
  *
  * @return string the file path
  *
  * @throws RendererException
  */
 protected function getLayoutFile(Layout $layout)
 {
     $layoutfile = $layout->getPath();
     if (null === $layoutfile && 0 < $this->manageableExt->count()) {
         $adapter = null;
         if (null !== $this->defaultAdapter && null !== ($adapter = $this->rendererAdapters->get($this->defaultAdapter))) {
             $extensions = $adapter->getManagedFileExtensions();
         } else {
             $extensions = $this->manageableExt->keys();
         }
         if (0 === count($extensions)) {
             throw new RendererException('Declared adapter(s) (count:' . $this->rendererAdapters->count() . ') is/are not able to manage ' . 'any file extensions at moment.');
         }
         $layoutfile = StringUtils::toPath($layout->getLabel(), array('extension' => reset($extensions)));
         $layout->setPath($layoutfile);
     }
     return $layoutfile;
 }