예제 #1
0
파일: cache.php 프로젝트: rundiz/fuel-start
 /**
  * delete cache with partial name.
  * 
  * @param string $partial_name some part of cache name. This parameter can be ALL to clear all cache
  * @return boolean
  */
 public static function deleteCache($partial_name = '')
 {
     if ($partial_name == null) {
         return true;
     }
     if ($partial_name == 'ALL') {
         \Cache::delete_all();
     }
     $cache_driver = \Config::get('cache.driver');
     if ($cache_driver == 'file') {
         // this site using cache file driver.
         $cache_subfolder = '';
         //if partial name has dot, means cache is in sub folders.
         if (strpos($partial_name, '.') !== false) {
             $partial_name_exp = explode('.', $partial_name);
             foreach ($partial_name_exp as $folder) {
                 if (end($partial_name_exp) != $folder) {
                     $cache_subfolder .= $folder . '/';
                 }
             }
             $partial_name = $partial_name_exp[count($partial_name_exp) - 1];
             unset($folder, $partial_name_exp);
         }
         // read cache directory and delete cache.
         $files = \Extension\File::readDir2D(APPPATH . 'cache/' . $cache_subfolder);
         if (is_array($files) && !empty($files)) {
             foreach ($files as $file) {
                 if (strpos($file, '.cache') !== false && strpos($file, $partial_name) !== false) {
                     if (is_writable($file)) {
                         unlink($file);
                     }
                 }
             }
             // endforeach;
         }
         unset($file, $files);
     } else {
         // this site using other cache driver.
         // there is no way to delete cache with partial name. use clear cache
         \Cache::delete_all();
     }
     return true;
 }
예제 #2
0
 /**
  * fetch permissions from core files (app/classes/controller/admin)
  *
  * @return array
  */
 public static function fetchPermissionsFile()
 {
     $permission_array = array();
     $self = static::forge();
     $controller_prefix = 'Controller_Admin_';
     if (is_dir($self->app_admin_path)) {
         $files = \Extension\File::readDir2D($self->app_admin_path);
         natsort($files);
         foreach ($files as $file) {
             $file_name = str_replace($self->app_admin_path, '', $file);
             if (is_file($file)) {
                 // prevent re-declare self class.
                 if ($file_name != 'accountpermission') {
                     include_once $file;
                 }
                 $file_to_class = $controller_prefix . ucwords(str_replace(array('.php', DS), array('', '_'), $file_name));
                 if (class_exists($file_to_class)) {
                     $obj = new $file_to_class();
                     if (method_exists($obj, '_define_permission')) {
                         $permission_array = array_merge($permission_array, $obj->_define_permission());
                     }
                 }
             }
         }
     }
     unset($controller_prefix, $files, $file, $file_name, $file_to_class, $obj, $self);
     return $permission_array;
 }