From 31c4eefbb90dcef7fb5e322449720869927eadf6 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 14 Mar 2015 20:01:00 -0400 Subject: [PATCH 1/4] Adding the new Bundle Framework class with a working addTwigNamespace() method This is meant to replace the @FOSUser Twig syntax AND the FosUserBundle:Register:register.html.twig syntax. Though, those haven't been deprecated yet --- .../Bundle/FrameworkBundle/Bundle/Bundle.php | 33 +++++++++++++++++++ .../DependencyInjection/TwigExtension.php | 6 ++++ 2 files changed, 39 insertions(+) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Bundle/Bundle.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Bundle/Bundle.php b/src/Symfony/Bundle/FrameworkBundle/Bundle/Bundle.php new file mode 100644 index 0000000000000..acf2565ff77d2 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Bundle/Bundle.php @@ -0,0 +1,33 @@ +twigPaths[$namespace] = $templateDirectory; + } + + public function build(ContainerBuilder $container) + { + foreach ($this->twigPaths as $namespace => $directory) { + if (!is_dir($directory)) { + throw new \InvalidArgumentException(sprintf( + 'Directory "%s" does not exist, so it cannot be added as a Twig path', $directory + )); + } + + $container->prependExtensionConfig('twig', array( + 'paths' => array($directory => $namespace) + )); + } + } + + +} \ No newline at end of file diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 70ed9eed9c112..9a07a145871ee 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -64,6 +64,12 @@ public function load(array $configs, ContainerBuilder $container) if (!$namespace) { $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path)); } else { + // register the "override" path + $twigFilesystemLoaderDefinition->addMethodCall('addPath', array( + $container->getParameter('kernel.root_dir').'/Resources/'.$namespace.'/views', + $namespace + )); + $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace)); } } From 03322b2bbf53a53fdc64217b6d23efcf72bbeaca Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 14 Mar 2015 20:55:48 -0400 Subject: [PATCH 2/4] Adding some deprecations --- .../FrameworkBundle/Templating/Loader/TemplateLocator.php | 4 ++++ .../Bundle/FrameworkBundle/Templating/TemplateNameParser.php | 3 +++ src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php index 286b7c62e4d2a..7a679b06ffb74 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php @@ -62,9 +62,13 @@ protected function getCacheKey($template) * * @throws \InvalidArgumentException When the template is not an instance of TemplateReferenceInterface * @throws \InvalidArgumentException When the template file can not be found + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function locate($template, $currentPath = null, $first = true) { + trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + if (!$template instanceof TemplateReferenceInterface) { throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php index 5730807facd4b..0cdc26817d688 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php @@ -20,6 +20,7 @@ * "bundle:section:template.format.engine" to TemplateReferenceInterface * instances. * + * @deprecated since version 2.8, to be removed in 3.0 * @author Fabien Potencier */ class TemplateNameParser extends BaseTemplateNameParser @@ -48,6 +49,8 @@ public function parse($name) return $this->cache[$name]; } + trigger_error('The "bundle:section:template.format.engine" syntax is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + // normalize name $name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'))); diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index 3c7f925d034d3..6337337756d19 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -78,7 +78,7 @@ protected function findTemplate($template) } catch (\Twig_Error_Loader $e) { $previous = $e; - // for BC + // deprecated - supports the bundle:directory:filename.format.engine format try { $template = $this->parser->parse($template); $file = $this->locator->locate($template); From 793fc325af98d5ba924f31a1941255b239989976 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 14 Mar 2015 21:00:14 -0400 Subject: [PATCH 3/4] Deprecating the @AcmeDemo Twig path namespace for an AcmeDemoBundle --- .../Bundle/TwigBundle/DependencyInjection/TwigExtension.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 9a07a145871ee..9d54c568fd781 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -74,7 +74,7 @@ public function load(array $configs, ContainerBuilder $container) } } - // register bundles as Twig namespaces + // register bundles as Twig namespaces (deprecated) foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views')) { $this->addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle); @@ -126,6 +126,9 @@ public function load(array $configs, ContainerBuilder $container) )); } + /** + * @deprecated The automatic @AcmeDemo (for AcmeDemoBundle) Twig path was deprecated in 2.8 and will be removed in 3.0 + */ private function addTwigPath($twigFilesystemLoaderDefinition, $dir, $bundle) { $name = $bundle; From 0325692deadd9d118416c3268d02ba93dd8f786c Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 14 Mar 2015 21:10:18 -0400 Subject: [PATCH 4/4] Fixing error if the app/Resources override directory didn't exist --- .../TwigBundle/DependencyInjection/TwigExtension.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 9d54c568fd781..dcc3854a4d209 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -65,10 +65,9 @@ public function load(array $configs, ContainerBuilder $container) $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path)); } else { // register the "override" path - $twigFilesystemLoaderDefinition->addMethodCall('addPath', array( - $container->getParameter('kernel.root_dir').'/Resources/'.$namespace.'/views', - $namespace - )); + if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/'.$namespace.'/views')) { + $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir, $namespace)); + } $twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace)); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy