Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DependencyInjection] added an extension for the Symfony Templating C…
…omponent
- Loading branch information
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
src/Symfony/Components/DependencyInjection/Loader/Extension/SymfonyTemplatingExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace Symfony\Components\DependencyInjection\Loader\Extension; | ||
|
||
use Symfony\Components\DependencyInjection\Loader\LoaderExtension; | ||
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Components\DependencyInjection\BuilderConfiguration; | ||
use Symfony\Components\DependencyInjection\Reference; | ||
|
||
/* | ||
* This file is part of the symfony framework. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* 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 <fabien.potencier@symfony-project.com> | ||
*/ | ||
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'; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Symfony/Components/DependencyInjection/Loader/Extension/xml/symfony/templating-1.0.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://www.symfony-project.org/schema/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.symfony-project.org/schema/services http://www.symfony-project.org/schema/services/services-1.0.xsd"> | ||
|
||
<parameters> | ||
<parameter key="symfony.templating.engine.class">Symfony\Components\Templating\Engine</parameter> | ||
<parameter key="symfony.templating.helperset.class">Symfony\Components\Templating\Helper\HelperSet</parameter> | ||
<parameter key="symfony.templating.loader.filesystem.class">Symfony\Components\Templating\Loader\FilesystemLoader</parameter> | ||
<parameter key="symfony.templating.loader.cache.class">Symfony\Components\Templating\Loader\CacheLoader</parameter> | ||
<parameter key="symfony.templating.loader.Chain.class">Symfony\Components\Templating\Loader\ChainLoader</parameter> | ||
<parameter key="symfony.templating.helper.javascripts.class">Symfony\Components\Templating\Helper\JavascriptsHelper</parameter> | ||
<parameter key="symfony.templating.helper.stylesheets.class">Symfony\Components\Templating\Helper\StylesheetsHelper</parameter> | ||
</parameters> | ||
|
||
<services> | ||
<service id="symfony.templating.engine" class="%symfony.templating.engine.class%"> | ||
<argument type="service" id="symfony.templating.loader" /> | ||
<argument type="collection"></argument> | ||
<argument type="service" id="symfony.templating.helperset" /> | ||
</service> | ||
|
||
<service id="symfony.templating.helperset" class="%symfony.templating.helperset.class%"> | ||
<argument>%symfony.templating.helpers%</argument> | ||
</service> | ||
|
||
<service id="symfony.templating.loader.filesystem" class="%symfony.templating.loader.filesystem.class%"> | ||
<argument>%symfony.templating.loader.filesystem.path%</argument> | ||
</service> | ||
|
||
<service id="symfony.templating.loader.cache" class="%symfony.templating.loader.cache.class%"> | ||
<argument type="service" id="symfony.templating.loader.wrapped" /> | ||
<argument>%symfony.templating.loader.cache.path%</argument> | ||
</service> | ||
|
||
<service id="symfony.templating.loader.chain" class="%symfony.templating.loader.chain.class%"> | ||
<argument>%symfony.templating.loader.chain.loaders%</argument> | ||
</service> | ||
|
||
<service id="symfony.templating.helper.javascripts" class="%symfony.templating.helper.javascripts.class%" /> | ||
<service id="symfony.templating.helper.stylesheets" class="%symfony.templating.helper.stylesheets.class%" /> | ||
|
||
<service id="symfony.templating.loader" alias="symfony.templating.loader.filesystem" /> | ||
</services> | ||
</container> |
19 changes: 19 additions & 0 deletions
19
src/Symfony/Components/DependencyInjection/Loader/schema/symfony/symfony-1.0.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<xsd:schema xmlns="http://www.symfony-project.org/schema/symfony" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
targetNamespace="http://www.symfony-project.org/schema/symfony" | ||
elementFormDefault="qualified"> | ||
|
||
<xsd:element name="templating" type="templating" /> | ||
|
||
<xsd:complexType name="templating"> | ||
<xsd:sequence> | ||
<xsd:element name="loader" type="xsd:string" minOccurs="0" maxOccurs="unbounded" /> | ||
<xsd:element name="helper" type="xsd:string" minOccurs="0" maxOccurs="unbounded" /> | ||
</xsd:sequence> | ||
|
||
<xsd:attribute name="path" type="xsd:string" /> | ||
<xsd:attribute name="cache" type="xsd:string" /> | ||
</xsd:complexType> | ||
</xsd:schema> |