@@ -50,7 +50,7 @@ public function addConfiguration(ArrayNodeDefinition $builder)
50
50
}
51
51
52
52
if (is_string ($ v )) {
53
- return false !== strpos ($ v , ':// ' ) ?
53
+ return false !== strpos ($ v , ':// ' ) || false !== strpos ( $ v , ' env_ ' ) ?
54
54
['dsn ' => $ v ] :
55
55
['alias ' => $ v ];
56
56
}
@@ -69,7 +69,9 @@ public function createConnectionFactory(ContainerBuilder $container, array $conf
69
69
if (isset ($ config ['alias ' ])) {
70
70
$ aliasId = sprintf ('enqueue.transport.%s.connection_factory ' , $ config ['alias ' ]);
71
71
} else {
72
- $ aliasId = $ this ->findFactory ($ config ['dsn ' ])->createConnectionFactory ($ container , $ config );
72
+ $ dsn = $ this ->resolveDSN ($ container , $ config ['dsn ' ]);
73
+
74
+ $ aliasId = $ this ->findFactory ($ dsn )->createConnectionFactory ($ container , $ config );
73
75
}
74
76
75
77
$ factoryId = sprintf ('enqueue.transport.%s.connection_factory ' , $ this ->getName ());
@@ -88,7 +90,9 @@ public function createContext(ContainerBuilder $container, array $config)
88
90
if (isset ($ config ['alias ' ])) {
89
91
$ aliasId = sprintf ('enqueue.transport.%s.context ' , $ config ['alias ' ]);
90
92
} else {
91
- $ aliasId = $ this ->findFactory ($ config ['dsn ' ])->createContext ($ container , $ config );
93
+ $ dsn = $ this ->resolveDSN ($ container , $ config ['dsn ' ]);
94
+
95
+ $ aliasId = $ this ->findFactory ($ dsn )->createContext ($ container , $ config );
92
96
}
93
97
94
98
$ contextId = sprintf ('enqueue.transport.%s.context ' , $ this ->getName ());
@@ -107,7 +111,9 @@ public function createDriver(ContainerBuilder $container, array $config)
107
111
if (isset ($ config ['alias ' ])) {
108
112
$ aliasId = sprintf ('enqueue.client.%s.driver ' , $ config ['alias ' ]);
109
113
} else {
110
- $ aliasId = $ this ->findFactory ($ config ['dsn ' ])->createDriver ($ container , $ config );
114
+ $ dsn = $ this ->resolveDSN ($ container , $ config ['dsn ' ]);
115
+
116
+ $ aliasId = $ this ->findFactory ($ dsn )->createDriver ($ container , $ config );
111
117
}
112
118
113
119
$ driverId = sprintf ('enqueue.client.%s.driver ' , $ this ->getName ());
@@ -126,6 +132,33 @@ public function getName()
126
132
return $ this ->name ;
127
133
}
128
134
135
+ /**
136
+ * This is a quick fix to the exception "Incompatible use of dynamic environment variables "ENQUEUE_DSN" found in parameters."
137
+ * TODO: We'll have to come up with a better solution.
138
+ *
139
+ * @param ContainerBuilder $container
140
+ * @param $dsn
141
+ *
142
+ * @return array|false|string
143
+ */
144
+ private function resolveDSN (ContainerBuilder $ container , $ dsn )
145
+ {
146
+ if (method_exists ($ container , 'resolveEnvPlaceholders ' )) {
147
+ $ dsn = $ container ->resolveEnvPlaceholders ($ dsn );
148
+
149
+ $ matches = [];
150
+ if (preg_match ('/%env\((.*?)\)/ ' , $ dsn , $ matches )) {
151
+ if (false === $ realDsn = getenv ($ matches [1 ])) {
152
+ throw new \LogicException (sprintf ('The env "%s" var is not defined ' , $ matches [1 ]));
153
+ }
154
+
155
+ return $ realDsn ;
156
+ }
157
+ }
158
+
159
+ return $ dsn ;
160
+ }
161
+
129
162
/**
130
163
* @param string
131
164
* @param mixed $dsn
0 commit comments