From 2044d1ab3617c951368b8c13c6f2d324d16267cc Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 16 Feb 2014 17:37:50 -0500 Subject: Update PicoDb --- vendor/PicoDb/Database.php | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'vendor') 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(); + } } -- cgit v1.2.3