From 2230dd4e6b148346c0ec596b9e3e12996a762ed8 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 22 May 2014 12:28:28 -0400 Subject: Code refactoring (add autoloader and change files organization) --- app/common.php | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/common.php (limited to 'app/common.php') diff --git a/app/common.php b/app/common.php new file mode 100644 index 00000000..5a26860f --- /dev/null +++ b/app/common.php @@ -0,0 +1,98 @@ +execute(); + +$registry = new Registry; + +$registry->db = function() use ($registry) { + require __DIR__.'/../vendor/PicoDb/Database.php'; + + if (DB_DRIVER === 'sqlite') { + + require __DIR__.'/Schema/Sqlite.php'; + + $db = new \PicoDb\Database(array( + 'driver' => 'sqlite', + 'filename' => DB_FILENAME + )); + } + elseif (DB_DRIVER === 'mysql') { + + require __DIR__.'/Schema/Mysql.php'; + + $db = new \PicoDb\Database(array( + 'driver' => 'mysql', + 'hostname' => DB_HOSTNAME, + 'username' => DB_USERNAME, + 'password' => DB_PASSWORD, + 'database' => DB_NAME, + 'charset' => 'utf8', + )); + } + else { + die('Database driver not supported'); + } + + if ($db->schema()->check(Schema\VERSION)) { + return $db; + } + else { + die('Unable to migrate database schema!'); + } +}; + +$registry->event = function() use ($registry) { + return new Event; +}; -- cgit v1.2.3