Refactored to 2 namespaces: Wootook & Legacies
Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
parent
cfeb6aca6d
commit
ec7e40e1aa
1004 changed files with 4808 additions and 2971 deletions
51
application/code/core/Wootook/Database.php
Normal file
51
application/code/core/Wootook/Database.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
class Wootook_Database
|
||||
extends PDO
|
||||
{
|
||||
protected static $_singleton = null;
|
||||
|
||||
protected static $_prefix = null;
|
||||
|
||||
public static $options = array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
$config = include ROOT_PATH . 'config.php';
|
||||
$hostname = $config['global']['database']['options']['hostname'];
|
||||
$username = $config['global']['database']['options']['username'];
|
||||
$password = $config['global']['database']['options']['password'];
|
||||
$database = $config['global']['database']['options']['database'];
|
||||
$port = 3306;
|
||||
|
||||
if (isset($config['global']['database']['options']['port'])) {
|
||||
$port = $config['global']['database']['options']['port'];
|
||||
}
|
||||
|
||||
$event = Wootook::dispatchEvent('database.prepare-options', array(
|
||||
'options' => self::$options
|
||||
));
|
||||
|
||||
self::$options = $event->getData('options');
|
||||
|
||||
self::$_singleton = new self("mysql:dbname={$database};host={$hostname};port={$port}", $username, $password, self::$options);
|
||||
|
||||
Wootook::dispatchEvent('database.init', array(
|
||||
'handler' => self::$_singleton
|
||||
));
|
||||
}
|
||||
return self::$_singleton;
|
||||
}
|
||||
|
||||
public function getTable($name)
|
||||
{
|
||||
if (self::$_prefix === null) {
|
||||
$config = include ROOT_PATH . 'config.php';
|
||||
self::$_prefix = $config['global']['database']['table_prefix'];
|
||||
}
|
||||
return self::$_prefix . $name;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue