Skip to content

Commit

Permalink
Remove dependency on symfony/templating
Browse files Browse the repository at this point in the history
  • Loading branch information
covex-nn committed Feb 8, 2018
1 parent 0146c04 commit 3fab05c
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 329 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"symfony/asset": "^2.8 || ^3.2 || ^4.0",
"symfony/form": "^2.8 || ^3.2 || ^4.0",
"symfony/http-kernel": "^2.8 || ^3.2 || ^4.0",
"symfony/templating": "^2.8 || ^3.2 || ^4.0",
"symfony/twig-bundle": "^2.8 || ^3.2 || ^4.0",
"twig/twig": "^1.34 || ^2.0"
},
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/your_first_block.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ We are almost done! Now, just declare the block as a service:
<service id="sonata.block.service.rss" class="Sonata\BlockBundle\Block\Service\RssBlockService">
<tag name="sonata.block" />
<argument/>
<argument type="service" id="sonata.templating" />
<argument type="service" id="twig" />
</service>
.. code-block:: yaml
Expand All @@ -187,8 +187,8 @@ We are almost done! Now, just declare the block as a service:
sonata.block.service.rss:
class: Sonata\BlockBundle\Block\Service\RssBlockService
arguments:
- sonata.block.service.rss
- "@templating"
- ~
- '@twig'
tags:
- { name: sonata.block }
Expand Down
10 changes: 0 additions & 10 deletions src/Block/Service/AbstractAdminBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,12 @@
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\CoreBundle\Model\Metadata;
use Sonata\CoreBundle\Validator\ErrorElement;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;

/**
* @author Christian Gripp <[email protected]>
*/
abstract class AbstractAdminBlockService extends AbstractBlockService implements AdminBlockServiceInterface
{
/**
* @param string $name
* @param EngineInterface $templating
*/
public function __construct($name, EngineInterface $templating)
{
parent::__construct($name, $templating);
}

/**
* {@inheritdoc}
*/
Expand Down
23 changes: 8 additions & 15 deletions src/Block/Service/AbstractBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Twig\Environment;

/**
* @author Sullivan Senechal <[email protected]>
Expand All @@ -31,23 +31,12 @@ abstract class AbstractBlockService implements BlockServiceInterface
protected $name;

/**
* @var EngineInterface|null
* @var Environment
*/
protected $templating;

/**
* @param string $name
* @param EngineInterface $templating
*/
public function __construct($name = null, EngineInterface $templating = null)
public function __construct(string $name, Environment $templating)
{
if (null === $name || null === $templating) {
@trigger_error(
'The $name and $templating parameters will be required fields with the 4.0 release.',
E_USER_DEPRECATED
);
}

$this->name = $name;
$this->templating = $templating;
}
Expand All @@ -63,7 +52,11 @@ public function __construct($name = null, EngineInterface $templating = null)
*/
public function renderResponse($view, array $parameters = [], Response $response = null)
{
return $this->getTemplating()->renderResponse($view, $parameters, $response);
$response = $response ?? new Response();

$response->setContent($this->getTemplating()->render($view, $parameters));

return $response;
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Block/Service/MenuBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
use Sonata\CoreBundle\Form\Type\ImmutableArrayType;
use Sonata\CoreBundle\Model\Metadata;
use Sonata\CoreBundle\Validator\ErrorElement;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* @author Hugo Briand <[email protected]>
Expand All @@ -56,12 +56,9 @@ class MenuBlockService extends AbstractAdminBlockService
protected $menuRegistry;

/**
* @param string $name
* @param EngineInterface $templating
* @param MenuProviderInterface $menuProvider
* @param MenuRegistryInterface|null $menuRegistry
*/
public function __construct($name, EngineInterface $templating, MenuProviderInterface $menuProvider, $menuRegistry = null)
public function __construct(string $name, Environment $templating, MenuProviderInterface $menuProvider, $menuRegistry = null)
{
parent::__construct($name, $templating);

Expand Down
22 changes: 8 additions & 14 deletions src/Exception/Renderer/InlineDebugRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Templating\EngineInterface;
use Twig\Environment;

/**
* This renderer uses a template to display an error message at the block position with extensive debug information.
Expand All @@ -25,11 +25,6 @@
*/
class InlineDebugRenderer implements RendererInterface
{
/**
* @var EngineInterface
*/
protected $templating;

/**
* @var string
*/
Expand All @@ -46,14 +41,13 @@ class InlineDebugRenderer implements RendererInterface
protected $debug;

/**
* @param EngineInterface $templating Templating engine
* @param string $template Template to render
* @param bool $debug Whether the debug is enabled or not
* @param bool $forceStyle Whether to force style within the template or not
* @var Environment
*/
public function __construct(EngineInterface $templating, $template, $debug, $forceStyle = true)
private $twig;

public function __construct(Environment $twig, string $template, bool $debug, bool $forceStyle = true)
{
$this->templating = $templating;
$this->twig = $twig;
$this->template = $template;
$this->debug = $debug;
$this->forceStyle = $forceStyle;
Expand All @@ -62,7 +56,7 @@ public function __construct(EngineInterface $templating, $template, $debug, $for
/**
* {@inheritdoc}
*/
public function render(\Exception $exception, BlockInterface $block, Response $response = null)
public function render(\Exception $exception, BlockInterface $block, Response $response = null): Response
{
$response = $response ?: new Response();

Expand All @@ -84,7 +78,7 @@ public function render(\Exception $exception, BlockInterface $block, Response $r
'forceStyle' => $this->forceStyle,
];

$content = $this->templating->render($this->template, $parameters);
$content = $this->twig->render($this->template, $parameters);
$response->setContent($content);

return $response;
Expand Down
20 changes: 8 additions & 12 deletions src/Exception/Renderer/InlineRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Templating\EngineInterface;
use Twig\Environment;

/**
* This renderer uses a template to display an error message at the block position.
Expand All @@ -24,37 +24,33 @@
*/
class InlineRenderer implements RendererInterface
{
/**
* @var EngineInterface
*/
protected $templating;

/**
* @var string
*/
protected $template;

/**
* @param EngineInterface $templating Templating engine
* @param string $template Template to render
* @var Environment
*/
public function __construct(EngineInterface $templating, $template)
private $twig;

public function __construct(Environment $twig, string $template)
{
$this->templating = $templating;
$this->twig = $twig;
$this->template = $template;
}

/**
* {@inheritdoc}
*/
public function render(\Exception $exception, BlockInterface $block, Response $response = null)
public function render(\Exception $exception, BlockInterface $block, Response $response = null): Response
{
$parameters = [
'exception' => $exception,
'block' => $block,
];

$content = $this->templating->render($this->template, $parameters);
$content = $this->twig->render($this->template, $parameters);

$response = $response ?: new Response();
$response->setContent($content);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/Renderer/MonkeyThrowRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MonkeyThrowRenderer implements RendererInterface
/**
* {@inheritdoc}
*/
public function render(\Exception $banana, BlockInterface $block, Response $response = null): void
public function render(\Exception $banana, BlockInterface $block, Response $response = null): Response
{
throw $banana;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/Renderer/RendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ interface RendererInterface
*
* @return Response
*/
public function render(\Exception $exception, BlockInterface $block, Response $response = null);
public function render(\Exception $exception, BlockInterface $block, Response $response = null): Response;
}
12 changes: 6 additions & 6 deletions src/Resources/config/block.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@
<service id="sonata.block.service.container" class="%sonata.block.service.container.class%">
<tag name="sonata.block"/>
<argument/>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
</service>
<service id="sonata.block.service.empty" class="%sonata.block.service.empty.class%">
<tag name="sonata.block"/>
<argument/>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
</service>
<service id="sonata.block.service.text" class="%sonata.block.service.text.class%">
<tag name="sonata.block"/>
<argument/>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
</service>
<service id="sonata.block.service.rss" class="%sonata.block.service.rss.class%">
<tag name="sonata.block"/>
<argument/>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
</service>
<service id="sonata.block.service.menu" class="%sonata.block.service.menu.class%">
<tag name="sonata.block"/>
<argument/>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
<argument type="service" id="knp_menu.menu_provider"/>
<argument type="service" id="sonata.block.menu.registry"/>
</service>
<service id="sonata.block.service.template" class="%sonata.block.service.template.class%">
<tag name="sonata.block"/>
<argument/>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
</service>
</services>
</container>
13 changes: 0 additions & 13 deletions src/Resources/config/core.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.templating.locator" class="Sonata\BlockBundle\Templating\TemplateLocator">
<argument type="service" id="file_locator"/>
<argument>%kernel.cache_dir%</argument>
</service>
<service id="sonata.templating.name_parser" class="Sonata\BlockBundle\Templating\TemplateNameParser">
<argument type="service" id="kernel"/>
</service>
<service id="sonata.templating" class="Sonata\BlockBundle\Templating\TwigEngine">
<argument type="service" id="twig"/>
<argument type="service" id="sonata.templating.name_parser"/>
<argument type="service" id="sonata.templating.locator"/>
</service>
<service id="sonata.block.manager" class="Sonata\BlockBundle\Block\BlockServiceManager" public="false">
<argument type="service" id="service_container"/>
<argument>%kernel.debug%</argument>
Expand All @@ -38,7 +26,6 @@
<argument type="service" id="sonata.block.templating.helper"/>
</service>
<service id="sonata.block.templating.helper" class="Sonata\BlockBundle\Templating\Helper\BlockHelper">
<tag name="templating.helper" alias="sonata_block"/>
<argument type="service" id="sonata.block.manager"/>
<argument>%sonata_block.cache_blocks%</argument>
<argument type="service" id="sonata.block.renderer"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/exception.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
</service>
<!-- exception renderers -->
<service id="sonata.block.exception.renderer.inline" class="Sonata\BlockBundle\Exception\Renderer\InlineRenderer" public="true">
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
<argument>@SonataBlock/Block/block_exception.html.twig</argument>
</service>
<service id="sonata.block.exception.renderer.inline_debug" class="Sonata\BlockBundle\Exception\Renderer\InlineDebugRenderer" public="true">
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
<argument>@SonataBlock/Block/block_exception_debug.html.twig</argument>
<argument>%kernel.debug%</argument>
<argument>true</argument>
Expand Down
20 changes: 0 additions & 20 deletions src/Templating/EngineInterface.php

This file was deleted.

23 changes: 0 additions & 23 deletions src/Templating/TemplateLocator.php

This file was deleted.

Loading

0 comments on commit 3fab05c

Please sign in to comment.