Skip to content

Commit d40a09a

Browse files
committed
Merge branch 'master' into dsn-transport
pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php
2 parents e19c43c + b500761 commit d40a09a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+615
-181
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Change Log
22

3+
## [0.4.0](https://github.com/php-enqueue/enqueue-dev/tree/0.4.0) (2017-05-12)
4+
[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.3.8...0.4.0)
5+
6+
- \[fs\] add DSN support [\#82](https://github.com/php-enqueue/enqueue-dev/pull/82) ([makasim](https://github.com/makasim))
7+
- \[amqp\] Configure by string DSN. [\#80](https://github.com/php-enqueue/enqueue-dev/pull/80) ([makasim](https://github.com/makasim))
8+
9+
- \[Extensions\] extensions priority [\#79](https://github.com/php-enqueue/enqueue-dev/issues/79)
10+
11+
- \[fs\] Filesystem transport must create a storage dir if it does not exists. [\#78](https://github.com/php-enqueue/enqueue-dev/pull/78) ([makasim](https://github.com/makasim))
12+
- \[magento\] Add basic docs for enqueue magento extension. [\#76](https://github.com/php-enqueue/enqueue-dev/pull/76) ([makasim](https://github.com/makasim))
13+
314
## [0.3.8](https://github.com/php-enqueue/enqueue-dev/tree/0.3.8) (2017-05-10)
415
[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.3.7...0.3.8)
516

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ Features:
1818
- [Filesystem](docs/transport/filesystem.md)
1919
- [Null](docs/transport/null.md).
2020
* Generic purpose abstraction level (the transport level).
21-
* "Opinionated" easy to use abstraction level (the client level).
21+
* Easy to use abstraction level (the client level).
22+
* [Symfony bundle](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/bundle/quick_tour.md)
23+
* [Magento1 extension](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/magento/quick_tour.md)
2224
* [Message bus](http://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageBus.html) support.
2325
* [RPC over MQ](https://www.rabbitmq.com/tutorials/tutorial-one-php.html) support.
2426
* Temporary queues support.
25-
* Well designed components (decoupled, reusable,).
26-
* Tested with unit and functional tests.
27+
* Well designed components decoupled and reusable.
28+
* Carefully tested including unit and functional tests.
2729
* For more visit [quick tour](docs/quick_tour.md).
2830

2931
## Resources
@@ -42,4 +44,4 @@ If you have any questions and inquires about our open source development, this p
4244

4345
## License
4446

45-
It is released under the [MIT License](LICENSE).
47+
It is released under the [MIT License](LICENSE).

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"friendsofphp/php-cs-fixer": "^2",
2828
"empi89/php-amqp-stubs": "*@dev"
2929
},
30+
"autoload": {
31+
"files": ["pkg/enqueue/functions_include.php"]
32+
},
3033
"config": {
3134
"bin-dir": "bin"
3235
},

docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ services:
1111
- './:/mqdev'
1212
environment:
1313
- AMQP_DSN=amqp://rabbitmq
14-
- RABBITMQ_DSN=rabbitmq_amqp://rabbitmq
1514
- SYMFONY__RABBITMQ__HOST=rabbitmq
1615
- SYMFONY__RABBITMQ__USER=guest
1716
- SYMFONY__RABBITMQ__PASSWORD=guest

docs/bundle/config_reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ enqueue:
9595
fs:
9696

9797
# The store directory where all queue\topics files will be created and messages are stored
98-
store_dir: ~ # Required
98+
path: ~ # Required
9999

100100
# The option tells how many messages should be read from file at once. The feature save resources but could lead to bigger messages lose.
101101
pre_fetch_count: 1

docs/bundle/quick_tour.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# EnqueueBundle. Quick tour.
22

3-
The bundle integrates enqueue library.
3+
The [EnqueueBundle](https://github.com/php-enqueue/enqueue-bundle) integrates enqueue library.
44
It adds easy to use [configuration layer](config_reference.md), register services, adds handy [cli commands](cli_commands.md).
55

66
## Install

docs/transport/filesystem.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,25 @@ $ composer require enqueue/fs
2424
<?php
2525
use Enqueue\Fs\FsConnectionFactory;
2626

27+
// stores messages in /tmp/enqueue folder
28+
$connectionFactory = new FsConnectionFactory();
29+
30+
// same as above
31+
$connectionFactory = new FsConnectionFactory('file://');
32+
33+
// stores in custom folder
34+
$connectionFactory = new FsConnectionFactory('/path/to/queue/dir');
35+
36+
// same as above
37+
$connectionFactory = new FsConnectionFactory('file://path/to/queue/dir');
38+
39+
// with options
40+
$connectionFactory = new FsConnectionFactory('file://path/to/queue/dir?pre_fetch_count=1');
41+
42+
// as an array
2743
$connectionFactory = new FsConnectionFactory([
28-
'store_dir' => '/tmp'
44+
'path' => '/path/to/queue/dir',
45+
'pre_fetch_count' => 1,
2946
]);
3047

3148
$psrContext = $connectionFactory->createContext();

pkg/amqp-ext/AmqpConnectionFactory.php

+16-22
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ class AmqpConnectionFactory implements PsrConnectionFactory
1717
private $connection;
1818

1919
/**
20-
* The config could be an array, string DSN or null. In case of null it will attempt to connect to localhost with default credentials
20+
* The config could be an array, string DSN or null. In case of null it will attempt to connect to localhost with default credentials.
2121
*
2222
* [
23-
* 'host' => amqp.host The host to connect too. Note: Max 1024 characters.
24-
* 'port' => amqp.port Port on the host.
25-
* 'vhost' => amqp.vhost The virtual host on the host. Note: Max 128 characters.
26-
* 'user' => amqp.user The user name to use. Note: Max 128 characters.
27-
* 'pass' => amqp.password Password. Note: Max 128 characters.
28-
* 'read_timeout' => Timeout in for income activity. Note: 0 or greater seconds. May be fractional.
29-
* 'write_timeout' => Timeout in for outcome activity. Note: 0 or greater seconds. May be fractional.
30-
* 'connect_timeout' => Connection timeout. Note: 0 or greater seconds. May be fractional.
31-
* 'persisted' => bool, Whether it use single persisted connection or open a new one for every context
32-
* 'lazy' => the connection will be performed as later as possible, if the option set to true
23+
* 'host' => 'amqp.host The host to connect too. Note: Max 1024 characters.',
24+
* 'port' => 'amqp.port Port on the host.',
25+
* 'vhost' => 'amqp.vhost The virtual host on the host. Note: Max 128 characters.',
26+
* 'user' => 'amqp.user The user name to use. Note: Max 128 characters.',
27+
* 'pass' => 'amqp.password Password. Note: Max 128 characters.',
28+
* 'read_timeout' => 'Timeout in for income activity. Note: 0 or greater seconds. May be fractional.',
29+
* 'write_timeout' => 'Timeout in for outcome activity. Note: 0 or greater seconds. May be fractional.',
30+
* 'connect_timeout' => 'Connection timeout. Note: 0 or greater seconds. May be fractional.',
31+
* 'persisted' => 'bool, Whether it use single persisted connection or open a new one for every context',
32+
* 'lazy' => 'the connection will be performed as later as possible, if the option set to true',
3333
* ]
3434
*
3535
* or
@@ -40,13 +40,13 @@ class AmqpConnectionFactory implements PsrConnectionFactory
4040
*/
4141
public function __construct($config = 'amqp://')
4242
{
43-
if (empty($config)) {
43+
if (empty($config) || 'amqp://' === $config) {
4444
$config = [];
45-
} else if (is_string($config)) {
45+
} elseif (is_string($config)) {
4646
$config = $this->parseDsn($config);
47-
} else if (is_array($config)) {
47+
} elseif (is_array($config)) {
4848
} else {
49-
throw new \LogicException('The config must be eaither an array of options, a DSN string or null');
49+
throw new \LogicException('The config must be either an array of options, a DSN string or null');
5050
}
5151

5252
$this->config = array_replace($this->defaultConfig(), $config);
@@ -82,7 +82,6 @@ private function establishConnection()
8282

8383
$this->config['persisted'] ? $this->connection->pconnect() : $this->connection->connect();
8484
}
85-
8685
if (false == $this->connection->isConnected()) {
8786
$this->config['persisted'] ? $this->connection->preconnect() : $this->connection->reconnect();
8887
}
@@ -97,10 +96,6 @@ private function establishConnection()
9796
*/
9897
private function parseDsn($dsn)
9998
{
100-
if ('amqp://' == $dsn) {
101-
return [];
102-
}
103-
10499
$dsnConfig = parse_url($dsn);
105100
if (false === $dsnConfig) {
106101
throw new \LogicException(sprintf('Failed to parse DSN "%s"', $dsn));
@@ -130,9 +125,8 @@ private function parseDsn($dsn)
130125

131126
unset($dsnConfig['scheme'], $dsnConfig['query'], $dsnConfig['fragment'], $dsnConfig['path']);
132127

133-
134128
$config = array_replace($this->defaultConfig(), $dsnConfig);
135-
$config = array_map(function($value) {
129+
$config = array_map(function ($value) {
136130
return urldecode($value);
137131
}, $config);
138132

pkg/amqp-ext/Symfony/AmqpTransportFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public function addConfiguration(ArrayNodeDefinition $builder)
3434
$builder
3535
->beforeNormalization()
3636
->ifString()
37-
->then(function ($v) {
38-
return ['dsn' => $v];
39-
})
37+
->then(function ($v) {
38+
return ['dsn' => $v];
39+
})
4040
->end()
4141
->children()
4242
->scalarNode('dsn')

pkg/amqp-ext/Tests/AmqpConnectionFactoryConfigTest.php

+16-14
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace Enqueue\AmqpExt\Tests;
44

55
use Enqueue\AmqpExt\AmqpConnectionFactory;
6-
use Enqueue\AmqpExt\Symfony\AmqpTransportFactory;
76
use Enqueue\Test\ClassExtensionTrait;
87
use PHPUnit\Framework\TestCase;
98

109
/**
11-
* The class contains the factory tests dedicated to configuration
10+
* The class contains the factory tests dedicated to configuration.
1211
*/
1312
class AmqpConnectionFactoryConfigTest extends TestCase
1413
{
@@ -17,7 +16,7 @@ class AmqpConnectionFactoryConfigTest extends TestCase
1716
public function testThrowNeitherArrayStringNorNullGivenAsConfig()
1817
{
1918
$this->expectException(\LogicException::class);
20-
$this->expectExceptionMessage('The config must be eaither an array of options, a DSN string or null');
19+
$this->expectExceptionMessage('The config must be either an array of options, a DSN string or null');
2120

2221
new AmqpConnectionFactory(new \stdClass());
2322
}
@@ -40,6 +39,9 @@ public function testThrowIfDsnCouldNotBeParsed()
4039

4140
/**
4241
* @dataProvider provideConfigs
42+
*
43+
* @param mixed $config
44+
* @param mixed $expectedConfig
4345
*/
4446
public function testShouldParseConfigurationAsExpected($config, $expectedConfig)
4547
{
@@ -63,13 +65,13 @@ public static function provideConfigs()
6365
'connect_timeout' => null,
6466
'persisted' => false,
6567
'lazy' => true,
66-
]
68+
],
6769
];
6870

6971
// some examples from Appendix A: Examples (https://www.rabbitmq.com/uri-spec.html)
7072

7173
yield [
72-
"amqp://user:pass@host:10000/vhost",
74+
'amqp://user:pass@host:10000/vhost',
7375
[
7476
'host' => 'host',
7577
'port' => 10000,
@@ -81,11 +83,11 @@ public static function provideConfigs()
8183
'connect_timeout' => null,
8284
'persisted' => false,
8385
'lazy' => true,
84-
]
86+
],
8587
];
8688

8789
yield [
88-
"amqp://user%61:%61pass@ho%61st:10000/v%2fhost",
90+
'amqp://user%61:%61pass@ho%61st:10000/v%2fhost',
8991
[
9092
'host' => 'hoast',
9193
'port' => 10000,
@@ -97,11 +99,11 @@ public static function provideConfigs()
9799
'connect_timeout' => null,
98100
'persisted' => false,
99101
'lazy' => true,
100-
]
102+
],
101103
];
102104

103105
yield [
104-
"amqp://",
106+
'amqp://',
105107
[
106108
'host' => 'localhost',
107109
'port' => 5672,
@@ -113,11 +115,11 @@ public static function provideConfigs()
113115
'connect_timeout' => null,
114116
'persisted' => false,
115117
'lazy' => true,
116-
]
118+
],
117119
];
118120

119121
yield [
120-
"amqp://user:pass@host:10000/vhost?connect_timeout=2&lazy=",
122+
'amqp://user:pass@host:10000/vhost?connect_timeout=2&lazy=',
121123
[
122124
'host' => 'host',
123125
'port' => 10000,
@@ -129,7 +131,7 @@ public static function provideConfigs()
129131
'connect_timeout' => '2',
130132
'persisted' => false,
131133
'lazy' => '',
132-
]
134+
],
133135
];
134136

135137
yield [
@@ -145,7 +147,7 @@ public static function provideConfigs()
145147
'connect_timeout' => null,
146148
'persisted' => false,
147149
'lazy' => true,
148-
]
150+
],
149151
];
150152

151153
yield [
@@ -161,7 +163,7 @@ public static function provideConfigs()
161163
'connect_timeout' => null,
162164
'persisted' => false,
163165
'lazy' => false,
164-
]
166+
],
165167
];
166168
}
167169
}

pkg/amqp-ext/composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
"require": {
1414
"php": ">=5.6",
1515
"ext-amqp": "^1.6",
16-
"enqueue/psr-queue": "^0.3|0.4@dev",
16+
"enqueue/psr-queue": "^0.4",
1717
"psr/log": "^1"
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "~5.4.0",
21-
"enqueue/test": "^0.3|0.4@dev",
22-
"enqueue/enqueue": "^0.3|0.4@dev",
23-
"enqueue/null": "^0.3|0.4@dev",
21+
"enqueue/test": "^0.4",
22+
"enqueue/enqueue": "^0.4",
23+
"enqueue/null": "^0.4",
2424
"empi89/php-amqp-stubs": "*@dev",
2525
"symfony/dependency-injection": "^2.8|^3",
2626
"symfony/config": "^2.8|^3"

pkg/dbal/composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
],
1313
"require": {
1414
"php": ">=5.6",
15-
"enqueue/psr-queue": "^0.3|0.4@dev",
15+
"enqueue/psr-queue": "^0.4",
1616
"doctrine/dbal": "~2.5",
1717
"psr/log": "^1"
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "~5.4.0",
21-
"enqueue/test": "^0.3|0.4@dev",
22-
"enqueue/enqueue": "^0.3|0.4@dev",
23-
"enqueue/null": "^0.3|0.4@dev",
21+
"enqueue/test": "^0.4",
22+
"enqueue/enqueue": "^0.4",
23+
"enqueue/null": "^0.4",
2424
"symfony/dependency-injection": "^2.8|^3",
2525
"symfony/config": "^2.8|^3"
2626
},

0 commit comments

Comments
 (0)