From c72e471c6554bc482c5d84c681a5015b74274660 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 31 Jan 2013 10:37:27 +0100 Subject: [PATCH] renamed some classes and Twig functions to more descriptive names (refs #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. --- .../Twig/Extension/HttpKernelExtension.php | 43 ++++++++----- .../Extension/HttpKernelExtensionTest.php | 18 +++--- .../Bundle/FrameworkBundle/CHANGELOG.md | 4 +- ...ategyPass.php => FragmentRendererPass.php} | 14 ++--- .../DependencyInjection/Configuration.php | 10 +-- .../FrameworkExtension.php | 20 +++--- ...ontainerAwareHIncludeFragmentRenderer.php} | 6 +- .../FrameworkBundle/FrameworkBundle.php | 4 +- .../Bundle/FrameworkBundle/HttpKernel.php | 6 +- .../Resources/config/content_generator.xml | 37 ----------- .../FrameworkBundle/Resources/config/esi.xml | 10 +-- .../{proxy.xml => fragment_listener.xml} | 6 +- .../Resources/config/fragment_renderer.xml | 36 +++++++++++ .../Resources/config/schema/symfony-1.0.xsd | 4 +- .../Resources/config/templating_php.xml | 2 +- .../Templating/Helper/ActionsHelper.php | 20 +++--- ...sTest.php => FragmentRendererPassTest.php} | 20 +++--- .../DependencyInjection/ConfigurationTest.php | 4 +- .../TwigBundle/Resources/config/twig.xml | 2 +- src/Symfony/Component/HttpKernel/CHANGELOG.md | 7 +-- .../Controller/ControllerReference.php | 4 +- ...ProxyListener.php => FragmentListener.php} | 21 ++++--- .../EsiFragmentRenderer.php} | 25 ++++---- .../FragmentHandler.php} | 59 +++++++++-------- .../FragmentRendererInterface.php} | 6 +- .../HIncludeFragmentRenderer.php} | 6 +- .../InlineFragmentRenderer.php} | 10 +-- .../RoutableFragmentRenderer.php} | 26 ++++---- ...tenerTest.php => FragmentListenerTest.php} | 24 +++---- .../EsiFragmentRendererTest.php} | 26 ++++---- .../FragmentHandlerTest.php} | 60 ++++++++---------- .../HIncludeFragmentRendererTest.php} | 22 +++---- .../InlineFragmentRendererTest.php} | 18 +++--- .../Fragment/RoutableFragmentRendererTest.php | 63 +++++++++++++++++++ .../ProxyAwareRenderingStrategyTest.php | 63 ------------------- 35 files changed, 354 insertions(+), 352 deletions(-) rename src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/{HttpRenderingStrategyPass.php => FragmentRendererPass.php} (69%) rename src/Symfony/Bundle/FrameworkBundle/{RenderingStrategy/ContainerAwareHIncludeRenderingStrategy.php => Fragment/ContainerAwareHIncludeFragmentRenderer.php} (83%) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Resources/config/content_generator.xml rename src/Symfony/Bundle/FrameworkBundle/Resources/config/{proxy.xml => fragment_listener.xml} (57%) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml rename src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/{HttpRenderingStrategyPassTest.php => FragmentRendererPassTest.php} (82%) rename src/Symfony/Component/HttpKernel/EventListener/{RouterProxyListener.php => FragmentListener.php} (81%) rename src/Symfony/Component/HttpKernel/{RenderingStrategy/EsiRenderingStrategy.php => Fragment/EsiFragmentRenderer.php} (68%) rename src/Symfony/Component/HttpKernel/{HttpContentRenderer.php => Fragment/FragmentHandler.php} (70%) rename src/Symfony/Component/HttpKernel/{RenderingStrategy/RenderingStrategyInterface.php => Fragment/FragmentRendererInterface.php} (87%) rename src/Symfony/Component/HttpKernel/{RenderingStrategy/HIncludeRenderingStrategy.php => Fragment/HIncludeFragmentRenderer.php} (93%) rename src/Symfony/Component/HttpKernel/{RenderingStrategy/DefaultRenderingStrategy.php => Fragment/InlineFragmentRenderer.php} (88%) rename src/Symfony/Component/HttpKernel/{RenderingStrategy/ProxyAwareRenderingStrategy.php => Fragment/RoutableFragmentRenderer.php} (55%) rename src/Symfony/Component/HttpKernel/Tests/EventListener/{RouterProxyListenerTest.php => FragmentListenerTest.php} (73%) rename src/Symfony/Component/HttpKernel/Tests/{RenderingStrategy/EsiRenderingStrategyTest.php => Fragment/EsiFragmentRendererTest.php} (53%) rename src/Symfony/Component/HttpKernel/Tests/{HttpContentRendererTest.php => Fragment/FragmentHandlerTest.php} (53%) rename src/Symfony/Component/HttpKernel/Tests/{RenderingStrategy/HIncludeRenderingStrategyTest.php => Fragment/HIncludeFragmentRendererTest.php} (67%) rename src/Symfony/Component/HttpKernel/Tests/{RenderingStrategy/DefaultRenderingStrategyTest.php => Fragment/InlineFragmentRendererTest.php} (80%) create mode 100644 src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php delete mode 100644 src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/ProxyAwareRenderingStrategyTest.php diff --git a/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php b/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php index cb18b5f6433b..ecdff56f5c16 100644 --- a/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php @@ -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; /** @@ -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()) diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php index f9c3f31d537f..1bc41f49eb1a 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php @@ -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 { @@ -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 @@ -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)); diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 5725d442c091..7d6321e81945 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -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 diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/HttpRenderingStrategyPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FragmentRendererPass.php similarity index 69% rename from src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/HttpRenderingStrategyPass.php rename to src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FragmentRendererPass.php index 3bb16f28c703..e3284ab45c24 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/HttpRenderingStrategyPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FragmentRendererPass.php @@ -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 */ -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))); } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 7faeac7ff586..557dc394149d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -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); @@ -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() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 9c04a3b284e5..7cff079e82b2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -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 @@ -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); @@ -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) { @@ -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']); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/RenderingStrategy/ContainerAwareHIncludeRenderingStrategy.php b/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php similarity index 83% rename from src/Symfony/Bundle/FrameworkBundle/RenderingStrategy/ContainerAwareHIncludeRenderingStrategy.php rename to src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php index c1afd188b3de..db54106358ef 100644 --- a/src/Symfony/Bundle/FrameworkBundle/RenderingStrategy/ContainerAwareHIncludeRenderingStrategy.php +++ b/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php @@ -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 */ -class ContainerAwareHIncludeRenderingStrategy extends HIncludeRenderingStrategy +class ContainerAwareHIncludeFragmentRenderer extends HIncludeFragmentRenderer { private $container; diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index c4caaea4e988..a255d120b9db 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -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; @@ -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); diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index 71a677cebeb0..79c6ea21071a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -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); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/content_generator.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/content_generator.xml deleted file mode 100644 index b9928df8c930..000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/content_generator.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - Symfony\Component\HttpKernel\HttpContentRenderer - Symfony\Component\HttpKernel\RenderingStrategy\DefaultRenderingStrategy - Symfony\Bundle\FrameworkBundle\RenderingStrategy\ContainerAwareHIncludeRenderingStrategy - - /_proxy - - - - - - - %kernel.debug% - - - - - - %http_content_renderer.proxy_path% - - - - - - - %http_content_renderer.strategy.hinclude.global_template% - %http_content_renderer.proxy_path% - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml index 8f29f55457b3..dd8e80107525 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml @@ -7,7 +7,7 @@ Symfony\Component\HttpKernel\HttpCache\Esi Symfony\Component\HttpKernel\EventListener\EsiListener - Symfony\Component\HttpKernel\RenderingStrategy\EsiRenderingStrategy + Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer @@ -18,11 +18,11 @@ - - + + - - %http_content_renderer.proxy_path% + + %fragment.path% diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/proxy.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_listener.xml similarity index 57% rename from src/Symfony/Bundle/FrameworkBundle/Resources/config/proxy.xml rename to src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_listener.xml index fca497721dfa..930ca17b0add 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/proxy.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_listener.xml @@ -5,14 +5,14 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Symfony\Component\HttpKernel\EventListener\RouterProxyListener + Symfony\Component\HttpKernel\EventListener\FragmentListener - + - %http_content_renderer.proxy_path% + %fragment.path% diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml new file mode 100644 index 000000000000..cbe3db3257b6 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml @@ -0,0 +1,36 @@ + + + + + + Symfony\Component\HttpKernel\Fragment\FragmentHandler + Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer + Symfony\Bundle\FrameworkBundle\Fragment\ContainerAwareHIncludeFragmentRenderer + + /_fragment + + + + + + + %kernel.debug% + + + + + + %fragment.path% + + + + + + + %fragment.renderer.hinclude.global_template% + %fragment.path% + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 14dcf9f8a59b..9ddf20305266 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -12,7 +12,7 @@ - + @@ -45,7 +45,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml index f93c7c7db4c2..9aadc8156b82 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml @@ -81,7 +81,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php index f07adb2ce205..730b963f45c4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper; use Symfony\Component\Templating\Helper\Helper; -use Symfony\Component\HttpKernel\HttpContentRenderer; +use Symfony\Component\HttpKernel\Fragment\FragmentHandler; use Symfony\Component\HttpKernel\Controller\ControllerReference; /** @@ -22,36 +22,36 @@ */ class ActionsHelper extends Helper { - 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; } /** - * Returns the Response content for a given URI. + * Returns the fragment content for a given URI. * * @param string $uri A URI * @param array $options An array of options * - * @return string + * @return string The fragment content * - * @see Symfony\Component\HttpKernel\HttpContentRenderer::render() + * @see Symfony\Component\HttpKernel\Fragment\FragmentHandler::render() */ public function render($uri, array $options = array()) { - $options = $this->renderer->fixOptions($options); + $options = $this->handler->fixOptions($options); $strategy = isset($options['strategy']) ? $options['strategy'] : 'default'; unset($options['strategy']); - return $this->renderer->render($uri, $strategy, $options); + return $this->handler->render($uri, $strategy, $options); } public function controller($controller, $attributes = array(), $query = array()) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/HttpRenderingStrategyPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FragmentRendererPassTest.php similarity index 82% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/HttpRenderingStrategyPassTest.php rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FragmentRendererPassTest.php index 4fe461fec4bf..ecc334deb65b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/HttpRenderingStrategyPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FragmentRendererPassTest.php @@ -15,12 +15,12 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\HttpRenderingStrategyPass; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FragmentRendererPass; -class HttpRenderingStrategyPassTest extends \PHPUnit_Framework_TestCase +class FragmentRendererPassTest extends \PHPUnit_Framework_TestCase { /** - * Tests that content rendering not implementing RenderingStrategyInterface + * Tests that content rendering not implementing FragmentRendererInterface * trigger an exception. * * @expectedException \InvalidArgumentException @@ -42,7 +42,7 @@ public function testContentRendererWithoutInterface() ->method('hasDefinition') ->will($this->returnValue(true)); - // We don't test kernel.content_renderer_strategy here + // We don't test kernel.fragment_renderer here $builder->expects($this->atLeastOnce()) ->method('findTaggedServiceIds') ->will($this->returnValue($services)); @@ -51,7 +51,7 @@ public function testContentRendererWithoutInterface() ->method('getDefinition') ->will($this->returnValue($definition)); - $pass = new HttpRenderingStrategyPass(); + $pass = new FragmentRendererPass(); $pass->process($builder); } @@ -65,20 +65,20 @@ public function testValidContentRenderer() $renderer ->expects($this->once()) ->method('addMethodCall') - ->with('addStrategy', array(new Reference('my_content_renderer'))) + ->with('addRenderer', array(new Reference('my_content_renderer'))) ; $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); $definition->expects($this->atLeastOnce()) ->method('getClass') - ->will($this->returnValue('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\RenderingStrategyService')); + ->will($this->returnValue('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\RendererService')); $builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); $builder->expects($this->any()) ->method('hasDefinition') ->will($this->returnValue(true)); - // We don't test kernel.content_renderer_strategy here + // We don't test kernel.fragment_renderer here $builder->expects($this->atLeastOnce()) ->method('findTaggedServiceIds') ->will($this->returnValue($services)); @@ -87,12 +87,12 @@ public function testValidContentRenderer() ->method('getDefinition') ->will($this->onConsecutiveCalls($renderer, $definition)); - $pass = new HttpRenderingStrategyPass(); + $pass = new FragmentRendererPass(); $pass->process($builder); } } -class RenderingStrategyService implements \Symfony\Component\HttpKernel\RenderingStrategy\RenderingStrategyInterface +class RendererService implements \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface { public function render($uri, Request $request = null, array $options = array()) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 7f40dffd49be..305f4e2dee2e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -98,9 +98,9 @@ protected static function getBundleDefaultConfig() 'field_name' => '_token', ), 'esi' => array('enabled' => false), - 'router_proxy' => array( + 'fragments' => array( 'enabled' => false, - 'path' => '/_proxy', + 'path' => '/_fragment', ), 'profiler' => array( 'enabled' => false, diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 06306578e902..6dbc001c0b8f 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -90,7 +90,7 @@ - + diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 0bb901ec39d8..d6f8886811c4 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -4,12 +4,11 @@ CHANGELOG 2.2.0 ----- - * added Symfony\Component\HttpKernel\EventListener\RouterProxyListener + * added Symfony\Component\HttpKernel\EventListener\FragmentListener * added Symfony\Component\HttpKernel\UriSigner - * added Symfony\Component\HttpKernel\HttpContentRenderer and rendering strategies (in Symfony\Component\HttpKernel\RenderingStrategy) - * added Symfony\Component\HttpKernel\EventListener\RouterProxyListener + * added Symfony\Component\HttpKernel\FragmentRenderer and rendering strategies (in Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface) * added Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel - * added ControllerReference to create reference of Controllers (used in the HttpContentRenderer class) + * added ControllerReference to create reference of Controllers (used in the FragmentRenderer class) * [BC BREAK] renamed TimeDataCollector::getTotalTime() to TimeDataCollector::getDuration() * updated the MemoryDataCollector to include the memory used in the diff --git a/src/Symfony/Component/HttpKernel/Controller/ControllerReference.php b/src/Symfony/Component/HttpKernel/Controller/ControllerReference.php index 905e89f5dc00..22d6cd320d0c 100644 --- a/src/Symfony/Component/HttpKernel/Controller/ControllerReference.php +++ b/src/Symfony/Component/HttpKernel/Controller/ControllerReference.php @@ -20,8 +20,8 @@ * * @author Fabien Potencier * - * @see Symfony\Component\HttpKernel\HttpContentRenderer - * @see Symfony\Component\HttpKernel\RenderingStrategy\RenderingStrategyInterface + * @see Symfony\Component\HttpKernel\FragmentRenderer + * @see Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface */ class ControllerReference { diff --git a/src/Symfony/Component/HttpKernel/EventListener/RouterProxyListener.php b/src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php similarity index 81% rename from src/Symfony/Component/HttpKernel/EventListener/RouterProxyListener.php rename to src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php index 3554361ae355..1a4d83b769cd 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/RouterProxyListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php @@ -20,32 +20,35 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** - * Proxies URIs when the current route name is "_proxy". + * Handles content fragments represented by special URIs. + * + * All URL paths starting with /_fragment are handled as + * content fragments by this listener. * * If the request does not come from a trusted IP, it throws an * AccessDeniedHttpException exception. * * @author Fabien Potencier */ -class RouterProxyListener implements EventSubscriberInterface +class FragmentListener implements EventSubscriberInterface { private $signer; - private $proxyPath; + private $fragmentPath; /** * Constructor. * - * @param UriSigner $signer A UriSigner instance - * @param string $proxyPath The path that triggers this listener + * @param UriSigner $signer A UriSigner instance + * @param string $fragmentPath The path that triggers this listener */ - public function __construct(UriSigner $signer, $proxyPath = '/_proxy') + public function __construct(UriSigner $signer, $fragmentPath = '/_fragment') { $this->signer = $signer; - $this->proxyPath = $proxyPath; + $this->fragmentPath = $fragmentPath; } /** - * Fixes request attributes when the route is '_proxy'. + * Fixes request attributes when the path is '/_fragment'. * * @param GetResponseEvent $event A GetResponseEvent instance * @@ -55,7 +58,7 @@ public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); - if ($this->proxyPath !== rawurldecode($request->getPathInfo())) { + if ($this->fragmentPath !== rawurldecode($request->getPathInfo())) { return; } diff --git a/src/Symfony/Component/HttpKernel/RenderingStrategy/EsiRenderingStrategy.php b/src/Symfony/Component/HttpKernel/Fragment/EsiFragmentRenderer.php similarity index 68% rename from src/Symfony/Component/HttpKernel/RenderingStrategy/EsiRenderingStrategy.php rename to src/Symfony/Component/HttpKernel/Fragment/EsiFragmentRenderer.php index 195066d00494..68b1a87da65c 100644 --- a/src/Symfony/Component/HttpKernel/RenderingStrategy/EsiRenderingStrategy.php +++ b/src/Symfony/Component/HttpKernel/Fragment/EsiFragmentRenderer.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\RenderingStrategy; +namespace Symfony\Component\HttpKernel\Fragment; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -21,32 +21,31 @@ * * @author Fabien Potencier */ -class EsiRenderingStrategy extends ProxyAwareRenderingStrategy +class EsiFragmentRenderer extends RoutableFragmentRenderer { private $esi; - private $defaultStrategy; + private $inlineStrategy; /** * Constructor. * * The "fallback" strategy when ESI is not available should always be an - * instance of DefaultRenderingStrategy (or a class you are using for the - * default strategy). + * instance of InlineFragmentRenderer. * - * @param Esi $esi An Esi instance - * @param RenderingStrategyInterface $defaultStrategy The default strategy to use when ESI is not supported + * @param Esi $esi An Esi instance + * @param InlineFragmentRenderer $inlineStrategy The inline strategy to use when ESI is not supported */ - public function __construct(Esi $esi, RenderingStrategyInterface $defaultStrategy) + public function __construct(Esi $esi, InlineFragmentRenderer $inlineStrategy) { $this->esi = $esi; - $this->defaultStrategy = $defaultStrategy; + $this->inlineStrategy = $inlineStrategy; } /** * {@inheritdoc} * * Note that if the current Request has no ESI capability, this method - * falls back to use the default rendering strategy. + * falls back to use the inline rendering strategy. * * Additional available options: * @@ -58,16 +57,16 @@ public function __construct(Esi $esi, RenderingStrategyInterface $defaultStrateg public function render($uri, Request $request, array $options = array()) { if (!$this->esi->hasSurrogateEsiCapability($request)) { - return $this->defaultStrategy->render($uri, $request, $options); + return $this->inlineStrategy->render($uri, $request, $options); } if ($uri instanceof ControllerReference) { - $uri = $this->generateProxyUri($uri, $request); + $uri = $this->generateFragmentUri($uri, $request); } $alt = isset($options['alt']) ? $options['alt'] : null; if ($alt instanceof ControllerReference) { - $alt = $this->generateProxyUri($alt, $request); + $alt = $this->generateFragmentUri($alt, $request); } $tag = $this->esi->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : ''); diff --git a/src/Symfony/Component/HttpKernel/HttpContentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php similarity index 70% rename from src/Symfony/Component/HttpKernel/HttpContentRenderer.php rename to src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php index d476bb2dba09..18f7b9899350 100644 --- a/src/Symfony/Component/HttpKernel/HttpContentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php @@ -9,58 +9,57 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel; +namespace Symfony\Component\HttpKernel\Fragment; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\RenderingStrategy\RenderingStrategyInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** - * Renders a URI using different strategies. + * Renders a URI that represents a resource fragment. * - * This class handles sub-requests. The response content from the sub-request - * is then embedded into a master request. The handling of the sub-request - * is managed by rendering strategies. + * This class handles the rendering of resource fragments that are included into + * a main resource. The handling of the rendering is managed by specialized renderers. * * @author Fabien Potencier * - * @see RenderingStrategyInterface + * @see FragmentRendererInterface */ -class HttpContentRenderer implements EventSubscriberInterface +class FragmentHandler implements EventSubscriberInterface { private $debug; - private $strategies; + private $renderers; private $requests; /** * Constructor. * - * @param RenderingStrategyInterface[] $strategies An array of RenderingStrategyInterface instances - * @param Boolean $debug Whether the debug mode is enabled or not + * @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances + * @param Boolean $debug Whether the debug mode is enabled or not */ - public function __construct(array $strategies = array(), $debug = false) + public function __construct(array $renderers = array(), $debug = false) { - $this->strategies = array(); - foreach ($strategies as $strategy) { - $this->addStrategy($strategy); + $this->renderers = array(); + foreach ($renderers as $renderer) { + $this->addRenderer($renderer); } $this->debug = $debug; $this->requests = array(); } /** - * Adds a rendering strategy. + * Adds a renderer. * - * @param RenderingStrategyInterface $strategy A RenderingStrategyInterface instance + * @param FragmentRendererInterface $strategy A FragmentRendererInterface instance */ - public function addStrategy(RenderingStrategyInterface $strategy) + public function addRenderer(FragmentRendererInterface $renderer) { - $this->strategies[$strategy->getName()] = $strategy; + $this->renderers[$renderer->getName()] = $renderer; } /** @@ -91,25 +90,25 @@ public function onKernelResponse(FilterResponseEvent $event) * * ignore_errors: true to return an empty string in case of an error * * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance - * @param string $strategy The strategy to use for the rendering + * @param string $renderer The renderer name * @param array $options An array of options * * @return string|null The Response content or null when the Response is streamed * - * @throws \InvalidArgumentException when the strategy does not exist + * @throws \InvalidArgumentException when the renderer does not exist * @throws \RuntimeException when the Response is not successful */ - public function render($uri, $strategy = 'default', array $options = array()) + public function render($uri, $renderer = 'inline', array $options = array()) { if (!isset($options['ignore_errors'])) { $options['ignore_errors'] = !$this->debug; } - if (!isset($this->strategies[$strategy])) { - throw new \InvalidArgumentException(sprintf('The "%s" rendering strategy does not exist.', $strategy)); + if (!isset($this->renderers[$renderer])) { + throw new \InvalidArgumentException(sprintf('The "%s" renderer does not exist.', $renderer)); } - return $this->deliver($this->strategies[$strategy]->render($uri, $this->requests[0], $options)); + return $this->deliver($this->renderers[$renderer]->render($uri, $this->requests[0], $options)); } /** @@ -148,9 +147,9 @@ public static function getSubscribedEvents() // to be removed in 2.3 public function fixOptions(array $options) { - // support for the standalone option is @deprecated in 2.2 and replaced with the strategy option + // support for the standalone option is @deprecated in 2.2 and replaced with the renderer option if (isset($options['standalone'])) { - trigger_error('The "standalone" option is deprecated in version 2.2 and replaced with the "strategy" option.', E_USER_DEPRECATED); + trigger_error('The "standalone" option is deprecated in version 2.2 and replaced with the "renderer" option.', E_USER_DEPRECATED); // support for the true value is @deprecated in 2.2, will be removed in 2.3 if (true === $options['standalone']) { @@ -158,16 +157,16 @@ public function fixOptions(array $options) $options['standalone'] = 'esi'; } elseif (false === $options['standalone']) { - trigger_error('The "false" value for the "standalone" option is deprecated in version 2.2 and replaced with the "default" value.', E_USER_DEPRECATED); + trigger_error('The "false" value for the "standalone" option is deprecated in version 2.2 and replaced with the "inline" value.', E_USER_DEPRECATED); - $options['standalone'] = 'default'; + $options['standalone'] = 'inline'; } elseif ('js' === $options['standalone']) { trigger_error('The "js" value for the "standalone" option is deprecated in version 2.2 and replaced with the "hinclude" value.', E_USER_DEPRECATED); $options['standalone'] = 'hinclude'; } - $options['strategy'] = $options['standalone']; + $options['renderer'] = $options['standalone']; unset($options['standalone']); } diff --git a/src/Symfony/Component/HttpKernel/RenderingStrategy/RenderingStrategyInterface.php b/src/Symfony/Component/HttpKernel/Fragment/FragmentRendererInterface.php similarity index 87% rename from src/Symfony/Component/HttpKernel/RenderingStrategy/RenderingStrategyInterface.php rename to src/Symfony/Component/HttpKernel/Fragment/FragmentRendererInterface.php index b4f8b8e50b40..a758d2c58200 100644 --- a/src/Symfony/Component/HttpKernel/RenderingStrategy/RenderingStrategyInterface.php +++ b/src/Symfony/Component/HttpKernel/Fragment/FragmentRendererInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\RenderingStrategy; +namespace Symfony\Component\HttpKernel\Fragment; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ControllerReference; @@ -19,9 +19,9 @@ * * @author Fabien Potencier * - * @see Symfony\Component\HttpKernel\HttpContentRenderer + * @see Symfony\Component\HttpKernel\FragmentRenderer */ -interface RenderingStrategyInterface +interface FragmentRendererInterface { /** * Renders a URI and returns the Response content. diff --git a/src/Symfony/Component/HttpKernel/RenderingStrategy/HIncludeRenderingStrategy.php b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php similarity index 93% rename from src/Symfony/Component/HttpKernel/RenderingStrategy/HIncludeRenderingStrategy.php rename to src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php index dd9f2d21fe0a..affb13799c71 100644 --- a/src/Symfony/Component/HttpKernel/RenderingStrategy/HIncludeRenderingStrategy.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\RenderingStrategy; +namespace Symfony\Component\HttpKernel\Fragment; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -22,7 +22,7 @@ * * @author Fabien Potencier */ -class HIncludeRenderingStrategy extends ProxyAwareRenderingStrategy +class HIncludeFragmentRenderer extends RoutableFragmentRenderer { protected $templating; @@ -61,7 +61,7 @@ public function render($uri, Request $request, array $options = array()) throw new \LogicException('You must use a proper URI when using the Hinclude rendering strategy or set a URL signer.'); } - $uri = $this->signer->sign($this->generateProxyUri($uri, $request)); + $uri = $this->signer->sign($this->generateFragmentUri($uri, $request)); } $template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate; diff --git a/src/Symfony/Component/HttpKernel/RenderingStrategy/DefaultRenderingStrategy.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php similarity index 88% rename from src/Symfony/Component/HttpKernel/RenderingStrategy/DefaultRenderingStrategy.php rename to src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php index 5a3427e05e3c..54655dc44a97 100644 --- a/src/Symfony/Component/HttpKernel/RenderingStrategy/DefaultRenderingStrategy.php +++ b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\RenderingStrategy; +namespace Symfony\Component\HttpKernel\Fragment; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -17,11 +17,11 @@ use Symfony\Component\HttpKernel\Controller\ControllerReference; /** - * Implements the default rendering strategy where the Request is rendered by the current HTTP kernel. + * Implements the inline rendering strategy where the Request is rendered by the current HTTP kernel. * * @author Fabien Potencier */ -class DefaultRenderingStrategy extends ProxyAwareRenderingStrategy +class InlineFragmentRenderer extends RoutableFragmentRenderer { private $kernel; @@ -45,7 +45,7 @@ public function __construct(HttpKernelInterface $kernel) public function render($uri, Request $request, array $options = array()) { if ($uri instanceof ControllerReference) { - $uri = $this->generateProxyUri($uri, $request); + $uri = $this->generateFragmentUri($uri, $request); } $subRequest = $this->createSubRequest($uri, $request); @@ -95,6 +95,6 @@ protected function createSubRequest($uri, Request $request) */ public function getName() { - return 'default'; + return 'inline'; } } diff --git a/src/Symfony/Component/HttpKernel/RenderingStrategy/ProxyAwareRenderingStrategy.php b/src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php similarity index 55% rename from src/Symfony/Component/HttpKernel/RenderingStrategy/ProxyAwareRenderingStrategy.php rename to src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php index 3c735efdeefe..879a0bb7ac5e 100644 --- a/src/Symfony/Component/HttpKernel/RenderingStrategy/ProxyAwareRenderingStrategy.php +++ b/src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php @@ -9,42 +9,42 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\RenderingStrategy; +namespace Symfony\Component\HttpKernel\Fragment; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\EventListener\RouterProxyListener; +use Symfony\Component\HttpKernel\EventListener\FragmentListener; /** - * Adds the possibility to generate a proxy URI for a given Controller. + * Adds the possibility to generate a fragment URI for a given Controller. * * @author Fabien Potencier */ -abstract class ProxyAwareRenderingStrategy implements RenderingStrategyInterface +abstract class RoutableFragmentRenderer implements FragmentRendererInterface { - private $proxyPath = '/_proxy'; + private $fragmentPath = '/_fragment'; /** - * Sets the proxy path that triggers the proxy listener + * Sets the fragment path that triggers the fragment listener. * * @param string $path The path * - * @see RouterProxyListener + * @see FragmentListener */ - public function setProxyPath($path) + public function setFragmentPath($path) { - $this->proxyPath = $path; + $this->fragmentPath = $path; } /** - * Generates a proxy URI for a given controller. + * Generates a fragment URI for a given controller. * * @param ControllerReference $reference A ControllerReference instance * @param Request $request A Request instance * - * @return string A proxy URI + * @return string A fragment URI */ - protected function generateProxyUri(ControllerReference $reference, Request $request) + protected function generateFragmentUri(ControllerReference $reference, Request $request) { if (!isset($reference->attributes['_format'])) { $reference->attributes['_format'] = $request->getRequestFormat(); @@ -54,6 +54,6 @@ protected function generateProxyUri(ControllerReference $reference, Request $req $reference->query['_path'] = http_build_query($reference->attributes, '', '&'); - return $request->getUriForPath($this->proxyPath.'?'.http_build_query($reference->query, '', '&')); + return $request->getUriForPath($this->fragmentPath.'?'.http_build_query($reference->query, '', '&')); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterProxyListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php similarity index 73% rename from src/Symfony/Component/HttpKernel/Tests/EventListener/RouterProxyListenerTest.php rename to src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php index f4a3356f6caa..153d8a44ff9c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterProxyListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php @@ -11,13 +11,13 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; -use Symfony\Component\HttpKernel\EventListener\RouterProxyListener; +use Symfony\Component\HttpKernel\EventListener\FragmentListener; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\UriSigner; -class RouterProxyListenerTest extends \PHPUnit_Framework_TestCase +class FragmentListenerTest extends \PHPUnit_Framework_TestCase { protected function setUp() { @@ -26,11 +26,11 @@ protected function setUp() } } - public function testOnlyTriggeredOnProxyRoute() + public function testOnlyTriggeredOnFragmentRoute() { $request = Request::create('http://example.com/foo?_path=foo%3Dbar%26_controller%3Dfoo'); - $listener = new RouterProxyListener(new UriSigner('foo')); + $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request); $expected = $request->attributes->all(); @@ -46,9 +46,9 @@ public function testOnlyTriggeredOnProxyRoute() */ public function testAccessDeniedWithNonSafeMethods() { - $request = Request::create('http://example.com/_proxy', 'POST'); + $request = Request::create('http://example.com/_fragment', 'POST'); - $listener = new RouterProxyListener(new UriSigner('foo')); + $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request); $listener->onKernelRequest($event); @@ -59,9 +59,9 @@ public function testAccessDeniedWithNonSafeMethods() */ public function testAccessDeniedWithNonLocalIps() { - $request = Request::create('http://example.com/_proxy', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); + $request = Request::create('http://example.com/_fragment', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); - $listener = new RouterProxyListener(new UriSigner('foo')); + $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request); $listener->onKernelRequest($event); @@ -72,9 +72,9 @@ public function testAccessDeniedWithNonLocalIps() */ public function testAccessDeniedWithWrongSignature() { - $request = Request::create('http://example.com/_proxy', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); + $request = Request::create('http://example.com/_fragment', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); - $listener = new RouterProxyListener(new UriSigner('foo')); + $listener = new FragmentListener(new UriSigner('foo')); $event = $this->createGetResponseEvent($request); $listener->onKernelRequest($event); @@ -83,9 +83,9 @@ public function testAccessDeniedWithWrongSignature() public function testWithSignature() { $signer = new UriSigner('foo'); - $request = Request::create($signer->sign('http://example.com/_proxy?_path=foo%3Dbar%26_controller%3Dfoo'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); + $request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1')); - $listener = new RouterProxyListener($signer); + $listener = new FragmentListener($signer); $event = $this->createGetResponseEvent($request); $listener->onKernelRequest($event); diff --git a/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/EsiRenderingStrategyTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php similarity index 53% rename from src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/EsiRenderingStrategyTest.php rename to src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php index 99c51926e43f..34e68a743600 100644 --- a/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/EsiRenderingStrategyTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\Tests\RenderingStrategy; +namespace Symfony\Component\HttpKernel\Tests\Fragment\FragmentRenderer; use Symfony\Component\HttpKernel\Controller\ControllerReference; -use Symfony\Component\HttpKernel\RenderingStrategy\EsiRenderingStrategy; +use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer; use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpFoundation\Request; -class EsiRenderingStrategyTest extends \PHPUnit_Framework_TestCase +class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase { protected function setUp() { @@ -25,21 +25,21 @@ protected function setUp() } } - public function testRenderFallbackToDefaultStrategyIfNoRequest() + public function testRenderFallbackToInlineStrategyIfNoRequest() { - $strategy = new EsiRenderingStrategy(new Esi(), $this->getDefaultStrategy(true)); + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true)); $strategy->render('/', Request::create('/')); } - public function testRenderFallbackToDefaultStrategyIfEsiNotSupported() + public function testRenderFallbackToInlineStrategyIfEsiNotSupported() { - $strategy = new EsiRenderingStrategy(new Esi(), $this->getDefaultStrategy(true)); + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true)); $strategy->render('/', Request::create('/')); } public function testRender() { - $strategy = new EsiRenderingStrategy(new Esi(), $this->getDefaultStrategy()); + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); $request = Request::create('/'); $request->headers->set('Surrogate-Capability', 'ESI/1.0'); @@ -47,17 +47,17 @@ public function testRender() $this->assertEquals('', $strategy->render('/', $request)->getContent()); $this->assertEquals("\n", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent()); $this->assertEquals('', $strategy->render('/', $request, array('alt' => 'foo'))->getContent()); - $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent()); + $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent()); } - private function getDefaultStrategy($called = false) + private function getInlineStrategy($called = false) { - $default = $this->getMockBuilder('Symfony\Component\HttpKernel\RenderingStrategy\DefaultRenderingStrategy')->disableOriginalConstructor()->getMock(); + $inline = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer')->disableOriginalConstructor()->getMock(); if ($called) { - $default->expects($this->once())->method('render'); + $inline->expects($this->once())->method('render'); } - return $default; + return $inline; } } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpContentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php similarity index 53% rename from src/Symfony/Component/HttpKernel/Tests/HttpContentRendererTest.php rename to src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php index 38305c93d03d..9671381a40da 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpContentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\Tests; +namespace Symfony\Component\HttpKernel\Tests\Fragment; -use Symfony\Component\HttpKernel\HttpContentRenderer; +use Symfony\Component\HttpKernel\Fragment\FragmentHandler; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -class HttpContentRendererTest extends \PHPUnit_Framework_TestCase +class FragmentHandlerTest extends \PHPUnit_Framework_TestCase { protected function setUp() { @@ -27,21 +27,20 @@ protected function setUp() /** * @expectedException \InvalidArgumentException */ - public function testRenderWhenStrategyDoesNotExist() + public function testRenderWhenRendererDoesNotExist() { - $renderer = new HttpContentRenderer(); - $renderer->render('/', 'foo'); + $handler = new FragmentHandler(); + $handler->render('/', 'foo'); } /** * @expectedException InvalidArgumentException */ - public function testRenderWithUnknownStrategy() + public function testRenderWithUnknownRenderer() { - $strategy = $this->getStrategy($this->returnValue(new Response('foo'))); - $renderer = $this->getRenderer($strategy); + $handler = $this->getHandler($this->returnValue(new Response('foo'))); - $renderer->render('/', 'bar'); + $handler->render('/', 'bar'); } /** @@ -50,18 +49,16 @@ public function testRenderWithUnknownStrategy() */ public function testDeliverWithUnsuccessfulResponse() { - $strategy = $this->getStrategy($this->returnValue(new Response('foo', 404))); - $renderer = $this->getRenderer($strategy); + $handler = $this->getHandler($this->returnValue(new Response('foo', 404))); - $renderer->render('/', 'foo'); + $handler->render('/', 'foo'); } public function testRender() { - $strategy = $this->getStrategy($this->returnValue(new Response('foo')), array('/', Request::create('/'), array('foo' => 'foo', 'ignore_errors' => true))); - $renderer = $this->getRenderer($strategy); + $handler = $this->getHandler($this->returnValue(new Response('foo')), array('/', Request::create('/'), array('foo' => 'foo', 'ignore_errors' => true))); - $this->assertEquals('foo', $renderer->render('/', 'foo', array('foo' => 'foo'))); + $this->assertEquals('foo', $handler->render('/', 'foo', array('foo' => 'foo'))); } /** @@ -69,31 +66,31 @@ public function testRender() */ public function testFixOptions($expected, $options) { - $renderer = new HttpContentRenderer(); + $handler = new FragmentHandler(); set_error_handler(function ($errorNumber, $message, $file, $line, $context) { return $errorNumber & E_USER_DEPRECATED; }); - $this->assertEquals($expected, $renderer->fixOptions($options)); + $this->assertEquals($expected, $handler->fixOptions($options)); restore_error_handler(); } public function getFixOptionsData() { return array( - array(array('strategy' => 'esi'), array('standalone' => true)), - array(array('strategy' => 'esi'), array('standalone' => 'esi')), - array(array('strategy' => 'hinclude'), array('standalone' => 'js')), + array(array('renderer' => 'esi'), array('standalone' => true)), + array(array('renderer' => 'esi'), array('standalone' => 'esi')), + array(array('renderer' => 'hinclude'), array('standalone' => 'js')), ); } - protected function getStrategy($returnValue, $arguments = array()) + protected function getHandler($returnValue, $arguments = array()) { - $strategy = $this->getMock('Symfony\Component\HttpKernel\RenderingStrategy\RenderingStrategyInterface'); - $strategy + $renderer = $this->getMock('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface'); + $renderer ->expects($this->any()) ->method('getName') ->will($this->returnValue('foo')) ; - $e = $strategy + $e = $renderer ->expects($this->any()) ->method('render') ->will($returnValue) @@ -103,13 +100,8 @@ protected function getStrategy($returnValue, $arguments = array()) call_user_func_array(array($e, 'with'), $arguments); } - return $strategy; - } - - protected function getRenderer($strategy) - { - $renderer = new HttpContentRenderer(); - $renderer->addStrategy($strategy); + $handler = new FragmentHandler(); + $handler->addRenderer($renderer); $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); $event @@ -117,8 +109,8 @@ protected function getRenderer($strategy) ->method('getRequest') ->will($this->returnValue(Request::create('/'))) ; - $renderer->onKernelRequest($event); + $handler->onKernelRequest($event); - return $renderer; + return $handler; } } diff --git a/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/HIncludeRenderingStrategyTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php similarity index 67% rename from src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/HIncludeRenderingStrategyTest.php rename to src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php index 7a5158d3ea43..76fd720a4527 100644 --- a/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/HIncludeRenderingStrategyTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\Tests\RenderingStrategy; +namespace Symfony\Component\HttpKernel\Fragment\Tests\FragmentRenderer; use Symfony\Component\HttpKernel\Controller\ControllerReference; -use Symfony\Component\HttpKernel\RenderingStrategy\HIncludeRenderingStrategy; +use Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer; use Symfony\Component\HttpKernel\UriSigner; use Symfony\Component\HttpFoundation\Request; -class HIncludeRenderingStrategyTest extends \PHPUnit_Framework_TestCase +class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase { protected function setUp() { @@ -30,38 +30,38 @@ protected function setUp() */ public function testRenderExceptionWhenControllerAndNoSigner() { - $strategy = new HIncludeRenderingStrategy(); + $strategy = new HIncludeFragmentRenderer(); $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/')); } public function testRenderWithControllerAndSigner() { - $strategy = new HIncludeRenderingStrategy(null, new UriSigner('foo')); + $strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo')); - $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent()); + $this->assertEquals('', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent()); } public function testRenderWithUri() { - $strategy = new HIncludeRenderingStrategy(); + $strategy = new HIncludeFragmentRenderer(); $this->assertEquals('', $strategy->render('/foo', Request::create('/'))->getContent()); - $strategy = new HIncludeRenderingStrategy(null, new UriSigner('foo')); + $strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo')); $this->assertEquals('', $strategy->render('/foo', Request::create('/'))->getContent()); } public function testRenderWhithDefault() { // only default - $strategy = new HIncludeRenderingStrategy(); + $strategy = new HIncludeFragmentRenderer(); $this->assertEquals('default', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent()); // only global default - $strategy = new HIncludeRenderingStrategy(null, null, 'global_default'); + $strategy = new HIncludeFragmentRenderer(null, null, 'global_default'); $this->assertEquals('global_default', $strategy->render('/foo', Request::create('/'), array())->getContent()); // global default and default - $strategy = new HIncludeRenderingStrategy(null, null, 'global_default'); + $strategy = new HIncludeFragmentRenderer(null, null, 'global_default'); $this->assertEquals('default', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent()); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/DefaultRenderingStrategyTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php similarity index 80% rename from src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/DefaultRenderingStrategyTest.php rename to src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php index 5d1d4c92d6e3..2ae969fee771 100644 --- a/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/DefaultRenderingStrategyTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php @@ -9,16 +9,16 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpKernel\Tests\RenderingStrategy; +namespace Symfony\Component\HttpKernel\Fragment\Tests\FragmentRenderer; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\HttpKernel; -use Symfony\Component\HttpKernel\RenderingStrategy\DefaultRenderingStrategy; +use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\EventDispatcher\EventDispatcher; -class DefaultRenderingStrategyTest extends \PHPUnit_Framework_TestCase +class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase { protected function setUp() { @@ -33,14 +33,14 @@ protected function setUp() public function testRender() { - $strategy = new DefaultRenderingStrategy($this->getKernel($this->returnValue(new Response('foo')))); + $strategy = new InlineFragmentRenderer($this->getKernel($this->returnValue(new Response('foo')))); $this->assertEquals('foo', $strategy->render('/', Request::create('/'))->getContent()); } public function testRenderWithControllerReference() { - $strategy = new DefaultRenderingStrategy($this->getKernel($this->returnValue(new Response('foo')))); + $strategy = new InlineFragmentRenderer($this->getKernel($this->returnValue(new Response('foo')))); $this->assertEquals('foo', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent()); } @@ -50,21 +50,21 @@ public function testRenderWithControllerReference() */ public function testRenderExceptionNoIgnoreErrors() { - $strategy = new DefaultRenderingStrategy($this->getKernel($this->throwException(new \RuntimeException('foo')))); + $strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo')))); $this->assertEquals('foo', $strategy->render('/', Request::create('/'))->getContent()); } public function testRenderExceptionIgnoreErrors() { - $strategy = new DefaultRenderingStrategy($this->getKernel($this->throwException(new \RuntimeException('foo')))); + $strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo')))); $this->assertEmpty($strategy->render('/', Request::create('/'), array('ignore_errors' => true))->getContent()); } public function testRenderExceptionIgnoreErrorsWithAlt() { - $strategy = new DefaultRenderingStrategy($this->getKernel($this->onConsecutiveCalls( + $strategy = new InlineFragmentRenderer($this->getKernel($this->onConsecutiveCalls( $this->throwException(new \RuntimeException('foo')), $this->returnValue(new Response('bar')) ))); @@ -103,7 +103,7 @@ public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() ; $kernel = new HttpKernel(new EventDispatcher(), $resolver); - $renderer = new DefaultRenderingStrategy($kernel); + $renderer = new InlineFragmentRenderer($kernel); // simulate a main request with output buffering ob_start(); diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php new file mode 100644 index 000000000000..2106f9de753e --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Fragment\Tests\FragmentRenderer; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer; + +class RoutableFragmentRendererTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider getGenerateFragmentUriData + */ + public function testGenerateFragmentUri($uri, $controller) + { + $this->assertEquals($uri, $this->getRenderer()->doGenerateFragmentUri($controller, Request::create('/'))); + } + + public function getGenerateFragmentUriData() + { + return array( + array('http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())), + array('http://localhost/_fragment?_path=_format%3Dxml%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())), + array('http://localhost/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())), + array('http://localhost/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))), + array('http://localhost/_fragment?foo=foo&_path=_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))), + ); + } + + public function testGenerateFragmentUriWithARequest() + { + $request = Request::create('/'); + $request->attributes->set('_format', 'json'); + $controller = new ControllerReference('controller', array(), array()); + + $this->assertEquals('http://localhost/_fragment?_path=_format%3Djson%26_controller%3Dcontroller', $this->getRenderer()->doGenerateFragmentUri($controller, $request)); + } + + private function getRenderer() + { + return new Renderer(); + } +} + +class Renderer extends RoutableFragmentRenderer +{ + public function render($uri, Request $request, array $options = array()) {} + public function getName() {} + + public function doGenerateFragmentUri(ControllerReference $reference, Request $request) + { + return parent::generateFragmentUri($reference, $request); + } +} diff --git a/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/ProxyAwareRenderingStrategyTest.php b/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/ProxyAwareRenderingStrategyTest.php deleted file mode 100644 index 51e2340117cb..000000000000 --- a/src/Symfony/Component/HttpKernel/Tests/RenderingStrategy/ProxyAwareRenderingStrategyTest.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\Tests\RenderingStrategy; - -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Controller\ControllerReference; -use Symfony\Component\HttpKernel\RenderingStrategy\ProxyAwareRenderingStrategy; - -class ProxyAwareRenderingStrategyTest extends \PHPUnit_Framework_TestCase -{ - /** - * @dataProvider getGenerateProxyUriData - */ - public function testGenerateProxyUri($uri, $controller) - { - $this->assertEquals($uri, $this->getStrategy()->doGenerateProxyUri($controller, Request::create('/'))); - } - - public function getGenerateProxyUriData() - { - return array( - array('http://localhost/_proxy?_path=_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())), - array('http://localhost/_proxy?_path=_format%3Dxml%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())), - array('http://localhost/_proxy?_path=foo%3Dfoo%26_format%3Djson%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())), - array('http://localhost/_proxy?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))), - array('http://localhost/_proxy?foo=foo&_path=_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))), - ); - } - - public function testGenerateProxyUriWithARequest() - { - $request = Request::create('/'); - $request->attributes->set('_format', 'json'); - $controller = new ControllerReference('controller', array(), array()); - - $this->assertEquals('http://localhost/_proxy?_path=_format%3Djson%26_controller%3Dcontroller', $this->getStrategy()->doGenerateProxyUri($controller, $request)); - } - - private function getStrategy() - { - return new Strategy(); - } -} - -class Strategy extends ProxyAwareRenderingStrategy -{ - public function render($uri, Request $request, array $options = array()) {} - public function getName() {} - - public function doGenerateProxyUri(ControllerReference $reference, Request $request) - { - return parent::generateProxyUri($reference, $request); - } -}