Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware is uncountable #6033

Closed
wants to merge 1 commit into from
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
4 changes: 2 additions & 2 deletions docs/en/reference/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ interfaces:
- ``Doctrine\DBAL\Driver\Statement``
- ``Doctrine\DBAL\Driver\Result``

Middlewares
-----------
Middleware
----------

A middleware sits in the middle between the wrapper components and the driver.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If middleware is not countable, is there something like a middleware? The way you use the term in the Configuration class now, middleware is the whole layer between the driver an the wrapper. I think, we need to find a different term for the thing that we create through implementing the Middleware interface.

By implementing the ``Doctrine\DBAL\Driver\Middleware``, it decorates the
Expand Down
52 changes: 44 additions & 8 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class Configuration
{
/** @var Middleware[] */
private array $middlewares = [];
private array $middleware = [];

/**
* The SQL logger in use. If null, SQL logging is disabled.
Expand Down Expand Up @@ -68,14 +68,14 @@ public function __construct()
/**
* Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled.
*
* @deprecated Use {@see setMiddlewares()} and {@see \Doctrine\DBAL\Logging\Middleware} instead.
* @deprecated Use {@see setMiddleware()} and {@see \Doctrine\DBAL\Logging\Middleware} instead.
*/
public function setSQLLogger(?SQLLogger $logger = null): void
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4967',
'%s is deprecated, use setMiddlewares() and Logging\\Middleware instead.',
'%s is deprecated, use setMiddleware() and Logging\\Middleware instead.',
__METHOD__,
);

Expand Down Expand Up @@ -212,21 +212,57 @@ public function getAutoCommit(): bool
}

/**
* @param Middleware[] $middlewares
* @deprecated setMiddlewares is deprecated since doctrine/dbal 3.6. Use setMiddleware instead.
*
* @param Middleware[] $middleware
*
* @return $this
*/
public function setMiddlewares(array $middleware): self
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6033',
'%s is deprecated since doctrine/dbal 3.7. Use setMiddleware instead.',
__METHOD__,
);

return $this->setMiddleware($middleware);
}

/**
* @param Middleware[] $middleware
*
* @return $this
*/
public function setMiddlewares(array $middlewares): self
public function setMiddleware(array $middleware): self
{
$this->middlewares = $middlewares;
$this->middleware = $middleware;

return $this;
}

/** @return Middleware[] */
/**
* @deprecated getMiddlewares is deprecated since doctrine/dbal 3.6. Use getMiddleware instead.
*
* @return Middleware[]
*/
public function getMiddlewares(): array
{
return $this->middlewares;
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6033',
'%s is deprecated since doctrine/dbal 3.7. Use getMiddleware instead.',
__METHOD__,
);

return $this->getMiddleware();
}

/** @return Middleware[] */
public function getMiddleware(): array
{
return $this->middleware;
}

public function getSchemaManagerFactory(): ?SchemaManagerFactory
Expand Down
2 changes: 1 addition & 1 deletion src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static function getConnection(

$driver = self::createDriver($params['driver'] ?? null, $params['driverClass'] ?? null);

foreach ($config->getMiddlewares() as $middleware) {
foreach ($config->getMiddleware() as $middleware) {
$driver = $middleware->wrap($driver);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/PortabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ private function connectWithPortability(int $mode, int $case): void
$this->connection->close();

$configuration = $this->connection->getConfiguration();
$configuration->setMiddlewares(
$configuration->setMiddleware(
array_merge(
$configuration->getMiddlewares(),
$configuration->getMiddleware(),
[new Middleware($mode, $case)],
),
);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ private static function createConfiguration(string $driver): Configuration
switch ($driver) {
case 'pdo_oci':
case 'oci8':
$configuration->setMiddlewares([new InitializeSession()]);
$configuration->setMiddleware([new InitializeSession()]);
break;
case 'pdo_sqlite':
case 'sqlite3':
$configuration->setMiddlewares([new EnableForeignKeys()]);
$configuration->setMiddleware([new EnableForeignKeys()]);
break;
}

Expand Down