Example #1
0
 public static function CheckCacheDir()
 {
     avada_Less_Cache::$cache_dir = str_replace('\\', '/', avada_Less_Cache::$cache_dir);
     avada_Less_Cache::$cache_dir = rtrim(avada_Less_Cache::$cache_dir, '/') . '/';
     if (!file_exists(avada_Less_Cache::$cache_dir)) {
         if (!mkdir(avada_Less_Cache::$cache_dir)) {
             throw new Less_Exception_Parser('Less.php cache directory couldn\'t be created: ' . avada_Less_Cache::$cache_dir);
         }
     } elseif (!is_dir(avada_Less_Cache::$cache_dir)) {
         throw new Less_Exception_Parser('Less.php cache directory doesn\'t exist: ' . avada_Less_Cache::$cache_dir);
     } elseif (!is_writable(avada_Less_Cache::$cache_dir)) {
         throw new Less_Exception_Parser('Less.php cache directory isn\'t writable: ' . avada_Less_Cache::$cache_dir);
     }
 }
Example #2
0
 /**
  * Return the results of parsePrimary for $file_path
  * Use cache and save cached results if possible
  *
  * @param string|null $file_path
  */
 private function GetRules($file_path)
 {
     $this->SetInput($file_path);
     $cache_file = $this->CacheFile($file_path);
     if ($cache_file) {
         if (avada_Less_Parser::$options['cache_method'] == 'callback') {
             if (is_callable(avada_Less_Parser::$options['cache_callback_get'])) {
                 $cache = call_user_func_array(avada_Less_Parser::$options['cache_callback_get'], array($this, $file_path, $cache_file));
                 if ($cache) {
                     $this->UnsetInput();
                     return $cache;
                 }
             }
         } elseif (file_exists($cache_file)) {
             switch (avada_Less_Parser::$options['cache_method']) {
                 // Using serialize
                 // Faster but uses more memory
                 case 'serialize':
                     $cache = unserialize(file_get_contents($cache_file));
                     if ($cache) {
                         touch($cache_file);
                         $this->UnsetInput();
                         return $cache;
                     }
                     break;
                     // Using generated php code
                 // Using generated php code
                 case 'var_export':
                 case 'php':
                     $this->UnsetInput();
                     return include $cache_file;
             }
         }
     }
     $rules = $this->parsePrimary();
     if ($this->pos < $this->input_len) {
         throw new Avada_Less_Exception_Chunk($this->input, null, $this->furthest, $this->env->currentFileInfo);
     }
     $this->UnsetInput();
     //save the cache
     if ($cache_file) {
         if (avada_Less_Parser::$options['cache_method'] == 'callback') {
             if (is_callable(avada_Less_Parser::$options['cache_callback_set'])) {
                 call_user_func_array(avada_Less_Parser::$options['cache_callback_set'], array($this, $file_path, $cache_file, $rules));
             }
         } else {
             //msg('write cache file');
             switch (avada_Less_Parser::$options['cache_method']) {
                 case 'serialize':
                     file_put_contents($cache_file, serialize($rules));
                     break;
                 case 'php':
                     file_put_contents($cache_file, '<?php return ' . self::ArgString($rules) . '; ?>');
                     break;
                 case 'var_export':
                     //Requires __set_state()
                     file_put_contents($cache_file, '<?php return ' . var_export($rules, true) . '; ?>');
                     break;
             }
             avada_Less_Cache::CleanCache();
         }
     }
     return $rules;
 }