@@ -60,19 +60,21 @@ public function load(array $configs, ContainerBuilder $container)
6060 $ class = null ;
6161 $ client = null ;
6262
63- switch ($ provider ) {
63+ switch ($ config [ ' providers ' ][ $ provider][ ' driver ' ] ) {
6464 case 'aws ' :
6565 $ class = $ container ->getParameter ('uecode_qpush.provider.aws ' );
6666 $ client = $ this ->createAwsClient (
6767 $ config ['providers ' ][$ provider ],
68- $ container
68+ $ container ,
69+ $ provider
6970 );
7071 break ;
7172 case 'ironmq ' :
7273 $ class = $ container ->getParameter ('uecode_qpush.provider.ironmq ' );
7374 $ client = $ this ->createIronMQClient (
7475 $ config ['providers ' ][$ provider ],
75- $ container
76+ $ container ,
77+ $ provider
7678 );
7779 break ;
7880 case 'sync ' :
@@ -116,12 +118,15 @@ public function load(array $configs, ContainerBuilder $container)
116118 *
117119 * @param array $config A Configuration array for the client
118120 * @param ContainerBuilder $container The container
121+ * @param string $name The provider key
119122 *
120- * return Reference
123+ * @ return Reference
121124 */
122- private function createAwsClient ($ config , ContainerBuilder $ container )
125+ private function createAwsClient ($ config , ContainerBuilder $ container, $ name )
123126 {
124- if (!$ container ->hasDefinition ('uecode_qpush.provider.aws ' )) {
127+ $ service = sprintf ('uecode_qpush.provider.%s ' , $ name );
128+
129+ if (!$ container ->hasDefinition ($ service )) {
125130
126131 if (!class_exists ('Aws\Common\Aws ' )) {
127132 throw new \RuntimeException (
@@ -140,24 +145,27 @@ private function createAwsClient($config, ContainerBuilder $container)
140145 ]
141146 ]);
142147
143- $ container ->setDefinition (' uecode_qpush.provider.aws ' , $ aws )
148+ $ container ->setDefinition ($ service , $ aws )
144149 ->setPublic (false );
145150 }
146151
147- return new Reference (' uecode_qpush.provider.aws ' );
152+ return new Reference ($ service );
148153 }
149154
150155 /**
151156 * Creates a definition for the IronMQ provider
152157 *
153158 * @param array $config A Configuration array for the provider
154159 * @param ContainerBuilder $container The container
160+ * @param string $name The provider key
155161 *
156- * return Reference
162+ * @ return Reference
157163 */
158- private function createIronMQClient ($ config , ContainerBuilder $ container )
164+ private function createIronMQClient ($ config , ContainerBuilder $ container, $ name )
159165 {
160- if (!$ container ->hasDefinition ('uecode_qpush.provider.ironmq ' )) {
166+ $ service = sprintf ('uecode_qpush.provider.%s ' , $ name );
167+
168+ if (!$ container ->hasDefinition ($ service )) {
161169
162170 if (!class_exists ('IronMQ ' )) {
163171 throw new \RuntimeException (
@@ -176,11 +184,11 @@ private function createIronMQClient($config, ContainerBuilder $container)
176184 ]
177185 ]);
178186
179- $ container ->setDefinition (' uecode_qpush.provider.ironmq ' , $ ironmq )
187+ $ container ->setDefinition ($ service , $ ironmq )
180188 ->setPublic (false );
181189 }
182190
183- return new Reference (' uecode_qpush.provider.ironmq ' );
191+ return new Reference ($ service );
184192 }
185193
186194 private function createSyncClient ()
0 commit comments