File tree Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ public function getTimestamp()
175
175
{
176
176
$ value = $ this ->getHeader ('timestamp ' );
177
177
178
- return $ value === null ? null : (int ) $ value ;
178
+ return null === $ value ? null : (int ) $ value ;
179
179
}
180
180
181
181
/**
Original file line number Diff line number Diff line change @@ -33,16 +33,23 @@ public function __construct($name = 'redis')
33
33
public function addConfiguration (ArrayNodeDefinition $ builder )
34
34
{
35
35
$ builder
36
+ ->beforeNormalization ()
37
+ ->ifTrue (function ($ node ) {
38
+ return empty ($ node ['dsn ' ]) && (empty ($ node ['host ' ]) || empty ($ node ['vendor ' ]));
39
+ })
40
+ ->thenInvalid ('Invalid configuration %s ' )
41
+ ->end ()
36
42
->children ()
43
+ ->scalarNode ('dsn ' )
44
+ ->info ('The redis connection given as DSN. For example redis://host:port?vendor=predis ' )
45
+ ->end ()
37
46
->scalarNode ('host ' )
38
- ->isRequired ()
39
47
->cannotBeEmpty ()
40
48
->info ('can be a host, or the path to a unix domain socket ' )
41
49
->end ()
42
50
->integerNode ('port ' )->end ()
43
51
->enumNode ('vendor ' )
44
52
->values (['phpredis ' , 'predis ' ])
45
- ->isRequired ()
46
53
->cannotBeEmpty ()
47
54
->info ('The library used internally to interact with Redis server ' )
48
55
->end ()
@@ -67,7 +74,7 @@ public function addConfiguration(ArrayNodeDefinition $builder)
67
74
public function createConnectionFactory (ContainerBuilder $ container , array $ config )
68
75
{
69
76
$ factory = new Definition (RedisConnectionFactory::class);
70
- $ factory ->setArguments ([$ config ]);
77
+ $ factory ->setArguments ([isset ( $ config [ ' dsn ' ]) ? $ config [ ' dsn ' ] : $ config ]);
71
78
72
79
$ factoryId = sprintf ('enqueue.transport.%s.connection_factory ' , $ this ->getName ());
73
80
$ container ->setDefinition ($ factoryId , $ factory );
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ public static function provideConfigs()
106
106
];
107
107
108
108
yield [
109
- 'redis://localhost:1234?foo=bar&lazy=0&persisted=true ' ,
109
+ 'redis://localhost:1234?foo=bar&lazy=0&persisted=true&database=5 ' ,
110
110
[
111
111
'host ' => 'localhost ' ,
112
112
'port ' => 1234 ,
@@ -117,7 +117,7 @@ public static function provideConfigs()
117
117
'persisted ' => true ,
118
118
'lazy ' => false ,
119
119
'foo ' => 'bar ' ,
120
- 'database ' => 0 ,
120
+ 'database ' => 5 ,
121
121
],
122
122
];
123
123
Original file line number Diff line number Diff line change @@ -62,6 +62,26 @@ public function testShouldAllowAddConfiguration()
62
62
], $ config );
63
63
}
64
64
65
+ public function testShouldAllowAddConfigurationFromDSN ()
66
+ {
67
+ $ transport = new RedisTransportFactory ();
68
+ $ tb = new TreeBuilder ();
69
+ $ rootNode = $ tb ->root ('foo ' );
70
+
71
+ $ transport ->addConfiguration ($ rootNode );
72
+ $ processor = new Processor ();
73
+ $ config = $ processor ->process ($ tb ->buildTree (), [[
74
+ 'dsn ' => 'redis://localhost:8080?vendor=predis&persisted=false&lazy=true&database=5 ' ,
75
+ ]]);
76
+
77
+ $ this ->assertEquals ([
78
+ 'persisted ' => false ,
79
+ 'lazy ' => true ,
80
+ 'database ' => 0 ,
81
+ 'dsn ' => 'redis://localhost:8080?vendor=predis&persisted=false&lazy=true&database=5 ' ,
82
+ ], $ config );
83
+ }
84
+
65
85
public function testShouldCreateConnectionFactory ()
66
86
{
67
87
$ container = new ContainerBuilder ();
You can’t perform that action at this time.
0 commit comments