Unverified Commit 97e0c2bb authored by Sergei Morozov's avatar Sergei Morozov

Merge branch '3.0.x'

parents ed4ac2af c00c3d83
......@@ -355,6 +355,10 @@ The Drizzle project is abandoned and is therefore not supported by Doctrine DBAL
# Upgrade to 3.0
## BC BREAK: Removed Doctrine\DBAL\Version
The `Doctrine\DBAL\Version` class is no longer available: please refrain from checking the DBAL version at runtime.
## BC BREAK User-provided `PDO` instance is no longer supported
In order to share the same `PDO` instances between DBAL and other components, initialize the connection in DBAL and access it using `Connection::getWrappedConnection()->getWrappedConnection()`.
......@@ -403,14 +407,19 @@ Please use other database client applications for import, e.g.:
# Upgrade to 2.11
## Deprecated `Doctrine\DBAL\Version` class
The usage of the `Doctrine\DBAL\Version` class is deprecated as internal implementation detail. Please refrain from checking the DBAL version at runtime.
## Deprecated `ExpressionBuilder` methods
The usage of the `andX()` and `orX()` methods of the `ExpressionBuilder` class has been deprecated. Use `and()` and `or()` instead.
## Deprecated `CompositeExpression` methods
The usage of the `add()` and `addMultiple()` methods of the `CompositeExpression` class has been deprecated. Use `with()` instead, which returns a new instance.
- The usage of the `add()` and `addMultiple()` methods of the `CompositeExpression` class has been deprecated. Use `with()` instead, which returns a new instance.
In the future, the `add*()` methods will be removed and the class will be effectively immutable.
- The usage of the `CompositeExpression` constructor has been deprecated. Use the `and()` / `or()` factory methods.
## Deprecated calling `QueryBuilder` methods with an array argument
......
......@@ -35,7 +35,7 @@
"php": "^7.2",
"doctrine/cache": "^1.0",
"doctrine/event-manager": "^1.0",
"ocramius/package-versions": "^1.2"
"ocramius/package-versions": "^1.4"
},
"require-dev": {
"doctrine/coding-standard": "^7.0",
......@@ -50,6 +50,9 @@
},
"bin": ["bin/doctrine-dbal"],
"config": {
"platform": {
"php": "7.2.0"
},
"sort-packages": true
},
"autoload": {
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a86df18ed2c69e764faef4b786e0326d",
"content-hash": "1d91a8d87cf22c7dbee3c58f8777ecf5",
"packages": [
{
"name": "doctrine/cache",
......@@ -156,16 +156,16 @@
},
{
"name": "ocramius/package-versions",
"version": "1.4.0",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/Ocramius/PackageVersions.git",
"reference": "a4d4b60d0e60da2487bd21a2c6ac089f85570dbb"
"reference": "44af6f3a2e2e04f2af46bcb302ad9600cba41c7d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/a4d4b60d0e60da2487bd21a2c6ac089f85570dbb",
"reference": "a4d4b60d0e60da2487bd21a2c6ac089f85570dbb",
"url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/44af6f3a2e2e04f2af46bcb302ad9600cba41c7d",
"reference": "44af6f3a2e2e04f2af46bcb302ad9600cba41c7d",
"shasum": ""
},
"require": {
......@@ -177,7 +177,7 @@
"doctrine/coding-standard": "^5.0.1",
"ext-zip": "*",
"infection/infection": "^0.7.1",
"phpunit/phpunit": "^7.0.0"
"phpunit/phpunit": "^7.5.17"
},
"type": "composer-plugin",
"extra": {
......@@ -202,7 +202,7 @@
}
],
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"time": "2019-02-21T12:16:21+00:00"
"time": "2019-11-15T16:17:10+00:00"
}
],
"packages-dev": [
......@@ -3189,5 +3189,8 @@
"platform": {
"php": "^7.2"
},
"platform-dev": []
"platform-dev": [],
"platform-overrides": {
"php": "7.2.0"
}
}
......@@ -6,6 +6,7 @@ namespace Doctrine\DBAL\Query\Expression;
use Countable;
use function array_filter;
use function array_merge;
use function array_values;
use function count;
use function implode;
......@@ -42,6 +43,8 @@ class CompositeExpression implements Countable
private $parts = [];
/**
* @internal Use the and() / or() factory methods.
*
* @param string $type Instance type of composite expression.
* @param self[]|string[] $parts Composition of expressions to be joined on composite expression.
*/
......@@ -53,6 +56,24 @@ class CompositeExpression implements Countable
}));
}
/**
* @param self|string $part
* @param self|string ...$parts
*/
public static function and($part, ...$parts) : self
{
return new self(self::TYPE_AND, array_merge([$part], $parts));
}
/**
* @param self|string $part
* @param self|string ...$parts
*/
public static function or($part, ...$parts) : self
{
return new self(self::TYPE_OR, array_merge([$part], $parts));
}
/**
* Returns a new CompositeExpression with the given parts added.
*
......
......@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Query\Expression;
use Doctrine\DBAL\Connection;
use function array_merge;
use function implode;
use function sprintf;
......@@ -46,7 +45,7 @@ class ExpressionBuilder
*/
public function and($expression, ...$expressions) : CompositeExpression
{
return new CompositeExpression(CompositeExpression::TYPE_AND, array_merge([$expression], $expressions));
return CompositeExpression::and($expression, ...$expressions);
}
/**
......@@ -57,7 +56,7 @@ class ExpressionBuilder
*/
public function or($expression, ...$expressions) : CompositeExpression
{
return new CompositeExpression(CompositeExpression::TYPE_OR, array_merge([$expression], $expressions));
return CompositeExpression::or($expression, ...$expressions);
}
/**
......
......@@ -14,7 +14,7 @@ class CompositeExpressionTest extends DbalTestCase
{
public function testCount() : void
{
$expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']);
$expr = CompositeExpression::or('u.group_id = 1');
self::assertCount(1, $expr);
......@@ -25,16 +25,16 @@ class CompositeExpressionTest extends DbalTestCase
public function testWith() : void
{
$expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']);
$expr = CompositeExpression::or('u.group_id = 1');
self::assertCount(1, $expr);
// test immutability
$expr->with(new CompositeExpression(CompositeExpression::TYPE_OR, ['u.user_id = 1']));
$expr->with(CompositeExpression::or('u.user_id = 1'));
self::assertCount(1, $expr);
$expr = $expr->with(new CompositeExpression(CompositeExpression::TYPE_OR, ['u.user_id = 1']));
$expr = $expr->with(CompositeExpression::or('u.user_id = 1'));
self::assertCount(2, $expr);
......@@ -85,9 +85,9 @@ class CompositeExpressionTest extends DbalTestCase
CompositeExpression::TYPE_AND,
[
'u.user = 1',
new CompositeExpression(
CompositeExpression::TYPE_OR,
['u.group_id = 1', 'u.group_id = 2']
CompositeExpression::or(
'u.group_id = 1',
'u.group_id = 2'
),
],
'(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))',
......@@ -96,9 +96,9 @@ class CompositeExpressionTest extends DbalTestCase
CompositeExpression::TYPE_OR,
[
'u.group_id = 1',
new CompositeExpression(
CompositeExpression::TYPE_AND,
['u.user = 1', 'u.group_id = 2']
CompositeExpression::and(
'u.user = 1',
'u.group_id = 2'
),
],
'(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))',
......
......@@ -65,9 +65,9 @@ class ExpressionBuilderTest extends DbalTestCase
[
[
'u.user = 1',
new CompositeExpression(
CompositeExpression::TYPE_OR,
['u.group_id = 1', 'u.group_id = 2']
CompositeExpression::or(
'u.group_id = 1',
'u.group_id = 2'
),
],
'(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))',
......@@ -75,9 +75,9 @@ class ExpressionBuilderTest extends DbalTestCase
[
[
'u.group_id = 1',
new CompositeExpression(
CompositeExpression::TYPE_AND,
['u.user = 1', 'u.group_id = 2']
CompositeExpression::and(
'u.user = 1',
'u.group_id = 2'
),
],
'(u.group_id = 1) AND ((u.user = 1) AND (u.group_id = 2))',
......@@ -122,9 +122,9 @@ class ExpressionBuilderTest extends DbalTestCase
[
[
'u.user = 1',
new CompositeExpression(
CompositeExpression::TYPE_OR,
['u.group_id = 1', 'u.group_id = 2']
CompositeExpression::or(
'u.group_id = 1',
'u.group_id = 2'
),
],
'(u.user = 1) OR ((u.group_id = 1) OR (u.group_id = 2))',
......@@ -132,9 +132,9 @@ class ExpressionBuilderTest extends DbalTestCase
[
[
'u.group_id = 1',
new CompositeExpression(
CompositeExpression::TYPE_AND,
['u.user = 1', 'u.group_id = 2']
CompositeExpression::and(
'u.user = 1',
'u.group_id = 2'
),
],
'(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment