public static function getPool($identifier) { \utils::deprecated(__CLASS__ . "::getPool", "\\Cherry\\Core\\ConfigManager::get"); if (array_key_exists($identifier, self::$pools)) { $pool = self::$pools[$identifier]; if (!array_key_exists($pool->cfghash, self::$configfiles)) { $path = $pool->cfgpath; $cpath = dirname($path) . '/.' . basename($path) . '.cache'; if (file_exists($path)) { // Check for a serialized cache of the config if (file_exists($cpath) && filemtime($cpath) > filemtime($path)) { // Load from cache self::debug("Reading config '{$identifier}' from cache..."); $tag = unserialize(file_get_contents($cpath)); } else { // Update cache self::debug("Updating cache for config '{$identifier}'..."); $tag = SdlTag::createFromFile($path); file_put_contents($cpath, serialize($tag)); } self::$configfiles[$pool->cfghash] = $tag; } else { self::debug("File not found: {$path}"); self::$configfiles[$pool->cfghash] = null; } } return self::$configfiles[$pool->cfghash]; } else { self::debug("Error: Pool has not been bound: {$identifier}"); return null; } }
public function load($filename, $output = false) { $doc = SdlTag::createFromFile($filename); $out = ""; foreach ($doc->getChildren() as $child) { $out .= $this->buildNodeTree($child); } if (class_exists("tidy")) { $t = new \tidy(); $cfg = ["indent" => true, "wrap" => 200, "doctype" => "omit"]; $t->parseString($out, $cfg, 'utf8'); $t->cleanRepair(); $out = (string) $t; } $out = "<!DOCTYPE HTML>\n" . $out; if ($output) { echo $out; } return $out; }
static function getInstance($pool = null) { if (!$pool) { $pool = self::POOL_DEFAULT; } if (!self::$connections) { $cp = PathResolver::path("{APP}/config/database.sdl"); if (file_exists($cp)) { $cfg = SdlTag::createFromFile($cp); foreach ($cfg->query("database/connection") as $connection) { $cpool = $connection[0]; $curi = $connection[1]; if (empty(self::$connections[$cpool])) { self::$connections[$cpool] = []; } self::sdebug("Database: Registered connection '{$curi}' to pool {$cpool}"); self::$connections[$cpool][] = $connection; } } } if (!self::$connections) { self::$connections = []; } if (!array_key_exists($pool, self::$dbpool)) { if (array_key_exists($pool, self::$connections)) { $pc = self::$connections[$pool]; if (is_array($pc)) { $dp = $pc[0][1]; } else { $dp = $pc[1]; } //var_dump($pool); //die(); //self::$dbpool[$pool] = new self(self::$connections[$pool]); $opts = ["pool" => $pool]; self::$dbpool[$pool] = new self($dp, $opts); } else { if (strpos($pool, "://") !== false) { self::$dbpool[$pool] = new self($pool); } else { throw new \UnexpectedValueException("Unable to connect to pool {$pool}"); } } } return self::$dbpool[$pool]; }