/** Read JSON from file on path * @param string $path * @return array|false */ public static function read($path, $silent = false) { try { $data = self::decode(\System\File::read($path, $silent)); } catch (\System\Error\Format $e) { $ex = new \System\Error\Format(sprintf('%s when parsing JSON file %s', $e->getMessage(), $path)); throw $ex; } return $data; }
/** * 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); }
/** Force env or read it * @param string $env Environment name * @return void */ public static function set_env($env = null) { if (is_null($env)) { if (file_exists($ef = BASE_DIR . self::DIR_CONF_DIST . '/env')) { self::$env = trim(\System\File::read($ef)); } } else { self::$env = $env; } if (!defined("YACMS_ENV")) { define("YACMS_ENV", self::$env); } }
/** 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); }
private function get_checksum() { if (!$this->md5_sum) { $this->md5_sum = md5(\System\File::read($p = $this->get_file_path())); } return $this->md5_sum; }
public function get_content() { return \System\File::read(BASE_DIR . $this->get_path()); }