@@ -50,7 +50,7 @@ public function addConfiguration(ArrayNodeDefinition $builder)
5050 }
5151
5252 if (is_string ($ v )) {
53- return false !== strpos ($ v , ':// ' ) ?
53+ return false !== strpos ($ v , ':// ' ) || false !== strpos ( $ v , ' env_ ' ) ?
5454 ['dsn ' => $ v ] :
5555 ['alias ' => $ v ];
5656 }
@@ -69,7 +69,9 @@ public function createConnectionFactory(ContainerBuilder $container, array $conf
6969 if (isset ($ config ['alias ' ])) {
7070 $ aliasId = sprintf ('enqueue.transport.%s.connection_factory ' , $ config ['alias ' ]);
7171 } 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 );
7375 }
7476
7577 $ factoryId = sprintf ('enqueue.transport.%s.connection_factory ' , $ this ->getName ());
@@ -88,7 +90,9 @@ public function createContext(ContainerBuilder $container, array $config)
8890 if (isset ($ config ['alias ' ])) {
8991 $ aliasId = sprintf ('enqueue.transport.%s.context ' , $ config ['alias ' ]);
9092 } 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 );
9296 }
9397
9498 $ contextId = sprintf ('enqueue.transport.%s.context ' , $ this ->getName ());
@@ -107,7 +111,9 @@ public function createDriver(ContainerBuilder $container, array $config)
107111 if (isset ($ config ['alias ' ])) {
108112 $ aliasId = sprintf ('enqueue.client.%s.driver ' , $ config ['alias ' ]);
109113 } 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 );
111117 }
112118
113119 $ driverId = sprintf ('enqueue.client.%s.driver ' , $ this ->getName ());
@@ -126,6 +132,33 @@ public function getName()
126132 return $ this ->name ;
127133 }
128134
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+
129162 /**
130163 * @param string
131164 * @param mixed $dsn
0 commit comments