Example #1
0
 public static function bind($identifier, $config, $writeable = false)
 {
     // If the file name contains a path, resolve it via pathresolver,
     // otherwise try to detect the location of the configuration file.
     if (strpos($config, "/") !== false) {
         $cfgpath = PathResolver::path($config);
     } else {
         $test = PathResolver::path("{APP}/{$config}");
         if (file_exists($test)) {
             $cfgpath = $test;
         } else {
             $test = PathResolver::path("{APP}/config/{$config}");
             if (file_exists($test)) {
                 $cfgpath = $test;
             }
         }
     }
     $cfghash = sha1($cfgpath);
     if (array_key_exists($identifier, self::$pools)) {
         // Key exists, make sure it's the same config file
         if (self::$pools[$identifier]->cfgpath == $cfgpath) {
             // Already set up, so update flags and return.
             self::$pools[$identifier]->writeable = $writeable;
             self::debug("Pool already bound. Updating flags for '{$identifier}");
             return true;
         }
     }
     self::debug("Binding pool '{$identifier}' to '{$cfgpath}'");
     $poolinfo = (object) ['id' => $identifier, 'cfgpath' => $cfgpath, 'cfghash' => $cfghash, 'writeable' => $writeable];
     self::$pools[$identifier] = $poolinfo;
 }
Example #2
0
 public function __construct($store = null, $key = null)
 {
     if (!$store) {
         $store = PathResolver::path("{DATA}/default.cks");
     }
     if (file_exists($store)) {
         $this->attachFile($store, $key);
     }
 }
Example #3
0
 public static function bindPool($config, $identifier, $writeable = false)
 {
     \utils::deprecated(__CLASS__ . "::bindPool", "\\Cherry\\Core\\ConfigManager::bind");
     $cfgpath = PathResolver::path($config);
     $cfghash = sha1($cfgpath);
     if (array_key_exists($identifier, self::$pools)) {
         // Key exists, make sure it's the same config file
         if (self::$pools[$identifier]->cfgpath == $cfgpath) {
             // Already set up, so update flags and return.
             self::$pools[$identifier]->writeable = $writeable;
             self::debug("Pool already bound. Updating flags for '{$identifier}");
             return true;
         }
     }
     self::debug("Binding pool '{$identifier}' to '{$cfgpath}'");
     $poolinfo = (object) ['id' => $identifier, 'cfgpath' => $cfgpath, 'cfghash' => $cfghash, 'writeable' => $writeable];
     self::$pools[$identifier] = $poolinfo;
 }
Example #4
0
function p($path)
{
    return \Cherry\Core\PathResolver::path($path);
}
Example #5
0
 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];
 }