13
13
14
14
use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
15
15
use Symfony \Component \DependencyInjection \ContainerInterface ;
16
+ use Symfony \Component \DependencyInjection \ChildDefinition ;
16
17
use Symfony \Component \DependencyInjection \DefinitionDecorator ;
17
18
use Symfony \Component \DependencyInjection \Reference ;
18
19
use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
@@ -143,24 +144,24 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
143
144
$ container ->setParameter (sprintf ('swiftmailer.mailer.%s.transport.smtp.%s ' , $ name , $ key ), $ mailer [$ key ]);
144
145
}
145
146
146
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.transport.eventdispatcher.abstract ' );
147
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.transport.eventdispatcher.abstract ' );
147
148
$ container
148
149
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.eventdispatcher ' , $ name ), $ definitionDecorator )
149
150
;
150
151
151
152
if ('smtp ' === $ transport ) {
152
- $ authDecorator = new DefinitionDecorator ('swiftmailer.transport.authhandler.abstract ' );
153
+ $ authDecorator = $ this -> createChildDefinition ('swiftmailer.transport.authhandler.abstract ' );
153
154
$ container
154
155
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.authhandler ' , $ name ), $ authDecorator )
155
156
->addMethodCall ('setUsername ' , array (sprintf ('%%swiftmailer.mailer.%s.transport.smtp.username%% ' , $ name )))
156
157
->addMethodCall ('setPassword ' , array (sprintf ('%%swiftmailer.mailer.%s.transport.smtp.password%% ' , $ name )))
157
158
->addMethodCall ('setAuthMode ' , array (sprintf ('%%swiftmailer.mailer.%s.transport.smtp.auth_mode%% ' , $ name )));
158
159
159
- $ bufferDecorator = new DefinitionDecorator ('swiftmailer.transport.buffer.abstract ' );
160
+ $ bufferDecorator = $ this -> createChildDefinition ('swiftmailer.transport.buffer.abstract ' );
160
161
$ container
161
162
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.buffer ' , $ name ), $ bufferDecorator );
162
163
163
- $ configuratorDecorator = new DefinitionDecorator ('swiftmailer.transport.smtp.configurator.abstract ' );
164
+ $ configuratorDecorator = $ this -> createChildDefinition ('swiftmailer.transport.smtp.configurator.abstract ' );
164
165
$ container
165
166
->setDefinition (sprintf ('swiftmailer.transport.configurator.%s ' , $ name ), $ configuratorDecorator )
166
167
->setArguments (array (
@@ -169,7 +170,7 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
169
170
))
170
171
;
171
172
172
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.transport.smtp.abstract ' );
173
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.transport.smtp.abstract ' );
173
174
$ container
174
175
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.smtp ' , $ name ), $ definitionDecorator )
175
176
->setArguments (array (
@@ -192,11 +193,11 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
192
193
193
194
$ container ->setAlias (sprintf ('swiftmailer.mailer.%s.transport ' , $ name ), sprintf ('swiftmailer.mailer.%s.transport.%s ' , $ name , $ transport ));
194
195
} elseif ('sendmail ' === $ transport ) {
195
- $ bufferDecorator = new DefinitionDecorator ('swiftmailer.transport.buffer.abstract ' );
196
+ $ bufferDecorator = $ this -> createChildDefinition ('swiftmailer.transport.buffer.abstract ' );
196
197
$ container
197
198
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.buffer ' , $ name ), $ bufferDecorator );
198
199
199
- $ configuratorDecorator = new DefinitionDecorator ('swiftmailer.transport.smtp.configurator.abstract ' );
200
+ $ configuratorDecorator = $ this -> createChildDefinition ('swiftmailer.transport.smtp.configurator.abstract ' );
200
201
$ container
201
202
->setDefinition (sprintf ('swiftmailer.transport.configurator.%s ' , $ name ), $ configuratorDecorator )
202
203
->setArguments (array (
@@ -205,7 +206,7 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
205
206
))
206
207
;
207
208
208
- $ definitionDecorator = new DefinitionDecorator (sprintf ('swiftmailer.transport.%s.abstract ' , $ transport ));
209
+ $ definitionDecorator = $ this -> createChildDefinition (sprintf ('swiftmailer.transport.%s.abstract ' , $ transport ));
209
210
$ container
210
211
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.%s ' , $ name , $ transport ), $ definitionDecorator )
211
212
->setArguments (array (
@@ -217,14 +218,14 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
217
218
218
219
$ container ->setAlias (sprintf ('swiftmailer.mailer.%s.transport ' , $ name ), sprintf ('swiftmailer.mailer.%s.transport.%s ' , $ name , $ transport ));
219
220
} elseif ('mail ' === $ transport ) {
220
- $ definitionDecorator = new DefinitionDecorator (sprintf ('swiftmailer.transport.%s.abstract ' , $ transport ));
221
+ $ definitionDecorator = $ this -> createChildDefinition (sprintf ('swiftmailer.transport.%s.abstract ' , $ transport ));
221
222
$ container
222
223
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.%s ' , $ name , $ transport ), $ definitionDecorator )
223
224
->addArgument (new Reference (sprintf ('swiftmailer.mailer.%s.transport.eventdispatcher ' , $ name )))
224
225
;
225
226
$ container ->setAlias (sprintf ('swiftmailer.mailer.%s.transport ' , $ name ), sprintf ('swiftmailer.mailer.%s.transport.%s ' , $ name , $ transport ));
226
227
} elseif ('null ' === $ transport ) {
227
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.transport.null.abstract ' );
228
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.transport.null.abstract ' );
228
229
$ container
229
230
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.null ' , $ name , $ transport ), $ definitionDecorator )
230
231
->setArguments (array (
@@ -236,7 +237,7 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
236
237
$ container ->setAlias (sprintf ('swiftmailer.mailer.%s.transport ' , $ name ), sprintf ('swiftmailer.mailer.transport.%s ' , $ transport ));
237
238
}
238
239
239
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.mailer.abstract ' );
240
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.mailer.abstract ' );
240
241
$ container
241
242
->setDefinition (sprintf ('swiftmailer.mailer.%s ' , $ name ), $ definitionDecorator )
242
243
->replaceArgument (0 , new Reference (sprintf ('swiftmailer.mailer.%s.transport ' , $ name )))
@@ -255,7 +256,7 @@ protected function configureMailerSpool($name, array $mailer, ContainerBuilder $
255
256
}
256
257
}
257
258
258
- $ definitionDecorator = new DefinitionDecorator (sprintf ('swiftmailer.spool.%s.abstract ' , $ type ));
259
+ $ definitionDecorator = $ this -> createChildDefinition (sprintf ('swiftmailer.spool.%s.abstract ' , $ type ));
259
260
if ('file ' === $ type ) {
260
261
$ container
261
262
->setDefinition (sprintf ('swiftmailer.mailer.%s.spool.file ' , $ name ), $ definitionDecorator )
@@ -268,7 +269,7 @@ protected function configureMailerSpool($name, array $mailer, ContainerBuilder $
268
269
}
269
270
$ container ->setAlias (sprintf ('swiftmailer.mailer.%s.spool ' , $ name ), sprintf ('swiftmailer.mailer.%s.spool.%s ' , $ name , $ type ));
270
271
271
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.transport.spool.abstract ' );
272
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.transport.spool.abstract ' );
272
273
$ container
273
274
->setDefinition (sprintf ('swiftmailer.mailer.%s.transport.spool ' , $ name ), $ definitionDecorator )
274
275
->setArguments (array (
@@ -297,7 +298,7 @@ protected function configureMailerSenderAddress($name, array $mailer, ContainerB
297
298
{
298
299
if (isset ($ mailer ['sender_address ' ]) && $ mailer ['sender_address ' ]) {
299
300
$ container ->setParameter (sprintf ('swiftmailer.mailer.%s.sender_address ' , $ name ), $ mailer ['sender_address ' ]);
300
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.plugin.impersonate.abstract ' );
301
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.plugin.impersonate.abstract ' );
301
302
$ container
302
303
->setDefinition (sprintf ('swiftmailer.mailer.%s.plugin.impersonate ' , $ name ), $ definitionDecorator )
303
304
->setArguments (array (
@@ -319,7 +320,7 @@ protected function configureMailerAntiFlood($name, array $mailer, ContainerBuild
319
320
if (isset ($ mailer ['antiflood ' ])) {
320
321
$ container ->setParameter (sprintf ('swiftmailer.mailer.%s.antiflood.threshold ' , $ name ), $ mailer ['antiflood ' ]['threshold ' ]);
321
322
$ container ->setParameter (sprintf ('swiftmailer.mailer.%s.antiflood.sleep ' , $ name ), $ mailer ['antiflood ' ]['sleep ' ]);
322
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.plugin.antiflood.abstract ' );
323
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.plugin.antiflood.abstract ' );
323
324
$ container
324
325
->setDefinition (sprintf ('swiftmailer.mailer.%s.plugin.antiflood ' , $ name ), $ definitionDecorator )
325
326
->setArguments (array (
@@ -340,7 +341,7 @@ protected function configureMailerDeliveryAddress($name, array $mailer, Containe
340
341
$ container ->setParameter (sprintf ('swiftmailer.mailer.%s.single_address ' , $ name ), $ mailer ['delivery_addresses ' ][0 ]);
341
342
$ container ->setParameter (sprintf ('swiftmailer.mailer.%s.delivery_addresses ' , $ name ), $ mailer ['delivery_addresses ' ]);
342
343
$ container ->setParameter (sprintf ('swiftmailer.mailer.%s.delivery_whitelist ' , $ name ), $ mailer ['delivery_whitelist ' ]);
343
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.plugin.redirecting.abstract ' );
344
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.plugin.redirecting.abstract ' );
344
345
$ container
345
346
->setDefinition (sprintf ('swiftmailer.mailer.%s.plugin.redirecting ' , $ name ), $ definitionDecorator )
346
347
->setArguments (array (
@@ -361,7 +362,7 @@ protected function configureMailerLogging($name, array $mailer, ContainerBuilder
361
362
{
362
363
if ($ mailer ['logging ' ]) {
363
364
$ container ->getDefinition ('swiftmailer.plugin.messagelogger.abstract ' );
364
- $ definitionDecorator = new DefinitionDecorator ('swiftmailer.plugin.messagelogger.abstract ' );
365
+ $ definitionDecorator = $ this -> createChildDefinition ('swiftmailer.plugin.messagelogger.abstract ' );
365
366
$ container
366
367
->setDefinition (sprintf ('swiftmailer.mailer.%s.plugin.messagelogger ' , $ name ), $ definitionDecorator )
367
368
;
@@ -396,4 +397,13 @@ public function getConfiguration(array $config, ContainerBuilder $container)
396
397
{
397
398
return new Configuration ($ container ->getParameter ('kernel.debug ' ));
398
399
}
400
+
401
+ private function createChildDefinition ($ id )
402
+ {
403
+ if (class_exists ('Symfony\Component\DependencyInjection\ChildDefinition ' )) {
404
+ return new ChildDefinition ($ id );
405
+ }
406
+
407
+ return new DefinitionDecorator ($ id );
408
+ }
399
409
}
0 commit comments