From 5e555d3d1a521cddbc829c5eb67ea3392cd8b6b5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 14 Jan 2010 18:34:03 +0100 Subject: [PATCH] [DependencyInjection] added an extension for the Symfony Templating Component --- .../Extension/SymfonyTemplatingExtension.php | 121 ++++++++++++++++++ .../Extension/xml/symfony/templating-1.0.xml | 46 +++++++ .../Loader/schema/symfony/symfony-1.0.xsd | 19 +++ 3 files changed, 186 insertions(+) create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php create mode 100644 src/Symfony/Components/DependencyInjection/Loader/Extension/xml/symfony/templating-1.0.xml create mode 100644 src/Symfony/Components/DependencyInjection/Loader/schema/symfony/symfony-1.0.xsd diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php b/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php new file mode 100644 index 000000000000..8eec895aff58 --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php @@ -0,0 +1,121 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * SymfonyTemplatingExtension is an extension for the Symfony Templating Component. + * + * @package symfony + * @subpackage dependency_injection + * @author Fabien Potencier + */ +class SymfonyTemplatingExtension extends LoaderExtension +{ + /** + * Loads the template configuration. + * + * @param array $config A configuration array + * + * @return BuilderConfiguration A BuilderConfiguration instance + */ + public function templatingLoad($config) + { + $configuration = new BuilderConfiguration(); + + $loader = new XmlFileLoader(__DIR__.'/xml/symfony'); + $configuration->merge($loader->load('templating-1.0.xml')); + + // path for the filesystem loader + if (isset($config['path'])) + { + $configuration->setParameter('symfony.templating.loader.filesystem.path', $config['path']); + } + + // loaders + if (isset($config['loader'])) + { + $loaders = array(); + $ids = is_array($config['loader']) ? $config['loader'] : array($config['loader']); + foreach ($ids as $id) + { + $loaders[] = new Reference($id); + } + } + else + { + $loaders = array( + new Reference('symfony.templating.loader.filesystem'), + ); + } + + $configuration->setParameter('symfony.templating.loader.chain.loaders', $loaders); + $configuration->setAlias('symfony.templating.loader', 'symfony.templating.loader.chain'); + + // helpers + if (isset($config['helper'])) + { + $helpers = array(); + $ids = is_array($config['helper']) ? $config['helper'] : array($config['helper']); + foreach ($ids as $id) + { + $helpers[] = new Reference($id); + } + } + else + { + $helpers = array( + new Reference('symfony.templating.helper.javascripts'), + new Reference('symfony.templating.helper.stylesheets'), + ); + } + + $configuration->setParameter('symfony.templating.helpers', $helpers); + + // cache? + if (isset($config['cache'])) + { + // wrap the loader with some cache + $configuration->setAlias('symfony.templating.loader.wrapped', $configuration->getAlias('symfony.templating.loader')); + $configuration->setAlias('symfony.templating.loader', 'symfony.templating.loader.cache'); + $configuration->setParameter('symfony.templating.loader.cache.path', $config['cache']); + } + + return $configuration; + } + + /** + * Returns the namespace to be used for this extension (XML namespace). + * + * @return string The XML namespace + */ + public function getNamespace() + { + return 'http://www.symfony-project.org/schema/symfony'; + } + + /** + * Returns the recommanded alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * @return string The alias + */ + public function getAlias() + { + return 'symfony'; + } +} diff --git a/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/symfony/templating-1.0.xml b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/symfony/templating-1.0.xml new file mode 100644 index 000000000000..8d2e031aec0d --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/Extension/xml/symfony/templating-1.0.xml @@ -0,0 +1,46 @@ + + + + + + Symfony\Components\Templating\Engine + Symfony\Components\Templating\Helper\HelperSet + Symfony\Components\Templating\Loader\FilesystemLoader + Symfony\Components\Templating\Loader\CacheLoader + Symfony\Components\Templating\Loader\ChainLoader + Symfony\Components\Templating\Helper\JavascriptsHelper + Symfony\Components\Templating\Helper\StylesheetsHelper + + + + + + + + + + + %symfony.templating.helpers% + + + + %symfony.templating.loader.filesystem.path% + + + + + %symfony.templating.loader.cache.path% + + + + %symfony.templating.loader.chain.loaders% + + + + + + + + diff --git a/src/Symfony/Components/DependencyInjection/Loader/schema/symfony/symfony-1.0.xsd b/src/Symfony/Components/DependencyInjection/Loader/schema/symfony/symfony-1.0.xsd new file mode 100644 index 000000000000..6be57233202f --- /dev/null +++ b/src/Symfony/Components/DependencyInjection/Loader/schema/symfony/symfony-1.0.xsd @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + +