@@ -101,12 +101,31 @@ public function load(array $configs, ContainerBuilder $container)
101
101
102
102
$ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
103
103
104
+ $ oldAssetsConfigured = false ;
105
+ if (
106
+ isset ($ config ['templating ' ])
107
+ &&
108
+ (
109
+ count ($ config ['templating ' ]['packages ' ])
110
+ ||
111
+ count ($ config ['templating ' ]['assets_base_urls ' ]['http ' ])
112
+ ||
113
+ count ($ config ['templating ' ]['assets_base_urls ' ]['ssl ' ])
114
+ )
115
+ ) {
116
+ $ oldAssetsConfigured = true ;
117
+ }
118
+
119
+ if (isset ($ config ['assets ' ]) && $ oldAssetsConfigured ) {
120
+ throw new \LogicException ('You cannot use the old asset configuration with the new one. ' );
121
+ }
122
+
104
123
if (isset ($ config ['assets ' ])) {
105
124
$ this ->registerAssetsConfiguration ($ config ['assets ' ], $ container , $ loader );
106
125
}
107
126
108
127
if (isset ($ config ['templating ' ])) {
109
- $ this ->registerTemplatingConfiguration ($ config ['templating ' ], $ config ['ide ' ], $ container , $ loader );
128
+ $ this ->registerTemplatingConfiguration ($ config ['templating ' ], $ config ['ide ' ], $ container , $ loader, $ oldAssetsConfigured );
110
129
}
111
130
112
131
$ this ->registerValidationConfiguration ($ config ['validation ' ], $ container , $ loader );
@@ -459,10 +478,9 @@ private function registerRequestConfiguration(array $config, ContainerBuilder $c
459
478
* @param ContainerBuilder $container A ContainerBuilder instance
460
479
* @param XmlFileLoader $loader An XmlFileLoader instance
461
480
*/
462
- private function registerTemplatingConfiguration (array $ config , $ ide , ContainerBuilder $ container , XmlFileLoader $ loader )
481
+ private function registerTemplatingConfiguration (array $ config , $ ide , ContainerBuilder $ container , XmlFileLoader $ loader, $ oldAssetsConfigured )
463
482
{
464
483
$ loader ->load ('templating.xml ' );
465
- $ loader ->load ('templating_php.xml ' );
466
484
467
485
$ links = array (
468
486
'textmate ' => 'txmt://open?url=file://%%f&line=%%l ' ,
@@ -472,12 +490,23 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
472
490
);
473
491
474
492
$ container ->setParameter ('templating.helper.code.file_link_format ' , isset ($ links [$ ide ]) ? $ links [$ ide ] : $ ide );
475
- $ container ->setParameter ('templating.helper.form.resources ' , $ config ['form ' ]['resources ' ]);
476
493
$ container ->setParameter ('fragment.renderer.hinclude.global_template ' , $ config ['hinclude_default_template ' ]);
477
494
478
- if ($ container ->getParameter ('kernel.debug ' )) {
479
- $ loader ->load ('templating_debug.xml ' );
495
+ if ($ oldAssetsConfigured ) {
496
+ $ loader ->load ('old_assets.xml ' );
497
+
498
+ // create package definitions and add them to the assets helper
499
+ $ defaultPackage = $ this ->createTemplatingPackageDefinition ($ container , $ config ['assets_base_urls ' ]['http ' ], $ config ['assets_base_urls ' ]['ssl ' ], $ config ['assets_version ' ], $ config ['assets_version_format ' ]);
500
+ $ container ->setDefinition ('templating.asset.default_package ' , $ defaultPackage );
501
+ $ namedPackages = array ();
502
+ foreach ($ config ['packages ' ] as $ name => $ package ) {
503
+ $ namedPackage = $ this ->createTemplatingPackageDefinition ($ container , $ package ['base_urls ' ]['http ' ], $ package ['base_urls ' ]['ssl ' ], $ package ['version ' ], $ package ['version_format ' ], $ name );
504
+ $ container ->setDefinition ('templating.asset.package. ' .$ name , $ namedPackage );
505
+ $ namedPackages [$ name ] = new Reference ('templating.asset.package. ' .$ name );
506
+ }
507
+ }
480
508
509
+ if ($ container ->getParameter ('kernel.debug ' )) {
481
510
$ logger = new Reference ('logger ' , ContainerInterface::IGNORE_ON_INVALID_REFERENCE );
482
511
483
512
$ container ->getDefinition ('templating.loader.cache ' )
@@ -486,25 +515,8 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
486
515
$ container ->getDefinition ('templating.loader.chain ' )
487
516
->addTag ('monolog.logger ' , array ('channel ' => 'templating ' ))
488
517
->addMethodCall ('setLogger ' , array ($ logger ));
489
-
490
- $ container ->setDefinition ('templating.engine.php ' , $ container ->findDefinition ('debug.templating.engine.php ' ));
491
- $ container ->setAlias ('debug.templating.engine.php ' , 'templating.engine.php ' );
492
518
}
493
519
494
- // create package definitions and add them to the assets helper
495
- $ defaultPackage = $ this ->createTemplatingPackageDefinition ($ container , $ config ['assets_base_urls ' ]['http ' ], $ config ['assets_base_urls ' ]['ssl ' ], $ config ['assets_version ' ], $ config ['assets_version_format ' ]);
496
- $ container ->setDefinition ('templating.asset.default_package ' , $ defaultPackage );
497
- $ namedPackages = array ();
498
- foreach ($ config ['packages ' ] as $ name => $ package ) {
499
- $ namedPackage = $ this ->createTemplatingPackageDefinition ($ container , $ package ['base_urls ' ]['http ' ], $ package ['base_urls ' ]['ssl ' ], $ package ['version ' ], $ package ['version_format ' ], $ name );
500
- $ container ->setDefinition ('templating.asset.package. ' .$ name , $ namedPackage );
501
- $ namedPackages [$ name ] = new Reference ('templating.asset.package. ' .$ name );
502
- }
503
- $ container ->getDefinition ('templating.helper.assets ' )->setArguments (array (
504
- new Reference ('templating.asset.default_package ' ),
505
- $ namedPackages ,
506
- ));
507
-
508
520
if (!empty ($ config ['loaders ' ])) {
509
521
$ loaders = array_map (function ($ loader ) { return new Reference ($ loader ); }, $ config ['loaders ' ]);
510
522
@@ -534,14 +546,6 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
534
546
$ container ->findDefinition ('templating.locator ' )->getClass (),
535
547
));
536
548
537
- if (in_array ('php ' , $ config ['engines ' ], true )) {
538
- $ this ->addClassesToCompile (array (
539
- 'Symfony \\Component \\Templating \\Storage \\FileStorage ' ,
540
- 'Symfony \\Bundle \\FrameworkBundle \\Templating \\PhpEngine ' ,
541
- 'Symfony \\Bundle \\FrameworkBundle \\Templating \\Loader \\FilesystemLoader ' ,
542
- ));
543
- }
544
-
545
549
$ container ->setParameter ('templating.engines ' , $ config ['engines ' ]);
546
550
$ engines = array_map (function ($ engine ) { return new Reference ('templating.engine. ' .$ engine ); }, $ config ['engines ' ]);
547
551
@@ -554,6 +558,33 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
554
558
}
555
559
$ container ->setAlias ('templating ' , 'templating.engine.delegating ' );
556
560
}
561
+
562
+ // configure the PHP engine if needed
563
+ if (in_array ('php ' , $ config ['engines ' ], true )) {
564
+ $ loader ->load ('templating_php.xml ' );
565
+
566
+ $ container ->setParameter ('templating.helper.form.resources ' , $ config ['form ' ]['resources ' ]);
567
+
568
+ if ($ container ->getParameter ('kernel.debug ' )) {
569
+ $ loader ->load ('templating_debug.xml ' );
570
+
571
+ $ container ->setDefinition ('templating.engine.php ' , $ container ->findDefinition ('debug.templating.engine.php ' ));
572
+ $ container ->setAlias ('debug.templating.engine.php ' , 'templating.engine.php ' );
573
+ }
574
+
575
+ if ($ oldAssetsConfigured ) {
576
+ $ container ->getDefinition ('templating.helper.assets ' )->setArguments (array (
577
+ new Reference ('templating.asset.default_package ' ),
578
+ $ namedPackages ,
579
+ ));
580
+ }
581
+
582
+ $ this ->addClassesToCompile (array (
583
+ 'Symfony \\Component \\Templating \\Storage \\FileStorage ' ,
584
+ 'Symfony \\Bundle \\FrameworkBundle \\Templating \\PhpEngine ' ,
585
+ 'Symfony \\Bundle \\FrameworkBundle \\Templating \\Loader \\FilesystemLoader ' ,
586
+ ));
587
+ }
557
588
}
558
589
559
590
/**
@@ -679,6 +710,7 @@ private function createPackageDefinition($basePath, array $baseUrls, Reference $
679
710
}
680
711
681
712
$ package = new DefinitionDecorator ('assets.url_package ' );
713
+
682
714
return $ package
683
715
->setPublic (false )
684
716
->replaceArgument (0 , $ baseUrls )
0 commit comments