Skip to content

Commit 97d378a

Browse files
committed
Merge branch '4.3'
* 4.3: [Messenger] Disable the SchemaAssetsFilter when setup the transport [Messenger] Fix missing auto_setup for RedisTransport [Contracts] split in one package per sub-contracts
2 parents b1a6cea + 8df4e57 commit 97d378a

File tree

21 files changed

+371
-33
lines changed

21 files changed

+371
-33
lines changed

src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ private function getDBALConnectionMock()
108108
$platform = $this->getMockBuilder(AbstractPlatform::class)
109109
->getMock();
110110
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
111+
$configuration = $this->getMockBuilder(\Doctrine\DBAL\Configuration::class)
112+
->getMock();
111113
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
114+
$driverConnection->method('getConfiguration')->willReturn($configuration);
112115

113116
return $driverConnection;
114117
}

src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ public function testFromDsn()
4242
public function testFromDsnWithOptions()
4343
{
4444
$this->assertEquals(
45-
new Connection(['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1'], [
45+
new Connection(['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false], [
4646
'host' => 'localhost',
4747
'port' => 6379,
4848
], [
4949
'serializer' => 2,
5050
]),
51-
Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['serializer' => 2])
51+
Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['serializer' => 2, 'auto_setup' => false])
5252
);
5353
}
5454

@@ -117,10 +117,6 @@ public function testGetAfterReject()
117117
{
118118
$redis = new \Redis();
119119
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', [], $redis);
120-
try {
121-
$connection->setup();
122-
} catch (TransportException $e) {
123-
}
124120

125121
$connection->add('1', []);
126122
$connection->add('2', []);
@@ -139,10 +135,6 @@ public function testGetNonBlocking()
139135
$redis = new \Redis();
140136

141137
$connection = Connection::fromDsn('redis://localhost/messenger-getnonblocking', [], $redis);
142-
try {
143-
$connection->setup();
144-
} catch (TransportException $e) {
145-
}
146138

147139
$this->assertNull($connection->get()); // no message, should return null immediately
148140
$connection->add('1', []);

src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,25 @@ public function reject(string $id): bool
197197

198198
public function setup(): void
199199
{
200+
$configuration = $this->driverConnection->getConfiguration();
201+
// Since Doctrine 2.9 the getFilterSchemaAssetsExpression is deprecated
202+
$hasFilterCallback = method_exists($configuration, 'getSchemaAssetsFilter');
203+
204+
if ($hasFilterCallback) {
205+
$assetFilter = $this->driverConnection->getConfiguration()->getSchemaAssetsFilter();
206+
$this->driverConnection->getConfiguration()->setSchemaAssetsFilter(null);
207+
} else {
208+
$assetFilter = $this->driverConnection->getConfiguration()->getFilterSchemaAssetsExpression();
209+
$this->driverConnection->getConfiguration()->setFilterSchemaAssetsExpression(null);
210+
}
211+
200212
$this->schemaSynchronizer->updateSchema($this->getSchema(), true);
213+
214+
if ($hasFilterCallback) {
215+
$this->driverConnection->getConfiguration()->setSchemaAssetsFilter($assetFilter);
216+
} else {
217+
$this->driverConnection->getConfiguration()->setFilterSchemaAssetsExpression($assetFilter);
218+
}
201219
}
202220

203221
public function getMessageCount(): int

src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,29 @@
2727
*/
2828
class Connection
2929
{
30+
private const DEFAULT_OPTIONS = [
31+
'stream' => 'messages',
32+
'group' => 'symfony',
33+
'consumer' => 'consumer',
34+
'auto_setup' => true,
35+
];
36+
3037
private $connection;
3138
private $stream;
3239
private $group;
3340
private $consumer;
41+
private $autoSetup;
3442
private $couldHavePendingMessages = true;
3543

3644
public function __construct(array $configuration, array $connectionCredentials = [], array $redisOptions = [], \Redis $redis = null)
3745
{
3846
$this->connection = $redis ?: new \Redis();
3947
$this->connection->connect($connectionCredentials['host'] ?? '127.0.0.1', $connectionCredentials['port'] ?? 6379);
4048
$this->connection->setOption(\Redis::OPT_SERIALIZER, $redisOptions['serializer'] ?? \Redis::SERIALIZER_PHP);
41-
$this->stream = $configuration['stream'] ?? '' ?: 'messages';
42-
$this->group = $configuration['group'] ?? '' ?: 'symfony';
43-
$this->consumer = $configuration['consumer'] ?? '' ?: 'consumer';
49+
$this->stream = $configuration['stream'] ?? self::DEFAULT_OPTIONS['stream'];
50+
$this->group = $configuration['group'] ?? self::DEFAULT_OPTIONS['group'];
51+
$this->consumer = $configuration['consumer'] ?? self::DEFAULT_OPTIONS['consumer'];
52+
$this->autoSetup = $configuration['auto_setup'] ?? self::DEFAULT_OPTIONS['auto_setup'];
4453
}
4554

4655
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
@@ -51,9 +60,9 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
5160

5261
$pathParts = explode('/', $parsedUrl['path'] ?? '');
5362

54-
$stream = $pathParts[1] ?? '';
55-
$group = $pathParts[2] ?? '';
56-
$consumer = $pathParts[3] ?? '';
63+
$stream = $pathParts[1] ?? null;
64+
$group = $pathParts[2] ?? null;
65+
$consumer = $pathParts[3] ?? null;
5766

5867
$connectionCredentials = [
5968
'host' => $parsedUrl['host'] ?? '127.0.0.1',
@@ -64,11 +73,21 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
6473
parse_str($parsedUrl['query'], $redisOptions);
6574
}
6675

67-
return new self(['stream' => $stream, 'group' => $group, 'consumer' => $consumer], $connectionCredentials, $redisOptions, $redis);
76+
$autoSetup = null;
77+
if (\array_key_exists('auto_setup', $redisOptions)) {
78+
$autoSetup = filter_var($redisOptions['auto_setup'], FILTER_VALIDATE_BOOLEAN);
79+
unset($redisOptions['auto_setup']);
80+
}
81+
82+
return new self(['stream' => $stream, 'group' => $group, 'consumer' => $consumer, 'auto_setup' => $autoSetup], $connectionCredentials, $redisOptions, $redis);
6883
}
6984

7085
public function get(): ?array
7186
{
87+
if ($this->autoSetup) {
88+
$this->setup();
89+
}
90+
7291
$messageId = '>'; // will receive new messages
7392

7493
if ($this->couldHavePendingMessages) {
@@ -141,6 +160,10 @@ public function reject(string $id): void
141160

142161
public function add(string $body, array $headers): void
143162
{
163+
if ($this->autoSetup) {
164+
$this->setup();
165+
}
166+
144167
$e = null;
145168
try {
146169
$added = $this->connection->xadd($this->stream, '*', ['message' => json_encode(
@@ -161,5 +184,7 @@ public function setup(): void
161184
} catch (\RedisException $e) {
162185
throw new TransportException($e->getMessage(), 0, $e);
163186
}
187+
188+
$this->autoSetup = false;
164189
}
165190
}

src/Symfony/Contracts/Cache/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018-2019 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

src/Symfony/Contracts/Cache/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Symfony Cache Contracts
2+
=======================
3+
4+
A set of abstractions extracted out of the Symfony components.
5+
6+
Can be used to build on semantics that the Symfony components proved useful - and
7+
that already have battle tested implementations.
8+
9+
See https://github.com/symfony/contracts/blob/master/README.md for more information.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "symfony/cache-contracts",
3+
"type": "library",
4+
"description": "Generic abstractions related to caching",
5+
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
6+
"homepage": "https://symfony.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Nicolas Grekas",
11+
"email": "[email protected]"
12+
},
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": "^7.1.3"
20+
},
21+
"suggest": {
22+
"psr/cache": "",
23+
"symfony/cache-implementation": ""
24+
},
25+
"autoload": {
26+
"psr-4": { "Symfony\\Contracts\\Cache\\": "" }
27+
},
28+
"minimum-stability": "dev",
29+
"extra": {
30+
"branch-alias": {
31+
"dev-master": "1.1-dev"
32+
}
33+
}
34+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018-2019 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Symfony EventDispatcher Contracts
2+
=================================
3+
4+
A set of abstractions extracted out of the Symfony components.
5+
6+
Can be used to build on semantics that the Symfony components proved useful - and
7+
that already have battle tested implementations.
8+
9+
See https://github.com/symfony/contracts/blob/master/README.md for more information.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "symfony/event-dispatcher-contracts",
3+
"type": "library",
4+
"description": "Generic abstractions related to dispatching event",
5+
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
6+
"homepage": "https://symfony.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Nicolas Grekas",
11+
"email": "[email protected]"
12+
},
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": "^7.1.3"
20+
},
21+
"suggest": {
22+
"psr/event-dispatcher": "",
23+
"symfony/event-dispatcher-implementation": ""
24+
},
25+
"autoload": {
26+
"psr-4": { "Symfony\\Contracts\\EventDispatcher\\": "" }
27+
},
28+
"minimum-stability": "dev",
29+
"extra": {
30+
"branch-alias": {
31+
"dev-master": "1.1-dev"
32+
}
33+
}
34+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018-2019 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Symfony HttpClient Contracts
2+
============================
3+
4+
A set of abstractions extracted out of the Symfony components.
5+
6+
Can be used to build on semantics that the Symfony components proved useful - and
7+
that already have battle tested implementations.
8+
9+
See https://github.com/symfony/contracts/blob/master/README.md for more information.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "symfony/http-client-contracts",
3+
"type": "library",
4+
"description": "Generic abstractions related to HTTP clients",
5+
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
6+
"homepage": "https://symfony.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Nicolas Grekas",
11+
"email": "[email protected]"
12+
},
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": "^7.1.3"
20+
},
21+
"suggest": {
22+
"symfony/http-client-implementation": ""
23+
},
24+
"autoload": {
25+
"psr-4": { "Symfony\\Contracts\\HttpClient\\": "" }
26+
},
27+
"minimum-stability": "dev",
28+
"extra": {
29+
"branch-alias": {
30+
"dev-master": "1.1-dev"
31+
}
32+
}
33+
}

src/Symfony/Contracts/README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,6 @@ providing abstractions that are useful on their own while still compatible with
4444
implementations provided by Symfony. Although not the main target, we hope that
4545
the declared contracts will directly or indirectly contribute to the PHP-FIG.
4646

47-
### Why isn't this package split into several packages?
48-
49-
Putting all interfaces in one package eases discoverability and dependency
50-
management. Instead of dealing with a myriad of small packages and the
51-
corresponding matrix of versions, you just need to deal with one package and one
52-
version. Also when using IDE autocompletion or just reading the source code, it
53-
makes it easier to figure out which contracts are provided.
54-
55-
There are two downsides to this approach: you may have unused files in your
56-
`vendor/` directory, and in the future, it will be impossible to use two
57-
different sub-namespaces in different major versions of the package. For the
58-
"unused files" downside, it has no practical consequences: their file sizes are
59-
very small, and there is no performance overhead at all since they are never
60-
loaded. For major versions, this package follows the Symfony BC + deprecation
61-
policies, with an additional restriction to never remove deprecated interfaces.
62-
6347
Resources
6448
---------
6549

src/Symfony/Contracts/Service/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018-2019 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

0 commit comments

Comments
 (0)