|
|
@@ -9,32 +9,8 @@ use Schema\Db\Adapter\MysqlAdapter;
|
|
|
use Schema\Db\Adapter\SQLiteAdapter;
|
|
|
use Schema\Db\Adapter\SqlServerAdapter;
|
|
|
|
|
|
-/*
|
|
|
-* @ctag Wrapper::get_table('table');
|
|
|
-* @ctag Wrapper::exec('table');
|
|
|
-*
|
|
|
-* @ctag $table->addColumn('column', 'type', $options = array());
|
|
|
-* @ctag $table->addColumn('column', 'string', $options = array( 'null' => true, 'default' => '' ) );
|
|
|
-* @ctag $table->addColumn('column', 'integer', $options = array( 'null' => true, 'default' => 0 ) );
|
|
|
-* @ctag $table->addColumn('column', 'text', $options = array( 'null' => true, 'default'=> '' ) );
|
|
|
-* @ctag $table->hasColumn('column');
|
|
|
-*
|
|
|
-* @ctag $table->addTimestamps();
|
|
|
-* @ctag $table->addTimestamps('created_at', 'updated_at');
|
|
|
-* @ctag $table->addSoftDelete();
|
|
|
-* @ctag $table->addSoftDelete($deletedAtColumnName = 'deleted_at');
|
|
|
-*
|
|
|
-* @ctag $table->addSoftDelete();
|
|
|
-* @ctag $table->removeColumn('column');
|
|
|
-* @ctag $table->renameColumn('column', 'newName');
|
|
|
-* @ctag $table->changeColumn('column', 'type', $options = array());
|
|
|
-*
|
|
|
-* @ctag $table->addForeignKey(Array('column'), 'remoteTable', Array('remoteColumn'), $options = array());
|
|
|
-* @ctag $table->addIndex($columns, $options = array());
|
|
|
-*
|
|
|
-*/
|
|
|
-
|
|
|
-class Wrapper{
|
|
|
+class Wrapper
|
|
|
+{
|
|
|
|
|
|
private static $_instance;
|
|
|
|
|
|
@@ -44,14 +20,16 @@ class Wrapper{
|
|
|
function __construct(){ }
|
|
|
|
|
|
//SINGLETON==============================================
|
|
|
- private static function newObj(){
|
|
|
+ private static function newObj()
|
|
|
+ {
|
|
|
if (!isset(self::$_instance)) {
|
|
|
self::$_instance = new Wrapper();
|
|
|
}
|
|
|
return self::$_instance;
|
|
|
}
|
|
|
|
|
|
- public static function getInstance(){
|
|
|
+ public static function getInstance()
|
|
|
+ {
|
|
|
if (!isset(self::$_instance)) {
|
|
|
return self::newObj();
|
|
|
}
|
|
|
@@ -59,7 +37,8 @@ class Wrapper{
|
|
|
}
|
|
|
//=======================================================
|
|
|
|
|
|
- public static function set_driver(\PDO $driver){
|
|
|
+ public static function set_driver(\PDO $driver)
|
|
|
+ {
|
|
|
$instance = self::getInstance();
|
|
|
$instance->_driver = $driver;
|
|
|
|
|
|
@@ -80,30 +59,34 @@ class Wrapper{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function get_table($name){
|
|
|
+ public static function get_table($name)
|
|
|
+ {
|
|
|
$instance = self::getInstance();
|
|
|
-
|
|
|
+
|
|
|
if( $instance->_adapter->getConnection()->prefix ){
|
|
|
$name = $instance->_adapter->getConnection()->prefix . $name;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return new Table($name, Array(), $instance->_adapter);
|
|
|
}
|
|
|
|
|
|
- public static function begin(){
|
|
|
+ public static function begin()
|
|
|
+ {
|
|
|
$instance = self::getInstance();
|
|
|
$instance->_adapter->beginTransaction();
|
|
|
}
|
|
|
|
|
|
- public static function commit(){
|
|
|
+ public static function commit()
|
|
|
+ {
|
|
|
$instance = self::getInstance();
|
|
|
$instance->_adapter->commitTransaction();
|
|
|
}
|
|
|
|
|
|
- public static function exec($sql){
|
|
|
+ public static function exec($sql)
|
|
|
+ {
|
|
|
$instance = self::getInstance();
|
|
|
$prefix = $instance->_adapter->getConnection()->prefix;
|
|
|
- $sql = preg_replace('/{(.*)}/', "$prefix$1", $sql);
|
|
|
+ $sql = preg_replace('/{.*?}/', "$prefix$1", $sql);
|
|
|
$instance->_driver->exec($sql);
|
|
|
}
|
|
|
|