From 84a76017d77af73cc3095cc281694f13286c8bc7 Mon Sep 17 00:00:00 2001 From: ahwelp Date: Tue, 24 Jan 2023 13:49:06 +0000 Subject: [PATCH] Fixing identation --- .gitignore | 0 composer.json | 0 src/Schema/Db/Adapter/AdapterFactory.php | 50 ++++++++++------- src/Schema/Db/Table.php | 71 +++++++++++++----------- src/Schema/Wrapper.php | 55 +++++++----------- src/index.php | 0 6 files changed, 87 insertions(+), 89 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 composer.json mode change 100644 => 100755 src/index.php diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 diff --git a/src/Schema/Db/Adapter/AdapterFactory.php b/src/Schema/Db/Adapter/AdapterFactory.php index 1ea0ca2..d1e57da 100755 --- a/src/Schema/Db/Adapter/AdapterFactory.php +++ b/src/Schema/Db/Adapter/AdapterFactory.php @@ -52,7 +52,7 @@ class AdapterFactory public static function instance() { if (!static::$instance) { - static::$instance = new static(); + static::$instance = new static (); } return static::$instance; } @@ -63,8 +63,8 @@ class AdapterFactory * @var array */ protected $adapters = array( - 'mysql' => 'Phinx\Db\Adapter\MysqlAdapter', - 'pgsql' => 'Phinx\Db\Adapter\PostgresAdapter', + 'mysql' => 'Phinx\Db\Adapter\MysqlAdapter', + 'pgsql' => 'Phinx\Db\Adapter\PostgresAdapter', 'sqlite' => 'Phinx\Db\Adapter\SQLiteAdapter', 'sqlsrv' => 'Phinx\Db\Adapter\SqlServerAdapter', ); @@ -76,7 +76,7 @@ class AdapterFactory */ protected $wrappers = array( 'prefix' => 'Phinx\Db\Adapter\TablePrefixAdapter', - 'proxy' => 'Phinx\Db\Adapter\ProxyAdapter', + 'proxy' => 'Phinx\Db\Adapter\ProxyAdapter', ); /** @@ -90,10 +90,12 @@ class AdapterFactory public function registerAdapter($name, $class) { if (!is_subclass_of($class, 'Phinx\Db\Adapter\AdapterInterface')) { - throw new \RuntimeException(sprintf( - 'Adapter class "%s" must implement Phinx\\Db\\Adapter\\AdapterInterface', - $class - )); + throw new \RuntimeException( + sprintf( + 'Adapter class "%s" must implement Phinx\\Db\\Adapter\\AdapterInterface', + $class + ) + ); } $this->adapters[$name] = $class; return $this; @@ -109,10 +111,12 @@ class AdapterFactory protected function getClass($name) { if (empty($this->adapters[$name])) { - throw new \RuntimeException(sprintf( - 'Adapter "%s" has not been registered', - $name - )); + throw new \RuntimeException( + sprintf( + 'Adapter "%s" has not been registered', + $name + ) + ); } return $this->adapters[$name]; } @@ -141,10 +145,12 @@ class AdapterFactory public function registerWrapper($name, $class) { if (!is_subclass_of($class, 'Phinx\Db\Adapter\WrapperInterface')) { - throw new \RuntimeException(sprintf( - 'Wrapper class "%s" must be implement Phinx\\Db\\Adapter\\WrapperInterface', - $class - )); + throw new \RuntimeException( + sprintf( + 'Wrapper class "%s" must be implement Phinx\\Db\\Adapter\\WrapperInterface', + $class + ) + ); } $this->wrappers[$name] = $class; return $this; @@ -160,10 +166,12 @@ class AdapterFactory protected function getWrapperClass($name) { if (empty($this->wrappers[$name])) { - throw new \RuntimeException(sprintf( - 'Wrapper "%s" has not been registered', - $name - )); + throw new \RuntimeException( + sprintf( + 'Wrapper "%s" has not been registered', + $name + ) + ); } return $this->wrappers[$name]; } @@ -180,4 +188,4 @@ class AdapterFactory $class = $this->getWrapperClass($name); return new $class($adapter); } -} +} \ No newline at end of file diff --git a/src/Schema/Db/Table.php b/src/Schema/Db/Table.php index 14d9623..b6793f6 100755 --- a/src/Schema/Db/Table.php +++ b/src/Schema/Db/Table.php @@ -1,4 +1,5 @@ setOptions($options); if (null !== $adapter) { - //echo 'Adapter definido'; $this->setAdapter($adapter); } } @@ -349,11 +351,13 @@ class Table // Delegate to Adapters to check column type if (!$this->getAdapter()->isValidColumnType($column)) { - throw new \InvalidArgumentException(sprintf( - 'An invalid column type "%s" was specified for column "%s".', - $column->getType(), - $column->getName() - )); + throw new \InvalidArgumentException( + sprintf( + 'An invalid column type "%s" was specified for column "%s".', + $column->getType(), + $column->getName() + ) + ); } $this->columns[] = $column; @@ -513,8 +517,8 @@ class Table $fk->setReferencedTable(new Table($referencedTable, array(), $this->adapter)); } $fk->setColumns($columns) - ->setReferencedColumns($referencedColumns) - ->setOptions($options); + ->setReferencedColumns($referencedColumns) + ->setOptions($options); $this->foreignKeys[] = $fk; return $this; @@ -566,34 +570,36 @@ class Table $createdAtColumnName = is_null($createdAtColumnName) ? 'created_at' : $createdAtColumnName; $updatedAtColumnName = is_null($updatedAtColumnName) ? 'updated_at' : $updatedAtColumnName; $this->addColumn($createdAtColumnName, 'timestamp', array( + 'default' => 'CURRENT_TIMESTAMP', + 'update' => '' + ) + ) + ->addColumn($updatedAtColumnName, 'timestamp', array( 'default' => 'CURRENT_TIMESTAMP', - 'update' => '' - )) - ->addColumn($updatedAtColumnName, 'timestamp', array( - 'null' => true, - 'default' => null - )); + ) + ); return $this; } - /** - * Add deleted_at column to the table. - * - * @param string $deletedAtColumnName - * - * @return Table + /** + * Add deleted_at column to the table. + * + * @param string $deletedAtColumnName + * + * @return Table */ - public function addSoftDelete($deletedAtColumnName = 'deleted_at'){ - $deletedAtColumnName = is_null($deletedAtColumnName) ? 'deleted_at' : $deletedAtColumnName; + public function addSoftDelete($deletedAtColumnName = 'deleted_at') + { + $deletedAtColumnName = is_null($deletedAtColumnName) ? 'deleted_at' : $deletedAtColumnName; $this->addColumn($deletedAtColumnName, 'timestamp', array( 'default' => null, - 'null' => true, - )); + 'null' => true, + ) + ); return $this; - } - - + } + /** * Insert data into the table. * @@ -626,10 +632,10 @@ class Table */ public function create() { - if (!$this->getAdapter()->hasTable($this->name)) { - $this->getAdapter()->createTable($this); - $this->saveData(); - $this->reset(); // reset pending changes + if (!$this->getAdapter()->hasTable($this->name)) { + $this->getAdapter()->createTable($this); + $this->saveData(); + $this->reset(); // reset pending changes } } @@ -691,4 +697,5 @@ class Table $this->reset(); // reset pending changes } -} + +} \ No newline at end of file diff --git a/src/Schema/Wrapper.php b/src/Schema/Wrapper.php index f7b10b3..f51926b 100755 --- a/src/Schema/Wrapper.php +++ b/src/Schema/Wrapper.php @@ -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); } diff --git a/src/index.php b/src/index.php old mode 100644 new mode 100755