Пример #1
0
 /**
  *
  */
 public function flush()
 {
     $this->_header();
     $success = false;
     $config = Libraries::get('app');
     $dir = TwigAdapter::cachePath();
     $trash = $config['resources'] . self::PATH_TO_REMOVE;
     $this->out('Starting cache flush.');
     if (!is_dir($dir)) {
         return $this->error('Cache folder not found... exiting.');
     }
     $this->out('Cache folder found : ' . $dir);
     if (is_dir($trash)) {
         $this->out('Old trash folder found (previous command failure possible), deleting it...');
         $this->_rrmdir($trash);
     }
     $this->out('Moving cache folder to temporary location...');
     rename($dir, $trash);
     $this->out('Deleting temporary cache location...');
     $success = $this->_rrmdir($trash);
     if (!$success) {
         return $this->error('Error while deleting Twig template cache.');
     }
     return $this->out('Success!');
 }
Пример #2
0
 /**
  * Initialize the necessary Twig objects & attach them to the current object instance.
  * Attach any configured filters in the lithium app bootstrap to the Twig object.
  *
  * @return void
  */
 protected function _init()
 {
     parent::_init();
     $loader = new Twig_Loader_Filesystem(array());
     $this->environment = new Twig_Environment($loader, $this->_config);
     Twig::$_lithiumContext = $this;
     $library = Libraries::get('li3_twig');
     $defaults = array('register' => array('magicHelperMethod' => false, 'globals' => false), 'extensions' => array());
     $options = empty($library['config']) || !is_array($library['config']) ? $defaults : $library['config'] + $defaults;
     if ($options['register']['magicHelperMethod']) {
         $this->environment->addFunction('*_*', new Twig_Function_Function('li3_twig\\template\\view\\adapter\\Twig::callLithiumHelper'));
     }
     if ($options['register']['globals']) {
         $this->environment->addGlobal('view', $this);
         $this->environment->addGlobal('this', $this);
     }
     if (!empty($options['extensions'])) {
         foreach ($options['extensions'] as $extension) {
             $extensions = $this->helper($extension);
             $this->environment->addExtension($extensions);
         }
     }
 }