Ejemplo n.º 1
0
 public static function loadConfig()
 {
     $conf = Config::getInstance();
     $memcache = new MemCache();
     if (array_key_exists("JCONFIG_FILE", $memcache)) {
         $conf->setData($memcache["JCONFIG_FILE"]);
         Logger::debug("Config loaded from cache");
         foreach ($conf->get("plugins", array()) as $plugin) {
             Plugins::add($plugin);
         }
     } else {
         $cache = Cache::Priv(self::config, ".php");
         if ($cache->check()) {
             if (file_exists(ROOT_DIR . "/composer.json")) {
                 $conf->append(ROOT_DIR . "/composer.json", false, "composer");
             }
             if (file_exists(CONFIG_DIR . "/config.json")) {
                 $conf->append(CONFIG_DIR . "/config.json");
             }
             if (file_exists(CONFIG_DIR . "/config.local.json")) {
                 $conf->append(CONFIG_DIR . "/config.local.json");
             }
             foreach (glob(CONFIG_DIR . "/*.json") as $file) {
                 $bn = basename($file);
                 if (substr($bn, 0, 7) != "config.") {
                     $conf->append($file, false, substr($bn, 0, strlen($bn) - 5));
                 }
             }
             if (DEBUG && file_exists(CONFIG_DIR . "/config.debug.json")) {
                 $conf->append(CONFIG_DIR . "/config.debug.json");
             }
             $confsave = $conf->getData();
             foreach ($conf->get("plugins", array()) as $plugin) {
                 Plugins::add($plugin);
             }
             foreach (array_reverse(Plugins::findAll(self::config)) as $dirname) {
                 if (file_exists($dirname . "/config.json")) {
                     $conf->append($dirname . "/config.json");
                 }
                 foreach (glob($dirname . "/*.json") as $file) {
                     $bn = basename($file);
                     if (substr($bn, 0, 7) != "config.") {
                         $conf->append($file, false, substr($bn, 0, strlen($bn) - 5));
                     }
                 }
             }
             Plugins::dispatchAllReversed("config", $conf);
             $conf->merge($confsave);
             ArrayWriter::toFile($conf->getData(), $cache->getFilename());
         } else {
             $conf->setData(ArrayWriter::fromFile($cache->getFilename()));
             foreach ($conf->get("plugins", array()) as $plugin) {
                 Plugins::add($plugin);
             }
         }
         $memcache["JCONFIG_FILE"] = $conf->getData();
     }
 }
Ejemplo n.º 2
0
 protected function minifyStylesheet($filename)
 {
     if ($this->isMin($filename)) {
         return file_get_contents($filename);
     } elseif (($item_min = $this->hasMin($filename)) !== false) {
         return file_get_contents($item_min);
     } else {
         $min = Cache::Priv($filename);
         if ($min->check()) {
             if (MINIFY_YUI) {
                 exec("yui-compressor --nomunge --type css '{$filename}'", $datamin, $ret);
                 if ($ret !== 0) {
                     $datamin = file_get_contents($filename);
                 }
             } else {
                 $less = new Less();
                 $less->enableMinify();
                 $datamin = $less->compileFile($filename);
             }
             $min->setContents($datamin);
             return $datamin;
         } else {
             return $min->getContents();
         }
     }
 }