Ejemplo n.º 1
0
 public static function cmd_libs()
 {
     \System\Init::basic();
     \Helper\Cli::out("Installed composer libraries");
     \Helper\Cli::sep();
     \Helper\Cli::out_flist(array("list" => \System\Composer::get_libs(), "margin" => 2, "show_keys" => false));
 }
Ejemplo n.º 2
0
 public static function check_for_changes($dir)
 {
     $mtime = filemtime(BASE_DIR . self::FILE_ROUTES_CACHE);
     $files = \System\Composer::find($dir, '/\\.json$/');
     foreach ($files as $file) {
         if (filemtime($file) > $mtime) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Build static cache
  *
  * @return void
  */
 public function cmd_static()
 {
     \System\Init::basic();
     $lib_list = \System\Composer::get_libs();
     $libs = array();
     foreach ($lib_list as $lib) {
         $libs[$lib] = $lib;
     }
     array_push($libs, null);
     \Helper\Cli::do_over($libs, function ($key, $name) {
         \System\Cache::build_static_for($name);
     }, 'Collecting static files');
 }
Ejemplo n.º 4
0
 /**
  * Generate rules for mod rewrite htaccess
  * @return string
  */
 public static function generate_rewrite_rules()
 {
     $dirs = \System\Composer::list_dirs(\System\Loader::DIR_REWRITE);
     foreach ($dirs as $dir) {
         $od = opendir($dir);
         $files = array();
         while ($file = readdir($od)) {
             if (strpos($file, '.') !== 0) {
                 $files[$file] = \System\File::read($dir . '/' . $file);
             }
         }
         ksort($files);
     }
     return implode("\n", $files);
 }
Ejemplo n.º 5
0
 /** Run list of init scripts
  * @param array $list   List of init scripts
  * @param array $locals Local data
  * @return void
  */
 public static function run(array $list, array $locals)
 {
     // Convert locals into level on variables
     foreach ((array) $locals as $k => $v) {
         $k = str_replace('-', '_', $k);
         ${$k} = $v;
     }
     $dirs = \System\Composer::list_dirs('/etc/init.d');
     foreach ($list as $init_step) {
         $found = false;
         foreach ($dirs as $dir) {
             if (file_exists($f = $dir . '/' . $init_step . '.php')) {
                 $found = true;
                 require_once $f;
                 break;
             }
         }
         if (!$found) {
             throw new \System\Error\File(sprintf("Init file '%s' was not found inside init folder '%s'.", $init_step, \System\Init::DIR_INIT));
         }
     }
 }
Ejemplo n.º 6
0
 public function resolve()
 {
     if ($this->src == 'static') {
         if ($this->use_cache) {
             $file = BASE_DIR . $this::DIR_CACHE . DIRECTORY_SEPARATOR . $this->name_full;
         } else {
             $file = \System\Composer::resolve($this::DIR_STATIC . DIRECTORY_SEPARATOR . $this->name_full);
         }
     } else {
         $file = $this::DIR_MEDIA . DIRECTORY_SEPARATOR . $this->name_full;
     }
     if (any($file)) {
         $cname = $this::CLASS_FILE;
         $this->file_path = $file;
         $this->file_point = $cname::from_path($file);
         if ($this->file_point) {
             $this->exists = $this->file_point->exists();
         } else {
             $this->exists = false;
         }
     } else {
         $this->exists = false;
     }
 }
Ejemplo n.º 7
0
 public static function read($dir, $assoc_keys = false, &$files = array(), &$temp = array())
 {
     $dirs = \System\Composer::list_dirs($dir);
     return \System\Json::read_dist_all($dirs, $assoc_keys, $files, $temp);
 }
Ejemplo n.º 8
0
 /** Get list of available files from user input
  * @param string $type
  * @param list   $modules
  * @return array
  */
 public function get_file_list($modules)
 {
     $found = array();
     $missing = array();
     try {
         $use_cache = \System\Settings::get('cache', 'resources');
     } catch (\System\Error\Config $e) {
         $use_cache = false;
     }
     if ($use_cache) {
         $dirs = array(BASE_DIR . $this::DIR_CACHE);
     } else {
         if ($this->src == 'static') {
             $src = $this::DIR_STATIC;
         } else {
             $src = $this::DIR_MEDIA;
         }
         $dirs = \System\Composer::list_dirs($src);
     }
     foreach ($modules as $module) {
         $mod_found = false;
         foreach ($dirs as $dir) {
             foreach ($this::$postfixes as $postfix) {
                 $path = $dir . DIRECTORY_SEPARATOR . $module;
                 if (file_exists($p = $path . '.list')) {
                     $list = $this->get_file_list(array_map('trim', array_filter(explode("\n", \System\File::read($p)))));
                     $found = array_merge($found, $list[self::KEY_FOUND]);
                     $missing = array_merge($missing, $list[self::KEY_MISSING]);
                     $mod_found = true;
                     break;
                 } else {
                     if (is_file($p = $path) || is_file($p = $path . '.' . $postfix)) {
                         $found[] = $p;
                         $mod_found = true;
                     }
                 }
                 if (is_dir($path)) {
                     $json = null;
                     $meta = self::get_meta($path, 'bower.json');
                     if (!$meta) {
                         $meta = self::get_meta($path, 'package.json');
                     }
                     if ($meta) {
                         $files = array();
                         foreach ($meta as $file) {
                             $files[] = str_replace($dir . '/', '', $path . '/' . $file);
                         }
                         $list = $this->get_file_list($files);
                         $found = array_merge($found, $list[self::KEY_FOUND]);
                         $mod_found = true;
                         break;
                     } else {
                         $files = \System\Directory::find_all_files($path);
                         foreach ($files as $key => $tmp_file) {
                             $files[$key] = str_replace($dir . '/', '', $files[$key]);
                         }
                         $list = $this->get_file_list($files);
                         $found = array_merge($found, $list[self::KEY_FOUND]);
                         $missing = array_merge($missing, $list[self::KEY_MISSING]);
                         $mod_found = true;
                         break;
                     }
                 }
             }
             if ($mod_found) {
                 break;
             }
         }
         if (!$mod_found) {
             $missing[] = $module;
         }
     }
     $this->sum = self::get_module_sum_from_list($modules);
     return array(self::KEY_FOUND => array_unique(array_filter($found)), self::KEY_MISSING => array_unique(array_filter($missing)), self::KEY_SUM => $this->sum);
 }
Ejemplo n.º 9
0
 public function get_template_path($name)
 {
     return \System\Composer::resolve(\System\Template::DIR_TEMPLATE . '/' . $name . '.' . $this->get_suffix());
 }
Ejemplo n.º 10
0
 public function get_file_path()
 {
     return \System\Composer::resolve(self::DIR . '/' . $this->get_filename());
 }
Ejemplo n.º 11
0
 public static function autoload($class_name)
 {
     $sources = array('/lib/class', '/lib');
     $found = false;
     $file = \System\Loader::get_class_file_name($class_name, true);
     $helper_pos = strpos(\System\Loader::get_link_from_class($class_name), 'helper');
     $is_helper = $helper_pos !== false && $helper_pos <= 1;
     foreach ($sources as $key => $source) {
         $classes = \System\Composer::list_dirs($source);
         foreach ($classes as $dir) {
             if (file_exists($f = $dir . '/' . $file)) {
                 $found = (include_once $f);
                 break;
             }
         }
         if ($found) {
             break;
         }
     }
 }
Ejemplo n.º 12
0
 private static function get_all()
 {
     return \System\Composer::list_dirs('/lib/test');
 }
Ejemplo n.º 13
0
 public function to_object()
 {
     if (!$this->mime) {
         $this->read_meta();
     }
     $path = str_replace(\System\File::DIR, '', $this->get_path_relative());
     $src = 'media';
     $cname = $this::RESOURCE_CNAME;
     $stat = $cname::DIR_STATIC;
     try {
         $cache = \System\Settings::get('cache', 'resources');
     } catch (\System\Error $e) {
         $cache = false;
     }
     if ($cache) {
         $dirs = array($stat);
     } else {
         $dirs = \System\Composer::list_dirs($stat);
         array_unshift($dirs, $stat);
     }
     foreach ($dirs as $dir) {
         if (strpos($path, $dir) === 0 || strpos($path, $dir = substr($dir, 1)) === 0) {
             $path = substr($path, strlen($dir));
             $src = 'static';
             break;
         }
     }
     $url = \System\Resource::get_url($src, self::RESOURCE_TYPE, preg_replace("/^\\//", '', $path));
     return array("url" => $url, "path" => $path, "name" => $this->name, "mime" => $this->mime, "size" => $this->size, "method" => $this->method ? $this->method : 'save');
 }
Ejemplo n.º 14
0
 public function get_context_processors()
 {
     $list = !!$this->context ? $this->context : $this->request->context;
     $files = array();
     foreach ($list as $name) {
         $file_path = \System\Composer::resolve('/lib/context/' . $name . '.php');
         if ($file_path) {
             array_push($files, $file_path);
         } else {
             throw new \System\Error\Config('Failed to find context processor.', $name);
         }
     }
     return $files;
 }