Fixing identation
This commit is contained in:
Regular → Executable
Regular → Executable
@@ -52,7 +52,7 @@ class AdapterFactory
|
|||||||
public static function instance()
|
public static function instance()
|
||||||
{
|
{
|
||||||
if (!static::$instance) {
|
if (!static::$instance) {
|
||||||
static::$instance = new static();
|
static::$instance = new static ();
|
||||||
}
|
}
|
||||||
return static::$instance;
|
return static::$instance;
|
||||||
}
|
}
|
||||||
@@ -90,10 +90,12 @@ class AdapterFactory
|
|||||||
public function registerAdapter($name, $class)
|
public function registerAdapter($name, $class)
|
||||||
{
|
{
|
||||||
if (!is_subclass_of($class, 'Phinx\Db\Adapter\AdapterInterface')) {
|
if (!is_subclass_of($class, 'Phinx\Db\Adapter\AdapterInterface')) {
|
||||||
throw new \RuntimeException(sprintf(
|
throw new \RuntimeException(
|
||||||
|
sprintf(
|
||||||
'Adapter class "%s" must implement Phinx\\Db\\Adapter\\AdapterInterface',
|
'Adapter class "%s" must implement Phinx\\Db\\Adapter\\AdapterInterface',
|
||||||
$class
|
$class
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$this->adapters[$name] = $class;
|
$this->adapters[$name] = $class;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -109,10 +111,12 @@ class AdapterFactory
|
|||||||
protected function getClass($name)
|
protected function getClass($name)
|
||||||
{
|
{
|
||||||
if (empty($this->adapters[$name])) {
|
if (empty($this->adapters[$name])) {
|
||||||
throw new \RuntimeException(sprintf(
|
throw new \RuntimeException(
|
||||||
|
sprintf(
|
||||||
'Adapter "%s" has not been registered',
|
'Adapter "%s" has not been registered',
|
||||||
$name
|
$name
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $this->adapters[$name];
|
return $this->adapters[$name];
|
||||||
}
|
}
|
||||||
@@ -141,10 +145,12 @@ class AdapterFactory
|
|||||||
public function registerWrapper($name, $class)
|
public function registerWrapper($name, $class)
|
||||||
{
|
{
|
||||||
if (!is_subclass_of($class, 'Phinx\Db\Adapter\WrapperInterface')) {
|
if (!is_subclass_of($class, 'Phinx\Db\Adapter\WrapperInterface')) {
|
||||||
throw new \RuntimeException(sprintf(
|
throw new \RuntimeException(
|
||||||
|
sprintf(
|
||||||
'Wrapper class "%s" must be implement Phinx\\Db\\Adapter\\WrapperInterface',
|
'Wrapper class "%s" must be implement Phinx\\Db\\Adapter\\WrapperInterface',
|
||||||
$class
|
$class
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$this->wrappers[$name] = $class;
|
$this->wrappers[$name] = $class;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -160,10 +166,12 @@ class AdapterFactory
|
|||||||
protected function getWrapperClass($name)
|
protected function getWrapperClass($name)
|
||||||
{
|
{
|
||||||
if (empty($this->wrappers[$name])) {
|
if (empty($this->wrappers[$name])) {
|
||||||
throw new \RuntimeException(sprintf(
|
throw new \RuntimeException(
|
||||||
|
sprintf(
|
||||||
'Wrapper "%s" has not been registered',
|
'Wrapper "%s" has not been registered',
|
||||||
$name
|
$name
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $this->wrappers[$name];
|
return $this->wrappers[$name];
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-10
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phinx
|
* Phinx
|
||||||
*
|
*
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
* @package Phinx
|
* @package Phinx
|
||||||
* @subpackage Phinx\Db
|
* @subpackage Phinx\Db
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Schema\Db;
|
namespace Schema\Db;
|
||||||
|
|
||||||
use Schema\Db\Table\Column;
|
use Schema\Db\Table\Column;
|
||||||
@@ -39,6 +41,7 @@ use Schema\Db\Adapter\AdapterInterface;
|
|||||||
*/
|
*/
|
||||||
class Table
|
class Table
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@@ -87,7 +90,6 @@ class Table
|
|||||||
$this->setOptions($options);
|
$this->setOptions($options);
|
||||||
|
|
||||||
if (null !== $adapter) {
|
if (null !== $adapter) {
|
||||||
//echo 'Adapter definido';
|
|
||||||
$this->setAdapter($adapter);
|
$this->setAdapter($adapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -349,11 +351,13 @@ class Table
|
|||||||
|
|
||||||
// Delegate to Adapters to check column type
|
// Delegate to Adapters to check column type
|
||||||
if (!$this->getAdapter()->isValidColumnType($column)) {
|
if (!$this->getAdapter()->isValidColumnType($column)) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(
|
||||||
|
sprintf(
|
||||||
'An invalid column type "%s" was specified for column "%s".',
|
'An invalid column type "%s" was specified for column "%s".',
|
||||||
$column->getType(),
|
$column->getType(),
|
||||||
$column->getName()
|
$column->getName()
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->columns[] = $column;
|
$this->columns[] = $column;
|
||||||
@@ -568,11 +572,12 @@ class Table
|
|||||||
$this->addColumn($createdAtColumnName, 'timestamp', array(
|
$this->addColumn($createdAtColumnName, 'timestamp', array(
|
||||||
'default' => 'CURRENT_TIMESTAMP',
|
'default' => 'CURRENT_TIMESTAMP',
|
||||||
'update' => ''
|
'update' => ''
|
||||||
))
|
)
|
||||||
|
)
|
||||||
->addColumn($updatedAtColumnName, 'timestamp', array(
|
->addColumn($updatedAtColumnName, 'timestamp', array(
|
||||||
'null' => true,
|
'default' => 'CURRENT_TIMESTAMP',
|
||||||
'default' => null
|
)
|
||||||
));
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -584,16 +589,17 @@ class Table
|
|||||||
*
|
*
|
||||||
* @return Table
|
* @return Table
|
||||||
*/
|
*/
|
||||||
public function addSoftDelete($deletedAtColumnName = 'deleted_at'){
|
public function addSoftDelete($deletedAtColumnName = 'deleted_at')
|
||||||
|
{
|
||||||
$deletedAtColumnName = is_null($deletedAtColumnName) ? 'deleted_at' : $deletedAtColumnName;
|
$deletedAtColumnName = is_null($deletedAtColumnName) ? 'deleted_at' : $deletedAtColumnName;
|
||||||
$this->addColumn($deletedAtColumnName, 'timestamp', array(
|
$this->addColumn($deletedAtColumnName, 'timestamp', array(
|
||||||
'default' => null,
|
'default' => null,
|
||||||
'null' => true,
|
'null' => true,
|
||||||
));
|
)
|
||||||
|
);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert data into the table.
|
* Insert data into the table.
|
||||||
*
|
*
|
||||||
@@ -691,4 +697,5 @@ class Table
|
|||||||
|
|
||||||
$this->reset(); // reset pending changes
|
$this->reset(); // reset pending changes
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+17
-34
@@ -9,32 +9,8 @@ use Schema\Db\Adapter\MysqlAdapter;
|
|||||||
use Schema\Db\Adapter\SQLiteAdapter;
|
use Schema\Db\Adapter\SQLiteAdapter;
|
||||||
use Schema\Db\Adapter\SqlServerAdapter;
|
use Schema\Db\Adapter\SqlServerAdapter;
|
||||||
|
|
||||||
/*
|
class Wrapper
|
||||||
* @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{
|
|
||||||
|
|
||||||
private static $_instance;
|
private static $_instance;
|
||||||
|
|
||||||
@@ -44,14 +20,16 @@ class Wrapper{
|
|||||||
function __construct(){ }
|
function __construct(){ }
|
||||||
|
|
||||||
//SINGLETON==============================================
|
//SINGLETON==============================================
|
||||||
private static function newObj(){
|
private static function newObj()
|
||||||
|
{
|
||||||
if (!isset(self::$_instance)) {
|
if (!isset(self::$_instance)) {
|
||||||
self::$_instance = new Wrapper();
|
self::$_instance = new Wrapper();
|
||||||
}
|
}
|
||||||
return self::$_instance;
|
return self::$_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getInstance(){
|
public static function getInstance()
|
||||||
|
{
|
||||||
if (!isset(self::$_instance)) {
|
if (!isset(self::$_instance)) {
|
||||||
return self::newObj();
|
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 = self::getInstance();
|
||||||
$instance->_driver = $driver;
|
$instance->_driver = $driver;
|
||||||
|
|
||||||
@@ -80,7 +59,8 @@ class Wrapper{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_table($name){
|
public static function get_table($name)
|
||||||
|
{
|
||||||
$instance = self::getInstance();
|
$instance = self::getInstance();
|
||||||
|
|
||||||
if( $instance->_adapter->getConnection()->prefix ){
|
if( $instance->_adapter->getConnection()->prefix ){
|
||||||
@@ -90,20 +70,23 @@ class Wrapper{
|
|||||||
return new Table($name, Array(), $instance->_adapter);
|
return new Table($name, Array(), $instance->_adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function begin(){
|
public static function begin()
|
||||||
|
{
|
||||||
$instance = self::getInstance();
|
$instance = self::getInstance();
|
||||||
$instance->_adapter->beginTransaction();
|
$instance->_adapter->beginTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function commit(){
|
public static function commit()
|
||||||
|
{
|
||||||
$instance = self::getInstance();
|
$instance = self::getInstance();
|
||||||
$instance->_adapter->commitTransaction();
|
$instance->_adapter->commitTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function exec($sql){
|
public static function exec($sql)
|
||||||
|
{
|
||||||
$instance = self::getInstance();
|
$instance = self::getInstance();
|
||||||
$prefix = $instance->_adapter->getConnection()->prefix;
|
$prefix = $instance->_adapter->getConnection()->prefix;
|
||||||
$sql = preg_replace('/{(.*)}/', "$prefix$1", $sql);
|
$sql = preg_replace('/{.*?}/', "$prefix$1", $sql);
|
||||||
$instance->_driver->exec($sql);
|
$instance->_driver->exec($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Regular → Executable
Reference in New Issue
Block a user