diff options
author | Frédéric Guillot <contact@fredericguillot.com> | 2014-02-16 17:37:50 -0500 |
---|---|---|
committer | Frédéric Guillot <contact@fredericguillot.com> | 2014-02-16 17:37:50 -0500 |
commit | 2044d1ab3617c951368b8c13c6f2d324d16267cc (patch) | |
tree | fa2166d7f5e22469de9a30a41278f197c0039751 | |
parent | 6fdf5894559ed24607658c5beab44853cc876482 (diff) |
Update PicoDb
-rw-r--r-- | vendor/PicoDb/Database.php | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/vendor/PicoDb/Database.php b/vendor/PicoDb/Database.php index c3405f72..86f5fe3c 100644 --- a/vendor/PicoDb/Database.php +++ b/vendor/PicoDb/Database.php @@ -4,6 +4,7 @@ namespace PicoDb; class Database { + private static $instances = array(); private $logs = array(); private $pdo; @@ -11,7 +12,6 @@ class Database public function __construct(array $settings) { if (! isset($settings['driver'])) { - throw new \LogicException('You must define a database driver.'); } @@ -30,6 +30,26 @@ class Database } + public static function bootstrap($name, \Closure $callback) + { + self::$instances[$name] = $callback; + } + + + public static function get($name) + { + if (! isset(self::$instances[$name])) { + throw new \LogicException('No database instance created with that name.'); + } + + if (is_callable(self::$instances[$name])) { + self::$instances[$name] = call_user_func(self::$instances[$name]); + } + + return self::$instances[$name]; + } + + public function setLogMessage($message) { $this->logs[] = $message; @@ -77,19 +97,25 @@ class Database public function startTransaction() { - $this->pdo->beginTransaction(); + if (! $this->pdo->inTransaction()) { + $this->pdo->beginTransaction(); + } } public function closeTransaction() { - $this->pdo->commit(); + if ($this->pdo->inTransaction()) { + $this->pdo->commit(); + } } public function cancelTransaction() { - $this->pdo->rollback(); + if ($this->pdo->inTransaction()) { + $this->pdo->rollback(); + } } |