Skip to content

Commit

Permalink
Decouple the Twig extension from the Templating component
Browse files Browse the repository at this point in the history
  • Loading branch information
GeLoLabs committed Feb 25, 2016
1 parent 9411fd6 commit ba497b4
Show file tree
Hide file tree
Showing 23 changed files with 1,133 additions and 772 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/vendor

# PHPUnit
/build
/phpunit.xml
/clover.xml
/report

# Coveralls
/coveralls.json
5 changes: 3 additions & 2 deletions DependencyInjection/Compiler/AssetsHelperCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Create assets.packages fallback alias for Symfony < 2.7
*
* @author Adam Misiorny <adam.misiorny@gmail.com>
* @author GeLo <geloen.eric@gmail.com>
*/
class AssetsHelperCompilerPass implements CompilerPassInterface
{
Expand All @@ -27,8 +28,8 @@ class AssetsHelperCompilerPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (Kernel::VERSION_ID < 20700 && $container->has('templating.helper.assets')) {
$container->setAlias('assets.packages', 'templating.helper.assets');
if (Kernel::VERSION_ID < 20700 && $container->hasDefinition($definition = 'templating.helper.assets')) {
$container->setAlias('assets.packages', $definition);
}
}
}
14 changes: 6 additions & 8 deletions DependencyInjection/Compiler/ResourceCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@ class ResourceCompilerPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
$templatingEngines = $container->getParameter('templating.engines');

if (in_array('php', $templatingEngines)) {
if ($container->hasParameter($parameter = 'templating.helper.form.resources')) {
$container->setParameter(
'templating.helper.form.resources',
$parameter,
array_merge(
array('IvoryCKEditorBundle:Form'),
$container->getParameter('templating.helper.form.resources')
$container->getParameter($parameter)
)
);
}

if (in_array('twig', $templatingEngines)) {
if ($container->hasParameter($parameter = 'twig.form.resources')) {
$container->setParameter(
'twig.form.resources',
$parameter,
array_merge(
array('IvoryCKEditorBundle:Form:ckeditor_widget.html.twig'),
$container->getParameter('twig.form.resources')
$container->getParameter($parameter)
)
);
}
Expand Down
37 changes: 37 additions & 0 deletions DependencyInjection/Compiler/TemplatingCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Ivory CKEditor package.
*
* (c) Eric GELOEN <geloen.eric@gmail.com>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/

namespace Ivory\CKEditorBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Templating compiler pass.
*
* @author GeLo <geloen.eric@gmail.com>
*/
class TemplatingCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('templating.engine.php')) {
$container->removeDefinition('ivory_ck_editor.templating.helper');
}

if (!$container->hasDefinition('twig')) {
$container->removeDefinition('ivory_ck_editor.twig_extension');
}
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/IvoryCKEditorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IvoryCKEditorExtension extends ConfigurableExtension
protected function loadInternal(array $config, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
foreach (array('form', 'templating', 'twig') as $service) {
foreach (array('form', 'renderer', 'templating', 'twig') as $service) {
$loader->load($service.'.xml');
}

Expand Down
4 changes: 3 additions & 1 deletion IvoryCKEditorBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Ivory\CKEditorBundle\DependencyInjection\Compiler\AssetsHelperCompilerPass;
use Ivory\CKEditorBundle\DependencyInjection\Compiler\ResourceCompilerPass;
use Ivory\CKEditorBundle\DependencyInjection\Compiler\TemplatingCompilerPass;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand All @@ -30,7 +31,8 @@ class IvoryCKEditorBundle extends Bundle
public function build(ContainerBuilder $container)
{
$container
->addCompilerPass(new AssetsHelperCompilerPass())
->addCompilerPass(new ResourceCompilerPass())
->addCompilerPass(new AssetsHelperCompilerPass());
->addCompilerPass(new TemplatingCompilerPass());
}
}

0 comments on commit ba497b4

Please sign in to comment.