diff --git a/composer.json b/composer.json index f23a96fb..3bf4f812 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,7 @@ }, "require-dev": { "phpunit/phpunit": "~5.0", - "mockery/mockery": "^0.9.4", - "vlucas/phpdotenv": "^2.1" + "mockery/mockery": "^0.9.4" }, "autoload": { "psr-4": { diff --git a/source/Database/Builders/DeleteQuery.php b/source/Spiral/Database/Builders/DeleteQuery.php similarity index 100% rename from source/Database/Builders/DeleteQuery.php rename to source/Spiral/Database/Builders/DeleteQuery.php diff --git a/source/Database/Builders/InsertQuery.php b/source/Spiral/Database/Builders/InsertQuery.php similarity index 100% rename from source/Database/Builders/InsertQuery.php rename to source/Spiral/Database/Builders/InsertQuery.php diff --git a/source/Database/Builders/Prototypes/AbstractAffect.php b/source/Spiral/Database/Builders/Prototypes/AbstractAffect.php similarity index 100% rename from source/Database/Builders/Prototypes/AbstractAffect.php rename to source/Spiral/Database/Builders/Prototypes/AbstractAffect.php diff --git a/source/Database/Builders/Prototypes/AbstractSelect.php b/source/Spiral/Database/Builders/Prototypes/AbstractSelect.php similarity index 100% rename from source/Database/Builders/Prototypes/AbstractSelect.php rename to source/Spiral/Database/Builders/Prototypes/AbstractSelect.php diff --git a/source/Database/Builders/Prototypes/AbstractWhere.php b/source/Spiral/Database/Builders/Prototypes/AbstractWhere.php similarity index 100% rename from source/Database/Builders/Prototypes/AbstractWhere.php rename to source/Spiral/Database/Builders/Prototypes/AbstractWhere.php diff --git a/source/Database/Builders/QueryBuilder.php b/source/Spiral/Database/Builders/QueryBuilder.php similarity index 100% rename from source/Database/Builders/QueryBuilder.php rename to source/Spiral/Database/Builders/QueryBuilder.php diff --git a/source/Database/Builders/SelectQuery.php b/source/Spiral/Database/Builders/SelectQuery.php similarity index 100% rename from source/Database/Builders/SelectQuery.php rename to source/Spiral/Database/Builders/SelectQuery.php diff --git a/source/Database/Builders/Traits/JoinsTrait.php b/source/Spiral/Database/Builders/Traits/JoinsTrait.php similarity index 100% rename from source/Database/Builders/Traits/JoinsTrait.php rename to source/Spiral/Database/Builders/Traits/JoinsTrait.php diff --git a/source/Database/Builders/UpdateQuery.php b/source/Spiral/Database/Builders/UpdateQuery.php similarity index 100% rename from source/Database/Builders/UpdateQuery.php rename to source/Spiral/Database/Builders/UpdateQuery.php diff --git a/source/Database/Configs/DatabasesConfig.php b/source/Spiral/Database/Configs/DatabasesConfig.php similarity index 100% rename from source/Database/Configs/DatabasesConfig.php rename to source/Spiral/Database/Configs/DatabasesConfig.php diff --git a/source/Database/DatabaseInterface.php b/source/Spiral/Database/DatabaseInterface.php similarity index 100% rename from source/Database/DatabaseInterface.php rename to source/Spiral/Database/DatabaseInterface.php diff --git a/source/Database/DatabaseManager.php b/source/Spiral/Database/DatabaseManager.php similarity index 100% rename from source/Database/DatabaseManager.php rename to source/Spiral/Database/DatabaseManager.php diff --git a/source/Database/Drivers/MySQL/MySQLCompiler.php b/source/Spiral/Database/Drivers/MySQL/MySQLCompiler.php similarity index 100% rename from source/Database/Drivers/MySQL/MySQLCompiler.php rename to source/Spiral/Database/Drivers/MySQL/MySQLCompiler.php diff --git a/source/Database/Drivers/MySQL/MySQLDriver.php b/source/Spiral/Database/Drivers/MySQL/MySQLDriver.php similarity index 100% rename from source/Database/Drivers/MySQL/MySQLDriver.php rename to source/Spiral/Database/Drivers/MySQL/MySQLDriver.php diff --git a/source/Database/Drivers/MySQL/MySQLHandler.php b/source/Spiral/Database/Drivers/MySQL/MySQLHandler.php similarity index 100% rename from source/Database/Drivers/MySQL/MySQLHandler.php rename to source/Spiral/Database/Drivers/MySQL/MySQLHandler.php diff --git a/source/Database/Drivers/MySQL/Schemas/MySQLColumn.php b/source/Spiral/Database/Drivers/MySQL/Schemas/MySQLColumn.php similarity index 100% rename from source/Database/Drivers/MySQL/Schemas/MySQLColumn.php rename to source/Spiral/Database/Drivers/MySQL/Schemas/MySQLColumn.php diff --git a/source/Database/Drivers/MySQL/Schemas/MySQLIndex.php b/source/Spiral/Database/Drivers/MySQL/Schemas/MySQLIndex.php similarity index 100% rename from source/Database/Drivers/MySQL/Schemas/MySQLIndex.php rename to source/Spiral/Database/Drivers/MySQL/Schemas/MySQLIndex.php diff --git a/source/Database/Drivers/MySQL/Schemas/MySQLReference.php b/source/Spiral/Database/Drivers/MySQL/Schemas/MySQLReference.php similarity index 100% rename from source/Database/Drivers/MySQL/Schemas/MySQLReference.php rename to source/Spiral/Database/Drivers/MySQL/Schemas/MySQLReference.php diff --git a/source/Database/Drivers/MySQL/Schemas/MySQLTable.php b/source/Spiral/Database/Drivers/MySQL/Schemas/MySQLTable.php similarity index 100% rename from source/Database/Drivers/MySQL/Schemas/MySQLTable.php rename to source/Spiral/Database/Drivers/MySQL/Schemas/MySQLTable.php diff --git a/source/Database/Drivers/Postgres/PostgresCompiler.php b/source/Spiral/Database/Drivers/Postgres/PostgresCompiler.php similarity index 100% rename from source/Database/Drivers/Postgres/PostgresCompiler.php rename to source/Spiral/Database/Drivers/Postgres/PostgresCompiler.php diff --git a/source/Database/Drivers/Postgres/PostgresDriver.php b/source/Spiral/Database/Drivers/Postgres/PostgresDriver.php similarity index 100% rename from source/Database/Drivers/Postgres/PostgresDriver.php rename to source/Spiral/Database/Drivers/Postgres/PostgresDriver.php diff --git a/source/Database/Drivers/Postgres/PostgresHandler.php b/source/Spiral/Database/Drivers/Postgres/PostgresHandler.php similarity index 100% rename from source/Database/Drivers/Postgres/PostgresHandler.php rename to source/Spiral/Database/Drivers/Postgres/PostgresHandler.php diff --git a/source/Database/Drivers/Postgres/PostgresInsertQuery.php b/source/Spiral/Database/Drivers/Postgres/PostgresInsertQuery.php similarity index 100% rename from source/Database/Drivers/Postgres/PostgresInsertQuery.php rename to source/Spiral/Database/Drivers/Postgres/PostgresInsertQuery.php diff --git a/source/Database/Drivers/Postgres/Schemas/PostgresColumn.php b/source/Spiral/Database/Drivers/Postgres/Schemas/PostgresColumn.php similarity index 100% rename from source/Database/Drivers/Postgres/Schemas/PostgresColumn.php rename to source/Spiral/Database/Drivers/Postgres/Schemas/PostgresColumn.php diff --git a/source/Spiral/Database/Drivers/Postgres/Schemas/PostgresIndex.php b/source/Spiral/Database/Drivers/Postgres/Schemas/PostgresIndex.php new file mode 100644 index 00000000..e15c417f --- /dev/null +++ b/source/Spiral/Database/Drivers/Postgres/Schemas/PostgresIndex.php @@ -0,0 +1,36 @@ +type = strpos($schema['indexdef'], ' UNIQUE ') ? self::UNIQUE : self::NORMAL; + + if (preg_match('/\(([^)]+)\)/', $schema['indexdef'], $matches)) { + $columns = explode(',', $matches[1]); + + foreach ($columns as $column) { + //Postgres adds quotes to all columns with uppercase letters + $index->columns[] = trim($column, ' "\''); + } + } + + return $index; + } +} \ No newline at end of file diff --git a/source/Database/Drivers/Postgres/Schemas/PostgresReference.php b/source/Spiral/Database/Drivers/Postgres/Schemas/PostgresReference.php similarity index 100% rename from source/Database/Drivers/Postgres/Schemas/PostgresReference.php rename to source/Spiral/Database/Drivers/Postgres/Schemas/PostgresReference.php diff --git a/source/Spiral/Database/Drivers/Postgres/Schemas/PostgresTable.php b/source/Spiral/Database/Drivers/Postgres/Schemas/PostgresTable.php new file mode 100644 index 00000000..3998e144 --- /dev/null +++ b/source/Spiral/Database/Drivers/Postgres/Schemas/PostgresTable.php @@ -0,0 +1,221 @@ +primarySequence; + } + + /** + * {@inheritdoc} + * + * SQLServer will reload schemas after successful savw. + */ + public function save( + int $behaviour = Behaviour::DO_ALL, + LoggerInterface $logger = null, + bool $reset = true + ) { + parent::save($behaviour, $logger, $reset); + + if ($reset) { + foreach ($this->fetchColumns() as $column) { + $currentColumn = $this->current->findColumn($column->getName()); + if (!empty($currentColumn) && $column->compare($currentColumn)) { + //Ensure constrained columns + $this->current->registerColumn($column); + } + } + } + } + + + /** + * {@inheritdoc} + */ + protected function fetchColumns(): array + { + //Required for constraints fetch + $tableOID = $this->driver->query('SELECT oid FROM pg_class WHERE relname = ?', [ + $this->getName(), + ])->fetchColumn(); + + $query = $this->driver->query( + 'SELECT * FROM information_schema.columns JOIN pg_type ON (pg_type.typname = columns.udt_name) WHERE table_name = ?', + [$this->getName()] + ); + + $result = []; + foreach ($query->bind('column_name', $name) as $schema) { + if (preg_match( + '/^nextval\([\'"]([a-z0-9_"]+)[\'"](?:::regclass)?\)$/i', + $schema['column_default'], + $matches + )) { + //Column is sequential + $this->sequences[$name] = $matches[1]; + } + + $result[] = PostgresColumn::createInstance( + $this->getName(), + $schema + ['tableOID' => $tableOID], + $this->driver + ); + } + + return $result; + } + + /** + * {@inheritdoc} + */ + protected function fetchIndexes(bool $all = false): array + { + $query = "SELECT * FROM pg_indexes WHERE schemaname = 'public' AND tablename = ?"; + + $result = []; + foreach ($this->driver->query($query, [$this->getName()]) as $schema) { + $conType = $this->driver->query( + 'SELECT contype FROM pg_constraint WHERE conname = ?', + [$schema['indexname']] + )->fetchColumn(); + + if ($conType == 'p') { + //Skipping primary keys + continue; + } + + $result[] = PostgresIndex::createInstance($this->getName(), $schema); + } + + return $result; + } + + /** + * {@inheritdoc} + */ + protected function fetchReferences(): array + { + //Mindblowing + $query = 'SELECT tc.constraint_name, tc.table_name, kcu.column_name, rc.update_rule, ' + . 'rc.delete_rule, ccu.table_name AS foreign_table_name, ' + . "ccu.column_name AS foreign_column_name\n" + . "FROM information_schema.table_constraints AS tc\n" + . "JOIN information_schema.key_column_usage AS kcu\n" + . " ON tc.constraint_name = kcu.constraint_name\n" + . "JOIN information_schema.constraint_column_usage AS ccu\n" + . " ON ccu.constraint_name = tc.constraint_name\n" + . "JOIN information_schema.referential_constraints AS rc\n" + . " ON rc.constraint_name = tc.constraint_name\n" + . "WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = ?"; + + $result = []; + + foreach ($this->driver->query($query, [$this->getName()]) as $schema) { + $result[] = PostgresReference::createInstance( + $this->getName(), + $this->getPrefix(), + $schema + ); + } + + return $result; + } + + /** + * {@inheritdoc} + */ + protected function fetchPrimaryKeys(): array + { + $query = "SELECT * FROM pg_indexes WHERE schemaname = 'public' AND tablename = ?"; + + foreach ($this->driver->query($query, [$this->getName()]) as $schema) { + $conType = $this->driver->query( + 'SELECT contype FROM pg_constraint WHERE conname = ?', + [$schema['indexname']] + )->fetchColumn(); + + if ($conType != 'p') { + //Skipping primary keys + continue; + } + + //To simplify definitions + $index = PostgresIndex::createInstance($this->getName(), $schema); + + if (is_array($this->primarySequence) && count($index->getColumns()) === 1) { + $column = $index->getColumns()[0]; + + if (isset($this->sequences[$column])) { + //We found our primary sequence + $this->primarySequence = $this->sequences[$column]; + } + } + + return $index->getColumns(); + } + + return []; + } + + /** + * {@inheritdoc} + */ + protected function createColumn(string $name): AbstractColumn + { + return new PostgresColumn($this->getName(), $name, $this->driver->getTimezone()); + } + + /** + * {@inheritdoc} + */ + protected function createIndex(string $name): AbstractIndex + { + return new PostgresIndex($this->getName(), $name); + } + + /** + * {@inheritdoc} + */ + protected function createForeign(string $name): AbstractReference + { + return new PostgresReference($this->getName(), $this->getPrefix(), $name); + } +} \ No newline at end of file diff --git a/source/Database/Drivers/SQLServer/SQLServerCompiler.php b/source/Spiral/Database/Drivers/SQLServer/SQLServerCompiler.php similarity index 100% rename from source/Database/Drivers/SQLServer/SQLServerCompiler.php rename to source/Spiral/Database/Drivers/SQLServer/SQLServerCompiler.php diff --git a/source/Database/Drivers/SQLServer/SQLServerDriver.php b/source/Spiral/Database/Drivers/SQLServer/SQLServerDriver.php similarity index 100% rename from source/Database/Drivers/SQLServer/SQLServerDriver.php rename to source/Spiral/Database/Drivers/SQLServer/SQLServerDriver.php diff --git a/source/Database/Drivers/SQLServer/SQLServerHandler.php b/source/Spiral/Database/Drivers/SQLServer/SQLServerHandler.php similarity index 100% rename from source/Database/Drivers/SQLServer/SQLServerHandler.php rename to source/Spiral/Database/Drivers/SQLServer/SQLServerHandler.php diff --git a/source/Database/Drivers/SQLServer/Schemas/SQLServerColumn.php b/source/Spiral/Database/Drivers/SQLServer/Schemas/SQLServerColumn.php similarity index 100% rename from source/Database/Drivers/SQLServer/Schemas/SQLServerColumn.php rename to source/Spiral/Database/Drivers/SQLServer/Schemas/SQLServerColumn.php diff --git a/source/Database/Drivers/SQLServer/Schemas/SQLServerIndex.php b/source/Spiral/Database/Drivers/SQLServer/Schemas/SQLServerIndex.php similarity index 100% rename from source/Database/Drivers/SQLServer/Schemas/SQLServerIndex.php rename to source/Spiral/Database/Drivers/SQLServer/Schemas/SQLServerIndex.php diff --git a/source/Database/Drivers/SQLServer/Schemas/SQLServerTable.php b/source/Spiral/Database/Drivers/SQLServer/Schemas/SQLServerTable.php similarity index 100% rename from source/Database/Drivers/SQLServer/Schemas/SQLServerTable.php rename to source/Spiral/Database/Drivers/SQLServer/Schemas/SQLServerTable.php diff --git a/source/Database/Drivers/SQLServer/Schemas/SQlServerReference.php b/source/Spiral/Database/Drivers/SQLServer/Schemas/SQlServerReference.php similarity index 100% rename from source/Database/Drivers/SQLServer/Schemas/SQlServerReference.php rename to source/Spiral/Database/Drivers/SQLServer/Schemas/SQlServerReference.php diff --git a/source/Database/Drivers/SQLite/SQLiteCompiler.php b/source/Spiral/Database/Drivers/SQLite/SQLiteCompiler.php similarity index 100% rename from source/Database/Drivers/SQLite/SQLiteCompiler.php rename to source/Spiral/Database/Drivers/SQLite/SQLiteCompiler.php diff --git a/source/Database/Drivers/SQLite/SQLiteDriver.php b/source/Spiral/Database/Drivers/SQLite/SQLiteDriver.php similarity index 100% rename from source/Database/Drivers/SQLite/SQLiteDriver.php rename to source/Spiral/Database/Drivers/SQLite/SQLiteDriver.php diff --git a/source/Database/Drivers/SQLite/SQLiteHandler.php b/source/Spiral/Database/Drivers/SQLite/SQLiteHandler.php similarity index 100% rename from source/Database/Drivers/SQLite/SQLiteHandler.php rename to source/Spiral/Database/Drivers/SQLite/SQLiteHandler.php diff --git a/source/Database/Drivers/SQLite/Schemas/SQLiteColumn.php b/source/Spiral/Database/Drivers/SQLite/Schemas/SQLiteColumn.php similarity index 100% rename from source/Database/Drivers/SQLite/Schemas/SQLiteColumn.php rename to source/Spiral/Database/Drivers/SQLite/Schemas/SQLiteColumn.php diff --git a/source/Database/Drivers/SQLite/Schemas/SQLiteIndex.php b/source/Spiral/Database/Drivers/SQLite/Schemas/SQLiteIndex.php similarity index 100% rename from source/Database/Drivers/SQLite/Schemas/SQLiteIndex.php rename to source/Spiral/Database/Drivers/SQLite/Schemas/SQLiteIndex.php diff --git a/source/Database/Drivers/SQLite/Schemas/SQLiteReference.php b/source/Spiral/Database/Drivers/SQLite/Schemas/SQLiteReference.php similarity index 100% rename from source/Database/Drivers/SQLite/Schemas/SQLiteReference.php rename to source/Spiral/Database/Drivers/SQLite/Schemas/SQLiteReference.php diff --git a/source/Database/Drivers/SQLite/Schemas/SQLiteTable.php b/source/Spiral/Database/Drivers/SQLite/Schemas/SQLiteTable.php similarity index 100% rename from source/Database/Drivers/SQLite/Schemas/SQLiteTable.php rename to source/Spiral/Database/Drivers/SQLite/Schemas/SQLiteTable.php diff --git a/source/Database/Entities/AbstractHandler.php b/source/Spiral/Database/Entities/AbstractHandler.php similarity index 100% rename from source/Database/Entities/AbstractHandler.php rename to source/Spiral/Database/Entities/AbstractHandler.php diff --git a/source/Database/Entities/Database.php b/source/Spiral/Database/Entities/Database.php similarity index 100% rename from source/Database/Entities/Database.php rename to source/Spiral/Database/Entities/Database.php diff --git a/source/Database/Entities/Driver.php b/source/Spiral/Database/Entities/Driver.php similarity index 100% rename from source/Database/Entities/Driver.php rename to source/Spiral/Database/Entities/Driver.php diff --git a/source/Database/Entities/PDODriver.php b/source/Spiral/Database/Entities/PDODriver.php similarity index 100% rename from source/Database/Entities/PDODriver.php rename to source/Spiral/Database/Entities/PDODriver.php diff --git a/source/Database/Entities/QueryCompiler.php b/source/Spiral/Database/Entities/QueryCompiler.php similarity index 100% rename from source/Database/Entities/QueryCompiler.php rename to source/Spiral/Database/Entities/QueryCompiler.php diff --git a/source/Database/Entities/QueryStatement.php b/source/Spiral/Database/Entities/QueryStatement.php similarity index 100% rename from source/Database/Entities/QueryStatement.php rename to source/Spiral/Database/Entities/QueryStatement.php diff --git a/source/Database/Entities/Quoter.php b/source/Spiral/Database/Entities/Quoter.php similarity index 100% rename from source/Database/Entities/Quoter.php rename to source/Spiral/Database/Entities/Quoter.php diff --git a/source/Database/Entities/Table.php b/source/Spiral/Database/Entities/Table.php similarity index 100% rename from source/Database/Entities/Table.php rename to source/Spiral/Database/Entities/Table.php diff --git a/source/Database/Exceptions/BuilderException.php b/source/Spiral/Database/Exceptions/BuilderException.php similarity index 100% rename from source/Database/Exceptions/BuilderException.php rename to source/Spiral/Database/Exceptions/BuilderException.php diff --git a/source/Database/Exceptions/CompilerException.php b/source/Spiral/Database/Exceptions/CompilerException.php similarity index 100% rename from source/Database/Exceptions/CompilerException.php rename to source/Spiral/Database/Exceptions/CompilerException.php diff --git a/source/Database/Exceptions/DBALException.php b/source/Spiral/Database/Exceptions/DBALException.php similarity index 100% rename from source/Database/Exceptions/DBALException.php rename to source/Spiral/Database/Exceptions/DBALException.php diff --git a/source/Database/Exceptions/DatabaseException.php b/source/Spiral/Database/Exceptions/DatabaseException.php similarity index 100% rename from source/Database/Exceptions/DatabaseException.php rename to source/Spiral/Database/Exceptions/DatabaseException.php diff --git a/source/Database/Exceptions/DefaultValueException.php b/source/Spiral/Database/Exceptions/DefaultValueException.php similarity index 100% rename from source/Database/Exceptions/DefaultValueException.php rename to source/Spiral/Database/Exceptions/DefaultValueException.php diff --git a/source/Database/Exceptions/DriverException.php b/source/Spiral/Database/Exceptions/DriverException.php similarity index 100% rename from source/Database/Exceptions/DriverException.php rename to source/Spiral/Database/Exceptions/DriverException.php diff --git a/source/Database/Exceptions/Drivers/MySQLDriverException.php b/source/Spiral/Database/Exceptions/Drivers/MySQLDriverException.php similarity index 100% rename from source/Database/Exceptions/Drivers/MySQLDriverException.php rename to source/Spiral/Database/Exceptions/Drivers/MySQLDriverException.php diff --git a/source/Database/Exceptions/InterpolatorException.php b/source/Spiral/Database/Exceptions/InterpolatorException.php similarity index 100% rename from source/Database/Exceptions/InterpolatorException.php rename to source/Spiral/Database/Exceptions/InterpolatorException.php diff --git a/source/Database/Exceptions/QueryException.php b/source/Spiral/Database/Exceptions/QueryException.php similarity index 100% rename from source/Database/Exceptions/QueryException.php rename to source/Spiral/Database/Exceptions/QueryException.php diff --git a/source/Database/Exceptions/QueryExceptionInterface.php b/source/Spiral/Database/Exceptions/QueryExceptionInterface.php similarity index 100% rename from source/Database/Exceptions/QueryExceptionInterface.php rename to source/Spiral/Database/Exceptions/QueryExceptionInterface.php diff --git a/source/Database/Exceptions/ResultException.php b/source/Spiral/Database/Exceptions/ResultException.php similarity index 100% rename from source/Database/Exceptions/ResultException.php rename to source/Spiral/Database/Exceptions/ResultException.php diff --git a/source/Database/Exceptions/SchemaException.php b/source/Spiral/Database/Exceptions/SchemaException.php similarity index 100% rename from source/Database/Exceptions/SchemaException.php rename to source/Spiral/Database/Exceptions/SchemaException.php diff --git a/source/Database/Exceptions/SchemaHandlerException.php b/source/Spiral/Database/Exceptions/SchemaHandlerException.php similarity index 100% rename from source/Database/Exceptions/SchemaHandlerException.php rename to source/Spiral/Database/Exceptions/SchemaHandlerException.php diff --git a/source/Database/Helpers/QueryInterpolator.php b/source/Spiral/Database/Helpers/QueryInterpolator.php similarity index 100% rename from source/Database/Helpers/QueryInterpolator.php rename to source/Spiral/Database/Helpers/QueryInterpolator.php diff --git a/source/Database/Helpers/SynchronizationPool.php b/source/Spiral/Database/Helpers/SynchronizationPool.php similarity index 100% rename from source/Database/Helpers/SynchronizationPool.php rename to source/Spiral/Database/Helpers/SynchronizationPool.php diff --git a/source/Database/Injections/Expression.php b/source/Spiral/Database/Injections/Expression.php similarity index 100% rename from source/Database/Injections/Expression.php rename to source/Spiral/Database/Injections/Expression.php diff --git a/source/Database/Injections/ExpressionInterface.php b/source/Spiral/Database/Injections/ExpressionInterface.php similarity index 100% rename from source/Database/Injections/ExpressionInterface.php rename to source/Spiral/Database/Injections/ExpressionInterface.php diff --git a/source/Spiral/Database/Injections/Fragment.php b/source/Spiral/Database/Injections/Fragment.php new file mode 100644 index 00000000..b3465d1c --- /dev/null +++ b/source/Spiral/Database/Injections/Fragment.php @@ -0,0 +1,65 @@ +where('time_created', '>', new SQLFragment("NOW()")); + */ +class Fragment implements FragmentInterface +{ + /** + * @var string + */ + protected $statement = null; + + /** + * @param string $statement + */ + public function __construct(string $statement) + { + $this->statement = $statement; + } + + /** + * {@inheritdoc} + */ + public function sqlStatement(): string + { + return $this->statement; + } + + /** + * {@inheritdoc} + */ + public function __toString(): string + { + return $this->sqlStatement(); + } + + /** + * @return array + */ + public function __debugInfo() + { + return ['statement' => $this->sqlStatement()]; + } + + /** + * @param array $an_array + * + * @return Fragment + */ + public static function __set_state(array $an_array): Fragment + { + return new static($an_array['statement']); + } +} diff --git a/source/Database/Injections/FragmentInterface.php b/source/Spiral/Database/Injections/FragmentInterface.php similarity index 100% rename from source/Database/Injections/FragmentInterface.php rename to source/Spiral/Database/Injections/FragmentInterface.php diff --git a/source/Database/Injections/Parameter.php b/source/Spiral/Database/Injections/Parameter.php similarity index 100% rename from source/Database/Injections/Parameter.php rename to source/Spiral/Database/Injections/Parameter.php diff --git a/source/Database/Injections/ParameterInterface.php b/source/Spiral/Database/Injections/ParameterInterface.php similarity index 100% rename from source/Database/Injections/ParameterInterface.php rename to source/Spiral/Database/Injections/ParameterInterface.php diff --git a/source/Database/Schemas/ColumnInterface.php b/source/Spiral/Database/Schemas/ColumnInterface.php similarity index 100% rename from source/Database/Schemas/ColumnInterface.php rename to source/Spiral/Database/Schemas/ColumnInterface.php diff --git a/source/Database/Schemas/IndexInterface.php b/source/Spiral/Database/Schemas/IndexInterface.php similarity index 100% rename from source/Database/Schemas/IndexInterface.php rename to source/Spiral/Database/Schemas/IndexInterface.php diff --git a/source/Database/Schemas/Prototypes/AbstractColumn.php b/source/Spiral/Database/Schemas/Prototypes/AbstractColumn.php similarity index 100% rename from source/Database/Schemas/Prototypes/AbstractColumn.php rename to source/Spiral/Database/Schemas/Prototypes/AbstractColumn.php diff --git a/source/Database/Schemas/Prototypes/AbstractElement.php b/source/Spiral/Database/Schemas/Prototypes/AbstractElement.php similarity index 100% rename from source/Database/Schemas/Prototypes/AbstractElement.php rename to source/Spiral/Database/Schemas/Prototypes/AbstractElement.php diff --git a/source/Database/Schemas/Prototypes/AbstractIndex.php b/source/Spiral/Database/Schemas/Prototypes/AbstractIndex.php similarity index 100% rename from source/Database/Schemas/Prototypes/AbstractIndex.php rename to source/Spiral/Database/Schemas/Prototypes/AbstractIndex.php diff --git a/source/Database/Schemas/Prototypes/AbstractReference.php b/source/Spiral/Database/Schemas/Prototypes/AbstractReference.php similarity index 100% rename from source/Database/Schemas/Prototypes/AbstractReference.php rename to source/Spiral/Database/Schemas/Prototypes/AbstractReference.php diff --git a/source/Database/Schemas/Prototypes/AbstractTable.php b/source/Spiral/Database/Schemas/Prototypes/AbstractTable.php similarity index 100% rename from source/Database/Schemas/Prototypes/AbstractTable.php rename to source/Spiral/Database/Schemas/Prototypes/AbstractTable.php diff --git a/source/Database/Schemas/ReferenceInterface.php b/source/Spiral/Database/Schemas/ReferenceInterface.php similarity index 100% rename from source/Database/Schemas/ReferenceInterface.php rename to source/Spiral/Database/Schemas/ReferenceInterface.php diff --git a/source/Database/Schemas/StateComparator.php b/source/Spiral/Database/Schemas/StateComparator.php similarity index 100% rename from source/Database/Schemas/StateComparator.php rename to source/Spiral/Database/Schemas/StateComparator.php diff --git a/source/Database/Schemas/TableInterface.php b/source/Spiral/Database/Schemas/TableInterface.php similarity index 100% rename from source/Database/Schemas/TableInterface.php rename to source/Spiral/Database/Schemas/TableInterface.php diff --git a/source/Database/Schemas/TableState.php b/source/Spiral/Database/Schemas/TableState.php similarity index 100% rename from source/Database/Schemas/TableState.php rename to source/Spiral/Database/Schemas/TableState.php diff --git a/source/Migrations/Atomizer.php b/source/Spiral/Migrations/Atomizer.php similarity index 100% rename from source/Migrations/Atomizer.php rename to source/Spiral/Migrations/Atomizer.php diff --git a/source/Migrations/Atomizer/AliasLookup.php b/source/Spiral/Migrations/Atomizer/AliasLookup.php similarity index 100% rename from source/Migrations/Atomizer/AliasLookup.php rename to source/Spiral/Migrations/Atomizer/AliasLookup.php diff --git a/source/Migrations/Atomizer/MigrationRenderer.php b/source/Spiral/Migrations/Atomizer/MigrationRenderer.php similarity index 100% rename from source/Migrations/Atomizer/MigrationRenderer.php rename to source/Spiral/Migrations/Atomizer/MigrationRenderer.php diff --git a/source/Migrations/Atomizer/RendererInterface.php b/source/Spiral/Migrations/Atomizer/RendererInterface.php similarity index 100% rename from source/Migrations/Atomizer/RendererInterface.php rename to source/Spiral/Migrations/Atomizer/RendererInterface.php diff --git a/source/Migrations/CapsuleInterface.php b/source/Spiral/Migrations/CapsuleInterface.php similarity index 100% rename from source/Migrations/CapsuleInterface.php rename to source/Spiral/Migrations/CapsuleInterface.php diff --git a/source/Migrations/Configs/MigrationsConfig.php b/source/Spiral/Migrations/Configs/MigrationsConfig.php similarity index 100% rename from source/Migrations/Configs/MigrationsConfig.php rename to source/Spiral/Migrations/Configs/MigrationsConfig.php diff --git a/source/Migrations/Exceptions/AtomizerException.php b/source/Spiral/Migrations/Exceptions/AtomizerException.php similarity index 100% rename from source/Migrations/Exceptions/AtomizerException.php rename to source/Spiral/Migrations/Exceptions/AtomizerException.php diff --git a/source/Migrations/Exceptions/BlueprintException.php b/source/Spiral/Migrations/Exceptions/BlueprintException.php similarity index 100% rename from source/Migrations/Exceptions/BlueprintException.php rename to source/Spiral/Migrations/Exceptions/BlueprintException.php diff --git a/source/Migrations/Exceptions/CapsuleException.php b/source/Spiral/Migrations/Exceptions/CapsuleException.php similarity index 100% rename from source/Migrations/Exceptions/CapsuleException.php rename to source/Spiral/Migrations/Exceptions/CapsuleException.php diff --git a/source/Migrations/Exceptions/ContextException.php b/source/Spiral/Migrations/Exceptions/ContextException.php similarity index 100% rename from source/Migrations/Exceptions/ContextException.php rename to source/Spiral/Migrations/Exceptions/ContextException.php diff --git a/source/Migrations/Exceptions/MigrationException.php b/source/Spiral/Migrations/Exceptions/MigrationException.php similarity index 100% rename from source/Migrations/Exceptions/MigrationException.php rename to source/Spiral/Migrations/Exceptions/MigrationException.php diff --git a/source/Migrations/Exceptions/OperationException.php b/source/Spiral/Migrations/Exceptions/OperationException.php similarity index 100% rename from source/Migrations/Exceptions/OperationException.php rename to source/Spiral/Migrations/Exceptions/OperationException.php diff --git a/source/Migrations/Exceptions/Operations/ColumnException.php b/source/Spiral/Migrations/Exceptions/Operations/ColumnException.php similarity index 100% rename from source/Migrations/Exceptions/Operations/ColumnException.php rename to source/Spiral/Migrations/Exceptions/Operations/ColumnException.php diff --git a/source/Migrations/Exceptions/Operations/IndexException.php b/source/Spiral/Migrations/Exceptions/Operations/IndexException.php similarity index 100% rename from source/Migrations/Exceptions/Operations/IndexException.php rename to source/Spiral/Migrations/Exceptions/Operations/IndexException.php diff --git a/source/Migrations/Exceptions/Operations/TableException.php b/source/Spiral/Migrations/Exceptions/Operations/TableException.php similarity index 100% rename from source/Migrations/Exceptions/Operations/TableException.php rename to source/Spiral/Migrations/Exceptions/Operations/TableException.php diff --git a/source/Migrations/Exceptions/RepositoryException.php b/source/Spiral/Migrations/Exceptions/RepositoryException.php similarity index 100% rename from source/Migrations/Exceptions/RepositoryException.php rename to source/Spiral/Migrations/Exceptions/RepositoryException.php diff --git a/source/Migrations/FileRepository.php b/source/Spiral/Migrations/FileRepository.php similarity index 100% rename from source/Migrations/FileRepository.php rename to source/Spiral/Migrations/FileRepository.php diff --git a/source/Migrations/Migration.php b/source/Spiral/Migrations/Migration.php similarity index 100% rename from source/Migrations/Migration.php rename to source/Spiral/Migrations/Migration.php diff --git a/source/Migrations/Migration/State.php b/source/Spiral/Migrations/Migration/State.php similarity index 100% rename from source/Migrations/Migration/State.php rename to source/Spiral/Migrations/Migration/State.php diff --git a/source/Migrations/MigrationCapsule.php b/source/Spiral/Migrations/MigrationCapsule.php similarity index 100% rename from source/Migrations/MigrationCapsule.php rename to source/Spiral/Migrations/MigrationCapsule.php diff --git a/source/Migrations/MigrationInterface.php b/source/Spiral/Migrations/MigrationInterface.php similarity index 100% rename from source/Migrations/MigrationInterface.php rename to source/Spiral/Migrations/MigrationInterface.php diff --git a/source/Migrations/OperationInterface.php b/source/Spiral/Migrations/OperationInterface.php similarity index 100% rename from source/Migrations/OperationInterface.php rename to source/Spiral/Migrations/OperationInterface.php diff --git a/source/Migrations/Operations/ColumnOperation.php b/source/Spiral/Migrations/Operations/ColumnOperation.php similarity index 100% rename from source/Migrations/Operations/ColumnOperation.php rename to source/Spiral/Migrations/Operations/ColumnOperation.php diff --git a/source/Migrations/Operations/Columns/AddColumn.php b/source/Spiral/Migrations/Operations/Columns/AddColumn.php similarity index 100% rename from source/Migrations/Operations/Columns/AddColumn.php rename to source/Spiral/Migrations/Operations/Columns/AddColumn.php diff --git a/source/Migrations/Operations/Columns/AlterColumn.php b/source/Spiral/Migrations/Operations/Columns/AlterColumn.php similarity index 100% rename from source/Migrations/Operations/Columns/AlterColumn.php rename to source/Spiral/Migrations/Operations/Columns/AlterColumn.php diff --git a/source/Migrations/Operations/Columns/DropColumn.php b/source/Spiral/Migrations/Operations/Columns/DropColumn.php similarity index 100% rename from source/Migrations/Operations/Columns/DropColumn.php rename to source/Spiral/Migrations/Operations/Columns/DropColumn.php diff --git a/source/Migrations/Operations/Columns/RenameColumn.php b/source/Spiral/Migrations/Operations/Columns/RenameColumn.php similarity index 100% rename from source/Migrations/Operations/Columns/RenameColumn.php rename to source/Spiral/Migrations/Operations/Columns/RenameColumn.php diff --git a/source/Migrations/Operations/IndexOperation.php b/source/Spiral/Migrations/Operations/IndexOperation.php similarity index 100% rename from source/Migrations/Operations/IndexOperation.php rename to source/Spiral/Migrations/Operations/IndexOperation.php diff --git a/source/Migrations/Operations/Indexes/AddIndex.php b/source/Spiral/Migrations/Operations/Indexes/AddIndex.php similarity index 100% rename from source/Migrations/Operations/Indexes/AddIndex.php rename to source/Spiral/Migrations/Operations/Indexes/AddIndex.php diff --git a/source/Migrations/Operations/Indexes/AlterIndex.php b/source/Spiral/Migrations/Operations/Indexes/AlterIndex.php similarity index 100% rename from source/Migrations/Operations/Indexes/AlterIndex.php rename to source/Spiral/Migrations/Operations/Indexes/AlterIndex.php diff --git a/source/Migrations/Operations/Indexes/DropIndex.php b/source/Spiral/Migrations/Operations/Indexes/DropIndex.php similarity index 100% rename from source/Migrations/Operations/Indexes/DropIndex.php rename to source/Spiral/Migrations/Operations/Indexes/DropIndex.php diff --git a/source/Migrations/Operations/ReferenceOperation.php b/source/Spiral/Migrations/Operations/ReferenceOperation.php similarity index 100% rename from source/Migrations/Operations/ReferenceOperation.php rename to source/Spiral/Migrations/Operations/ReferenceOperation.php diff --git a/source/Migrations/Operations/References/AddReference.php b/source/Spiral/Migrations/Operations/References/AddReference.php similarity index 100% rename from source/Migrations/Operations/References/AddReference.php rename to source/Spiral/Migrations/Operations/References/AddReference.php diff --git a/source/Migrations/Operations/References/AlterReference.php b/source/Spiral/Migrations/Operations/References/AlterReference.php similarity index 100% rename from source/Migrations/Operations/References/AlterReference.php rename to source/Spiral/Migrations/Operations/References/AlterReference.php diff --git a/source/Migrations/Operations/References/DropReference.php b/source/Spiral/Migrations/Operations/References/DropReference.php similarity index 100% rename from source/Migrations/Operations/References/DropReference.php rename to source/Spiral/Migrations/Operations/References/DropReference.php diff --git a/source/Migrations/Operations/Table/CreateTable.php b/source/Spiral/Migrations/Operations/Table/CreateTable.php similarity index 100% rename from source/Migrations/Operations/Table/CreateTable.php rename to source/Spiral/Migrations/Operations/Table/CreateTable.php diff --git a/source/Migrations/Operations/Table/DropTable.php b/source/Spiral/Migrations/Operations/Table/DropTable.php similarity index 100% rename from source/Migrations/Operations/Table/DropTable.php rename to source/Spiral/Migrations/Operations/Table/DropTable.php diff --git a/source/Migrations/Operations/Table/PrimaryKeys.php b/source/Spiral/Migrations/Operations/Table/PrimaryKeys.php similarity index 100% rename from source/Migrations/Operations/Table/PrimaryKeys.php rename to source/Spiral/Migrations/Operations/Table/PrimaryKeys.php diff --git a/source/Migrations/Operations/Table/RenameTable.php b/source/Spiral/Migrations/Operations/Table/RenameTable.php similarity index 100% rename from source/Migrations/Operations/Table/RenameTable.php rename to source/Spiral/Migrations/Operations/Table/RenameTable.php diff --git a/source/Migrations/Operations/Table/UpdateTable.php b/source/Spiral/Migrations/Operations/Table/UpdateTable.php similarity index 100% rename from source/Migrations/Operations/Table/UpdateTable.php rename to source/Spiral/Migrations/Operations/Table/UpdateTable.php diff --git a/source/Migrations/Operations/TableOperation.php b/source/Spiral/Migrations/Operations/TableOperation.php similarity index 100% rename from source/Migrations/Operations/TableOperation.php rename to source/Spiral/Migrations/Operations/TableOperation.php diff --git a/source/Migrations/Operations/Traits/OptionsTrait.php b/source/Spiral/Migrations/Operations/Traits/OptionsTrait.php similarity index 100% rename from source/Migrations/Operations/Traits/OptionsTrait.php rename to source/Spiral/Migrations/Operations/Traits/OptionsTrait.php diff --git a/source/Migrations/RepositoryInterface.php b/source/Spiral/Migrations/RepositoryInterface.php similarity index 100% rename from source/Migrations/RepositoryInterface.php rename to source/Spiral/Migrations/RepositoryInterface.php diff --git a/source/Migrations/TableBlueprint.php b/source/Spiral/Migrations/TableBlueprint.php similarity index 100% rename from source/Migrations/TableBlueprint.php rename to source/Spiral/Migrations/TableBlueprint.php diff --git a/source/Pagination/CountingInterface.php b/source/Spiral/Pagination/CountingInterface.php similarity index 100% rename from source/Pagination/CountingInterface.php rename to source/Spiral/Pagination/CountingInterface.php diff --git a/source/Pagination/Exceptions/PaginationException.php b/source/Spiral/Pagination/Exceptions/PaginationException.php similarity index 100% rename from source/Pagination/Exceptions/PaginationException.php rename to source/Spiral/Pagination/Exceptions/PaginationException.php diff --git a/source/Pagination/PagedInterface.php b/source/Spiral/Pagination/PagedInterface.php similarity index 100% rename from source/Pagination/PagedInterface.php rename to source/Spiral/Pagination/PagedInterface.php diff --git a/source/Pagination/Paginator.php b/source/Spiral/Pagination/Paginator.php similarity index 100% rename from source/Pagination/Paginator.php rename to source/Spiral/Pagination/Paginator.php diff --git a/source/Pagination/PaginatorAwareInterface.php b/source/Spiral/Pagination/PaginatorAwareInterface.php similarity index 100% rename from source/Pagination/PaginatorAwareInterface.php rename to source/Spiral/Pagination/PaginatorAwareInterface.php diff --git a/source/Pagination/PaginatorInterface.php b/source/Spiral/Pagination/PaginatorInterface.php similarity index 100% rename from source/Pagination/PaginatorInterface.php rename to source/Spiral/Pagination/PaginatorInterface.php diff --git a/source/Pagination/PaginatorsInterface.php b/source/Spiral/Pagination/PaginatorsInterface.php similarity index 100% rename from source/Pagination/PaginatorsInterface.php rename to source/Spiral/Pagination/PaginatorsInterface.php diff --git a/source/Pagination/Traits/LimitsTrait.php b/source/Spiral/Pagination/Traits/LimitsTrait.php similarity index 100% rename from source/Pagination/Traits/LimitsTrait.php rename to source/Spiral/Pagination/Traits/LimitsTrait.php diff --git a/source/Pagination/Traits/PaginatorTrait.php b/source/Spiral/Pagination/Traits/PaginatorTrait.php similarity index 100% rename from source/Pagination/Traits/PaginatorTrait.php rename to source/Spiral/Pagination/Traits/PaginatorTrait.php diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..a8bf0c76 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,18 @@ +