Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 104 additions & 97 deletions resources/.phpstorm.meta.php

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Spiral\Core\Container\InjectableInterface;
use Cycle\Database\Driver\DriverInterface;
use Spiral\Database\Driver\DriverInterface as SpiralDriverInterface;
use Cycle\Database\Query\DeleteQuery;
use Cycle\Database\Query\InsertQuery;
use Cycle\Database\Query\SelectQuery;
Expand Down Expand Up @@ -46,11 +47,13 @@ final class Database implements DatabaseInterface, InjectableInterface
private $readDriver;

/**
* @param string $name Internal database name/id.
* @param string $prefix Default database table prefix, will be used for all
* table identifiers.
* @param DriverInterface $driver Driver instance responsible for database connection.
* @param DriverInterface|null $readDriver Read-only driver connection.
* @param string $name Internal database name/id.
* @param string $prefix Default database table prefix, will be used for all
* table identifiers.
* @param SpiralDriverInterface|DriverInterface $driver Driver instance responsible for database connection.
* The signature of this argument will be changed to {@see DriverInterface} in future release.
* @param SpiralDriverInterface|DriverInterface|null $readDriver Read-only driver connection.
* The signature of this argument will be changed to {@see DriverInterface} in future release.
*/
public function __construct(
string $name,
Expand Down
8 changes: 5 additions & 3 deletions src/DatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Spiral\Core\Container;
use Spiral\Core\FactoryInterface;
use Cycle\Database\Config\DatabaseConfig;
use Spiral\Database\Config\DatabaseConfig as SpiralDatabaseConfig;
use Cycle\Database\Config\DatabasePartial;
use Cycle\Database\Driver\Driver;
use Cycle\Database\Driver\DriverInterface;
Expand Down Expand Up @@ -121,10 +122,11 @@ public function setLogger(LoggerInterface $logger): void
}

/**
* @param DatabaseConfig $config
* @param FactoryInterface $factory
* @param SpiralDatabaseConfig|DatabaseConfig $config The signature of this
* argument will be changed to {@see DatabaseConfig} in future release.
* @param FactoryInterface|null $factory
*/
public function __construct(DatabaseConfig $config, FactoryInterface $factory = null)
public function __construct(SpiralDatabaseConfig $config, FactoryInterface $factory = null)
{
$this->config = $config;
$this->factory = $factory ?? new Container();
Expand Down
6 changes: 4 additions & 2 deletions src/Driver/CompilerCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Cycle\Database\Query\QueryInterface;
use Cycle\Database\Query\QueryParameters;
use Cycle\Database\Query\SelectQuery;
use Spiral\Database\Driver\CachingCompilerInterface as SpiralCachingCompilerInterface;

/**
* Caches calculated queries. Code in this class is performance optimized.
Expand All @@ -32,9 +33,10 @@ final class CompilerCache implements CompilerInterface
private $compiler;

/**
* @param CachingCompilerInterface $compiler
* @param SpiralCachingCompilerInterface|CachingCompilerInterface $compiler The signature
* of this argument will be changed to {@see DriverInterface} in future release.
*/
public function __construct(CachingCompilerInterface $compiler)
public function __construct(SpiralCachingCompilerInterface $compiler)
{
$this->compiler = $compiler;
}
Expand Down
18 changes: 12 additions & 6 deletions src/Driver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
use Cycle\Database\Query\Interpolator;
use Cycle\Database\StatementInterface;
use Throwable;
use Spiral\Database\Query\BuilderInterface as SpiralBuilderInterface;
use Spiral\Database\Driver\HandlerInterface as SpiralHandlerInterface;
use Spiral\Database\Driver\CompilerInterface as SpiralCompilerInterface;

/**
* Provides low level abstraction at top of
Expand Down Expand Up @@ -97,15 +100,18 @@ abstract class Driver implements DriverInterface, LoggerAwareInterface

/**
* @param array $options
* @param HandlerInterface $schemaHandler
* @param CompilerInterface $queryCompiler
* @param BuilderInterface $queryBuilder
* @param SpiralHandlerInterface|HandlerInterface $schemaHandler The signature of
* this argument will be changed to {@see HandlerInterface} in future release.
* @param SpiralCompilerInterface|CompilerInterface $queryCompiler The signature of
* this argument will be changed to {@see CompilerInterface} in future release.
* @param SpiralBuilderInterface|BuilderInterface $queryBuilder The signature of
* this argument will be changed to {@see BuilderInterface} in future release.
*/
public function __construct(
array $options,
HandlerInterface $schemaHandler,
CompilerInterface $queryCompiler,
BuilderInterface $queryBuilder
SpiralHandlerInterface $schemaHandler,
SpiralCompilerInterface $queryCompiler,
SpiralBuilderInterface $queryBuilder
) {
$this->schemaHandler = $schemaHandler->withDriver($this);
$this->queryBuilder = $queryBuilder->withDriver($this);
Expand Down
6 changes: 4 additions & 2 deletions src/Driver/ReadonlyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
use Cycle\Database\Schema\AbstractForeignKey;
use Cycle\Database\Schema\AbstractIndex;
use Cycle\Database\Schema\AbstractTable;
use Spiral\Database\Driver\HandlerInterface as SpiralHandlerInterface;

final class ReadonlyHandler implements HandlerInterface
{
/** @var HandlerInterface */
private $parent;

/**
* @param HandlerInterface $parent
* @param SpiralHandlerInterface|HandlerInterface $parent The signature of this
* argument will be changed to {@see HandlerInterface} in future release.
*/
public function __construct(HandlerInterface $parent)
public function __construct(SpiralHandlerInterface $parent)
{
$this->parent = $parent;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Exception/HandlerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@

namespace Cycle\Database\Exception;

use Spiral\Database\Exception\StatementException as SpiralStatementException;

/**
* Schema sync related exception.
*/
class HandlerException extends DriverException implements StatementExceptionInterface
{
/**
* @param StatementException $e
* @param SpiralStatementException|StatementException $e The signature of this
* argument will be changed to {@see StatementException} in future release.
*/
public function __construct(StatementException $e)
public function __construct(SpiralStatementException $e)
{
parent::__construct($e->getMessage(), $e->getCode(), $e);
}
Expand Down
24 changes: 16 additions & 8 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
namespace Cycle\Database\Query;

use Cycle\Database\Driver\DriverInterface;
use Spiral\Database\Query\SelectQuery as SpiralSelectQuery;
use Spiral\Database\Query\InsertQuery as SpiralInsertQuery;
use Spiral\Database\Query\UpdateQuery as SpiralUpdateQuery;
use Spiral\Database\Query\DeleteQuery as SpiralDeleteQuery;

/**
* Initiates active queries.
Expand All @@ -36,16 +40,20 @@ final class QueryBuilder implements BuilderInterface
/**
* QueryBuilder constructor.
*
* @param SelectQuery $selectQuery
* @param InsertQuery $insertQuery
* @param UpdateQuery $updateQuery
* @param DeleteQuery $deleteQuery
* @param SpiralSelectQuery|SelectQuery $selectQuery The signature of this
* argument will be changed to {@see SelectQuery} in future release.
* @param SpiralInsertQuery|InsertQuery $insertQuery The signature of this
* argument will be changed to {@see InsertQuery} in future release.
* @param SpiralUpdateQuery|UpdateQuery $updateQuery The signature of this
* argument will be changed to {@see UpdateQuery} in future release.
* @param SpiralDeleteQuery|DeleteQuery $deleteQuery The signature of this
* argument will be changed to {@see DeleteQuery} in future release.
*/
public function __construct(
SelectQuery $selectQuery,
InsertQuery $insertQuery,
UpdateQuery $updateQuery,
DeleteQuery $deleteQuery
SpiralSelectQuery $selectQuery,
SpiralInsertQuery $insertQuery,
SpiralUpdateQuery $updateQuery,
SpiralDeleteQuery $deleteQuery
) {
$this->selectQuery = $selectQuery;
$this->insertQuery = $insertQuery;
Expand Down
10 changes: 6 additions & 4 deletions src/Schema/AbstractTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Cycle\Database\Exception\HandlerException;
use Cycle\Database\Exception\SchemaException;
use Cycle\Database\TableInterface;
use Spiral\Database\Driver\DriverInterface as SpiralDriverInterface;

/**
* AbstractTable class used to describe and manage state of specified table. It provides ability to
Expand Down Expand Up @@ -98,11 +99,12 @@ abstract class AbstractTable implements TableInterface, ElementInterface
private $prefix;

/**
* @param DriverInterface $driver Parent driver.
* @param string $name Table name, must include table prefix.
* @param string $prefix Database specific table prefix.
* @param SpiralDriverInterface|DriverInterface $driver Parent driver. The signature
* of this argument will be changed to {@see DriverInterface} in future release.
* @param string $name Table name, must include table prefix.
* @param string $prefix Database specific table prefix.
*/
public function __construct(DriverInterface $driver, string $name, string $prefix)
public function __construct(SpiralDriverInterface $driver, string $name, string $prefix)
{
$this->driver = $driver;
$this->prefix = $prefix;
Expand Down
10 changes: 7 additions & 3 deletions src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Cycle\Database\Schema;

use Spiral\Database\Schema\State as SpiralState;

/**
* Compares two table states.
*/
Expand All @@ -23,10 +25,12 @@ final class Comparator implements ComparatorInterface
private $current;

/**
* @param State $initial
* @param State $current
* @param SpiralState|State $initial The signature of this argument
* will be changed to {@see State} in future release.
* @param SpiralState|State $current The signature of this argument
* will be changed to {@see State} in future release.
*/
public function __construct(State $initial, State $current)
public function __construct(SpiralState $initial, SpiralState $current)
{
$this->initial = $initial;
$this->current = $current;
Expand Down
6 changes: 4 additions & 2 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Cycle\Database\Query\SelectQuery;
use Cycle\Database\Query\UpdateQuery;
use Cycle\Database\Schema\AbstractTable;
use Spiral\Database\DatabaseInterface as SpiralDatabaseInterface;

/**
* Represent table level abstraction with simplified access to SelectQuery associated with such
Expand All @@ -36,8 +37,9 @@ final class Table implements TableInterface, \IteratorAggregate, \Countable
private $name;

/**
* @param DatabaseInterface $database Parent DBAL database.
* @param string $name Table name without prefix.
* @param SpiralDatabaseInterface|DatabaseInterface $database Parent DBAL database. The signature
* of this argument will be changed to {@see DatabaseInterface} in future release.
* @param string $name Table name without prefix.
*/
public function __construct(DatabaseInterface $database, string $name)
{
Expand Down
19 changes: 18 additions & 1 deletion src/polyfill.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
// Replaces: SQlServerForeignKey to SQLServerForeignKey
class_alias(
\Cycle\Database\Driver\SQLServer\Schema\SQLServerForeignKey::class,
\Spiral\Database\Driver\SQLServer\Schema\SQlServerForeignKey::class,
\Spiral\Database\Driver\SQLServer\Schema\SQlServerForeignKey::class
);


spl_autoload_register(static function (string $class) {
if (strpos($class, 'Spiral\\Database\\') === 0) {
$original = 'Cycle\\Database\\' . substr($class, 16);
Expand All @@ -29,3 +30,19 @@ class_alias(
class_alias($original, $class);
}
});

// Preload some aliases
interface_exists(\Spiral\Database\Driver\CachingCompilerInterface::class);
interface_exists(\Spiral\Database\Driver\CompilerInterface::class);
interface_exists(\Spiral\Database\Driver\HandlerInterface::class);
interface_exists(\Spiral\Database\Driver\DriverInterface::class);
interface_exists(\Spiral\Database\Query\BuilderInterface::class);
interface_exists(\Spiral\Database\DatabaseInterface::class);

class_exists(\Spiral\Database\Exception\StatementException::class);
class_exists(\Spiral\Database\Config\DatabaseConfig::class);
class_exists(\Spiral\Database\Query\SelectQuery::class);
class_exists(\Spiral\Database\Query\InsertQuery::class);
class_exists(\Spiral\Database\Query\UpdateQuery::class);
class_exists(\Spiral\Database\Query\DeleteQuery::class);
class_exists(\Spiral\Database\Schema\State::class);