protected static function loadDefault(Iface $stockpile, $name, $dsn) { $db = Connection::instance($dsn); if (!$db instanceof \Gaia\DB\ExtendedIface) { $db = new \Gaia\DB($db); } if ($db->isa('mysql')) { $classname = 'Gaia\\Stockpile\\Storage\\MySQL\\' . $name; } elseif ($db->isa('sqlite')) { $classname = 'Gaia\\Stockpile\\Storage\\SQLite\\' . $name; } else { throw new Exception('invalid db driver', $db); } $table = $stockpile->app() . '_stockpile_' . constant($classname . '::TABLE'); $object = new $classname($db, $table, $stockpile->user()); if (!\Gaia\Stockpile\Storage::isAutoSchemaEnabled()) { return $object; } $cache = new Store\Gate(new Store\Apc()); $key = 'stockpile/storage/__create/' . md5($dsn . '/' . Connection::version() . '/' . $table . '/' . $classname); if ($cache->get($key)) { return $object; } if (!$cache->add($key, 1, 60)) { return $object; } $object->create(); return $object; }
public function __construct($db, $app = 'default') { if (!$db instanceof \Gaia\DB\Iface) { $db = new \Gaia\DB($db); } if ($db->isa('mysql')) { $this->core = new \Gaia\NewId\DB\MySQL($db, $app); } elseif ($db->isa('pgsql') || $db->isa('postgre')) { $this->core = new \Gaia\NewId\DB\PgSQL($db, $app); } else { trigger_error('db platform not supported', E_USER_ERROR); exit(1); } }
protected static function loadDefault(Iface $souk, $dsn) { $db = Connection::instance($dsn); if (!$db instanceof \Gaia\DB\Iface) { throw new Exception('invalid db driver', $db); } if (!$db instanceof \Gaia\DB\ExtendedIface) { $db = new \Gaia\DB($db); } if ($db->isa('mysql')) { $classname = 'Gaia\\Souk\\Storage\\MySQL'; } elseif ($db->isa('sqlite')) { $classname = 'Gaia\\Souk\\Storage\\SQLite'; } else { throw new Exception('invalid db driver', $db); } return new $classname($db, $souk->app(), $souk->user(), $dsn . '.' . Connection::version()); }
public function __construct(\Gaia\DB\Iface $db, $app = 'default') { if (!preg_match('/^[a-z0-9_]+$/', $app)) { throw new Exception('invalid-app'); } if (!$db->isa('mysql')) { trigger_error('invalid db layer', E_USER_ERROR); exit(1); } if (!$db->isa('\\gaia\\db\\extendediface')) { $db = new \Gaia\DB($db); } if (!$db->isa('gaia\\db\\except')) { $db = new \Gaia\DB\Except($db); } $this->app = $app; $this->db = $db; }