Skip to content

Commit

Permalink
renamed some classes and Twig functions to more descriptive names (refs
Browse files Browse the repository at this point in the history
#6871)

HttpContentRenderer has been renamed to FragmentHandler.
The RendererStrategy subnamespace has been renamed to Fragment.
The strategy classes now have Fragment in their names.
ProxyRouterListener has been renamed to FragmentListener
The router_proxy configuration entry has been renamed to fragments.
  • Loading branch information
fabpot committed Feb 1, 2013
1 parent c85ec8b commit c72e471
Show file tree
Hide file tree
Showing 35 changed files with 354 additions and 352 deletions.
43 changes: 27 additions & 16 deletions src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Bridge\Twig\Extension;

use Symfony\Component\HttpKernel\HttpContentRenderer;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Component\HttpKernel\Controller\ControllerReference;

/**
Expand All @@ -21,50 +21,61 @@
*/
class HttpKernelExtension extends \Twig_Extension
{
private $renderer;
private $handler;

/**
* Constructor.
*
* @param HttpContentRenderer $renderer A HttpContentRenderer instance
* @param FragmentHandler $handler A FragmentHandler instance
*/
public function __construct(HttpContentRenderer $renderer)
public function __construct(FragmentHandler $handler)
{
$this->renderer = $renderer;
$this->handler = $handler;
}

public function getFunctions()
{
return array(
'render' => new \Twig_Function_Method($this, 'render', array('is_safe' => array('html'))),
'render_*' => new \Twig_Function_Method($this, 'renderStrategy', array('is_safe' => array('html'))),
'render' => new \Twig_Function_Method($this, 'renderFragment', array('is_safe' => array('html'))),
'render_*' => new \Twig_Function_Method($this, 'renderFragmentStrategy', array('is_safe' => array('html'))),
'controller' => new \Twig_Function_Method($this, 'controller'),
);
}

/**
* Renders a URI.
* Renders a fragment.
*
* @param string $uri A URI
* @param array $options An array of options
*
* @return string The Response content
* @return string The fragment content
*
* @see Symfony\Component\HttpKernel\HttpContentRenderer::render()
* @see Symfony\Component\HttpKernel\Fragment\FragmentHandler::render()
*/
public function render($uri, $options = array())
public function renderFragment($uri, $options = array())
{
$options = $this->renderer->fixOptions($options);
$options = $this->handler->fixOptions($options);

$strategy = isset($options['strategy']) ? $options['strategy'] : 'default';
$strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
unset($options['strategy']);

return $this->renderer->render($uri, $strategy, $options);
return $this->handler->render($uri, $strategy, $options);
}

public function renderStrategy($strategy, $uri, $options = array())
/**
* Renders a fragment.
*
* @param string $strategy A strategy name
* @param string $uri A URI
* @param array $options An array of options
*
* @return string The fragment content
*
* @see Symfony\Component\HttpKernel\Fragment\FragmentHandler::render()
*/
public function renderFragmentStrategy($strategy, $uri, $options = array())
{
return $this->renderer->render($uri, $strategy, $options);
return $this->handler->render($uri, $strategy, $options);
}

public function controller($controller, $attributes = array(), $query = array())
Expand Down
Expand Up @@ -15,7 +15,7 @@
use Symfony\Bridge\Twig\Tests\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpContentRenderer;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;

class HttpKernelExtensionTest extends TestCase
{
Expand All @@ -33,21 +33,21 @@ protected function setUp()
/**
* @expectedException \Twig_Error_Runtime
*/
public function testRenderWithError()
public function testFragmentWithError()
{
$kernel = $this->getHttpContentRenderer($this->throwException(new \Exception('foo')));
$kernel = $this->getFragmentHandler($this->throwException(new \Exception('foo')));

$loader = new \Twig_Loader_Array(array('index' => '{{ render("foo") }}'));
$loader = new \Twig_Loader_Array(array('index' => '{{ fragment("foo") }}'));
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
$twig->addExtension(new HttpKernelExtension($kernel));

$this->renderTemplate($kernel);
}

protected function getHttpContentRenderer($return)
protected function getFragmentHandler($return)
{
$strategy = $this->getMock('Symfony\\Component\\HttpKernel\\RenderingStrategy\\RenderingStrategyInterface');
$strategy->expects($this->once())->method('getName')->will($this->returnValue('default'));
$strategy = $this->getMock('Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface');
$strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
$strategy->expects($this->once())->method('render')->will($return);

// simulate a master request
Expand All @@ -58,13 +58,13 @@ protected function getHttpContentRenderer($return)
->will($this->returnValue(Request::create('/')))
;

$renderer = new HttpContentRenderer(array($strategy));
$renderer = new FragmentHandler(array($strategy));
$renderer->onKernelRequest($event);

return $renderer;
}

protected function renderTemplate(HttpContentRenderer $renderer, $template = '{{ render("foo") }}')
protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
{
$loader = new \Twig_Loader_Array(array('index' => $template));
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Expand Up @@ -8,11 +8,11 @@ CHANGELOG
* deprecated `Symfony\Bundle\FrameworkBundle\HttpKernel::render()` and `Symfony\Bundle\FrameworkBundle\HttpKernel::forward()`
* deprecated the `Symfony\Bundle\FrameworkBundle\HttpKernel` class in favor of `Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel`
* added support for adding new HTTP content rendering strategies (like ESI and Hinclude)
in the DIC via the `kernel.content_renderer_strategy` tag
in the DIC via the `kernel.fragment_renderer` tag
* [BC BREAK] restricted the `Symfony\Bundle\FrameworkBundle\HttpKernel::render()` method to only accept URIs or ControllerReference instances
* `Symfony\Bundle\FrameworkBundle\HttpKernel::render()` method signature changed and the first argument
must now be a URI or a ControllerReference instance (the `generateInternalUri()` method was removed)
* The internal routes (`Resources/config/routing/internal.xml`) have been removed and replaced with a listener (`Symfony\Component\HttpKernel\EventListener\RouterProxyListener`)
* The internal routes (`Resources/config/routing/internal.xml`) have been removed and replaced with a listener (`Symfony\Component\HttpKernel\EventListener\FragmentListener`)
* The `render` method of the `actions` templating helper signature and arguments changed
* replaced Symfony\Bundle\FrameworkBundle\Controller\TraceableControllerResolver by Symfony\Component\HttpKernel\Controller\TraceableControllerResolver
* replaced Symfony\Component\HttpKernel\Debug\ContainerAwareTraceableEventDispatcher by Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher
Expand Down
Expand Up @@ -16,30 +16,30 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
* Adds services tagged kernel.content_renderer_strategy as HTTP content rendering strategies.
* Adds services tagged kernel.fragment_renderer as HTTP content rendering strategies.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class HttpRenderingStrategyPass implements CompilerPassInterface
class FragmentRendererPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (false === $container->hasDefinition('http_content_renderer')) {
if (false === $container->hasDefinition('fragment.handler')) {
return;
}

$definition = $container->getDefinition('http_content_renderer');
foreach (array_keys($container->findTaggedServiceIds('kernel.content_renderer_strategy')) as $id) {
$definition = $container->getDefinition('fragment.handler');
foreach (array_keys($container->findTaggedServiceIds('kernel.fragment_renderer')) as $id) {
// We must assume that the class value has been correctly filled, even if the service is created by a factory
$class = $container->getDefinition($id)->getClass();

$refClass = new \ReflectionClass($class);
$interface = 'Symfony\Component\HttpKernel\RenderingStrategy\RenderingStrategyInterface';
$interface = 'Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface';
if (!$refClass->implementsInterface($interface)) {
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
}

$definition->addMethodCall('addStrategy', array(new Reference($id)));
$definition->addMethodCall('addRenderer', array(new Reference($id)));
}
}
}
Expand Up @@ -73,7 +73,7 @@ public function getConfigTreeBuilder()

$this->addFormSection($rootNode);
$this->addEsiSection($rootNode);
$this->addRouterProxySection($rootNode);
$this->addFragmentsSection($rootNode);
$this->addProfilerSection($rootNode);
$this->addRouterSection($rootNode);
$this->addSessionSection($rootNode);
Expand Down Expand Up @@ -115,15 +115,15 @@ private function addEsiSection(ArrayNodeDefinition $rootNode)
;
}

private function addRouterProxySection(ArrayNodeDefinition $rootNode)
private function addFragmentsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('router_proxy')
->info('proxy configuration for the HTTP content renderer')
->arrayNode('fragments')
->info('fragments configuration')
->canBeEnabled()
->children()
->scalarNode('path')->defaultValue('/_proxy')->end()
->scalarNode('path')->defaultValue('/_fragment')->end()
->end()
->end()
->end()
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function load(array $configs, ContainerBuilder $container)

$loader->load('web.xml');
$loader->load('services.xml');
$loader->load('content_generator.xml');
$loader->load('fragment_renderer.xml');

// A translator must always be registered (as support is included by
// default in the Form component). If disabled, an identity translator
Expand Down Expand Up @@ -92,7 +92,7 @@ public function load(array $configs, ContainerBuilder $container)

$this->registerValidationConfiguration($config['validation'], $container, $loader);
$this->registerEsiConfiguration($config['esi'], $container, $loader);
$this->registerRouterProxyConfiguration($config['router_proxy'], $container, $loader);
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
$this->registerTranslatorConfiguration($config['translator'], $container);

Expand Down Expand Up @@ -166,9 +166,9 @@ private function registerFormConfiguration($config, ContainerBuilder $container,
/**
* Loads the ESI configuration.
*
* @param array $config A proxy configuration array
* @param array $config An ESI configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerEsiConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
Expand All @@ -180,20 +180,20 @@ private function registerEsiConfiguration(array $config, ContainerBuilder $conta
}

/**
* Loads the router proxy configuration.
* Loads the fragments configuration.
*
* @param array $config A proxy configuration array
* @param array $config A fragments configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerRouterProxyConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
private function registerFragmentsConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}

$loader->load('proxy.xml');
$container->setParameter('http_content_renderer.proxy_path', $config['path']);
$loader->load('fragment_listener.xml');
$container->setParameter('fragment.path', $config['path']);
}

/**
Expand Down
Expand Up @@ -9,19 +9,19 @@
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\RenderingStrategy;
namespace Symfony\Bundle\FrameworkBundle\Fragment;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\UriSigner;
use Symfony\Component\HttpKernel\RenderingStrategy\HIncludeRenderingStrategy;
use Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer;

/**
* Implements the Hinclude rendering strategy.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ContainerAwareHIncludeRenderingStrategy extends HIncludeRenderingStrategy
class ContainerAwareHIncludeFragmentRenderer extends HIncludeFragmentRenderer
{
private $container;

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Expand Up @@ -25,7 +25,7 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\HttpRenderingStrategyPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FragmentRendererPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Scope;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new AddCacheClearerPass());
$container->addCompilerPass(new TranslationExtractorPass());
$container->addCompilerPass(new TranslationDumperPass());
$container->addCompilerPass(new HttpRenderingStrategyPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);

if ($container->getParameter('kernel.debug')) {
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
Expand Up @@ -67,17 +67,17 @@ public function forward($controller, array $attributes = array(), array $query =
* @throws \RuntimeException
* @throws \Exception
*
* @deprecated in 2.2, will be removed in 2.3 (use Symfony\Component\HttpKernel\HttpContentRenderer::render() instead)
* @deprecated in 2.2, will be removed in 2.3 (use Symfony\Component\HttpKernel\FragmentRenderer::render() instead)
*/
public function render($uri, array $options = array())
{
trigger_error('render() is deprecated since version 2.2 and will be removed in 2.3. Use Symfony\Component\HttpKernel\HttpContentRenderer::render() instead.', E_USER_DEPRECATED);
trigger_error('render() is deprecated since version 2.2 and will be removed in 2.3. Use Symfony\Component\HttpKernel\FragmentRenderer::render() instead.', E_USER_DEPRECATED);

$options = $this->renderer->fixOptions($options);

$strategy = isset($options['strategy']) ? $options['strategy'] : 'default';
unset($options['strategy']);

$this->container->get('http_content_renderer')->render($uri, $strategy, $options);
$this->container->get('fragment.handler')->render($uri, $strategy, $options);
}
}

This file was deleted.

0 comments on commit c72e471

Please sign in to comment.