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.
This commit is contained in:
parent
c85ec8b14a
commit
c72e471c65
@ -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 @@ use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||
*/
|
||||
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())
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
|
||||
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 @@ class HttpKernelExtensionTest extends TestCase
|
||||
/**
|
||||
* @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 @@ class HttpKernelExtensionTest extends TestCase
|
||||
->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));
|
||||
|
@ -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
|
||||
|
@ -16,30 +16,30 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
@ -73,7 +73,7 @@ class Configuration implements ConfigurationInterface
|
||||
|
||||
$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 @@ class Configuration implements ConfigurationInterface
|
||||
;
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -41,7 +41,7 @@ class FrameworkExtension extends Extension
|
||||
|
||||
$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 @@ class FrameworkExtension extends Extension
|
||||
|
||||
$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 @@ class FrameworkExtension extends Extension
|
||||
/**
|
||||
* 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 @@ class FrameworkExtension extends Extension
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -25,7 +25,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilder
|
||||
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 @@ class FrameworkBundle extends Bundle
|
||||
$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);
|
||||
|
@ -67,17 +67,17 @@ class HttpKernel extends ContainerAwareHttpKernel
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="http_content_renderer.class">Symfony\Component\HttpKernel\HttpContentRenderer</parameter>
|
||||
<parameter key="http_content_renderer.strategy.default.class">Symfony\Component\HttpKernel\RenderingStrategy\DefaultRenderingStrategy</parameter>
|
||||
<parameter key="http_content_renderer.strategy.hinclude.class">Symfony\Bundle\FrameworkBundle\RenderingStrategy\ContainerAwareHIncludeRenderingStrategy</parameter>
|
||||
<parameter key="http_content_renderer.strategy.hinclude.global_template"></parameter>
|
||||
<parameter key="http_content_renderer.proxy_path">/_proxy</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="http_content_renderer" class="%http_content_renderer.class%">
|
||||
<tag name="kernel.event_subscriber" />
|
||||
<argument type="collection" />
|
||||
<argument>%kernel.debug%</argument>
|
||||
</service>
|
||||
|
||||
<service id="http_content_renderer.strategy.default" class="%http_content_renderer.strategy.default.class%">
|
||||
<tag name="kernel.content_renderer_strategy" />
|
||||
<argument type="service" id="http_kernel" />
|
||||
<call method="setProxyPath"><argument>%http_content_renderer.proxy_path%</argument></call>
|
||||
</service>
|
||||
|
||||
<service id="http_content_renderer.strategy.hinclude" class="%http_content_renderer.strategy.hinclude.class%">
|
||||
<tag name="kernel.content_renderer_strategy" />
|
||||
<argument type="service" id="service_container" />
|
||||
<argument type="service" id="uri_signer" />
|
||||
<argument>%http_content_renderer.strategy.hinclude.global_template%</argument>
|
||||
<call method="setProxyPath"><argument>%http_content_renderer.proxy_path%</argument></call>
|
||||
</service>
|
||||
|
||||
</services>
|
||||
</container>
|
@ -7,7 +7,7 @@
|
||||
<parameters>
|
||||
<parameter key="esi.class">Symfony\Component\HttpKernel\HttpCache\Esi</parameter>
|
||||
<parameter key="esi_listener.class">Symfony\Component\HttpKernel\EventListener\EsiListener</parameter>
|
||||
<parameter key="http_content_renderer.strategy.esi.class">Symfony\Component\HttpKernel\RenderingStrategy\EsiRenderingStrategy</parameter>
|
||||
<parameter key="fragment.renderer.esi.class">Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
@ -18,11 +18,11 @@
|
||||
<argument type="service" id="esi" on-invalid="ignore" />
|
||||
</service>
|
||||
|
||||
<service id="http_content_renderer.strategy.esi" class="%http_content_renderer.strategy.esi.class%">
|
||||
<tag name="kernel.content_renderer_strategy" />
|
||||
<service id="fragment.renderer.esi" class="%fragment.renderer.esi.class%">
|
||||
<tag name="kernel.fragment_renderer" />
|
||||
<argument type="service" id="esi" />
|
||||
<argument type="service" id="http_content_renderer.strategy.default" />
|
||||
<call method="setProxyPath"><argument>%http_content_renderer.proxy_path%</argument></call>
|
||||
<argument type="service" id="fragment.renderer.inline" />
|
||||
<call method="setFragmentPath"><argument>%fragment.path%</argument></call>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
@ -5,14 +5,14 @@
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="http_content_renderer.listener.router_proxy.class">Symfony\Component\HttpKernel\EventListener\RouterProxyListener</parameter>
|
||||
<parameter key="fragment.listener.class">Symfony\Component\HttpKernel\EventListener\FragmentListener</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="http_content_renderer.listener.router_proxy" class="%http_content_renderer.listener.router_proxy.class%">
|
||||
<service id="fragment.listener" class="%fragment.listener.class%">
|
||||
<tag name="kernel.event_subscriber" />
|
||||
<argument type="service" id="uri_signer" />
|
||||
<argument>%http_content_renderer.proxy_path%</argument>
|
||||
<argument>%fragment.path%</argument>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" ?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="fragment.handler.class">Symfony\Component\HttpKernel\Fragment\FragmentHandler</parameter>
|
||||
<parameter key="fragment.renderer.inline.class">Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer</parameter>
|
||||
<parameter key="fragment.renderer.hinclude.class">Symfony\Bundle\FrameworkBundle\Fragment\ContainerAwareHIncludeFragmentRenderer</parameter>
|
||||
<parameter key="fragment.renderer.hinclude.global_template"></parameter>
|
||||
<parameter key="fragment.path">/_fragment</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="fragment.handler" class="%fragment.handler.class%">
|
||||
<tag name="kernel.event_subscriber" />
|
||||
<argument type="collection" />
|
||||
<argument>%kernel.debug%</argument>
|
||||
</service>
|
||||
|
||||
<service id="fragment.renderer.inline" class="%fragment.renderer.inline.class%">
|
||||
<tag name="kernel.fragment_renderer" />
|
||||
<argument type="service" id="http_kernel" />
|
||||
<call method="setFragmentPath"><argument>%fragment.path%</argument></call>
|
||||
</service>
|
||||
|
||||
<service id="fragment.renderer.hinclude" class="%fragment.renderer.hinclude.class%">
|
||||
<tag name="kernel.fragment_renderer" />
|
||||
<argument type="service" id="service_container" />
|
||||
<argument type="service" id="uri_signer" />
|
||||
<argument>%fragment.renderer.hinclude.global_template%</argument>
|
||||
<call method="setFragmentPath"><argument>%fragment.path%</argument></call>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
@ -12,7 +12,7 @@
|
||||
<xsd:element name="form" type="form" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="csrf-protection" type="csrf_protection" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="esi" type="esi" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="router-proxy" type="router-proxy" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="fragments" type="fragments" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="profiler" type="profiler" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="router" type="router" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="session" type="session" minOccurs="0" maxOccurs="1" />
|
||||
@ -45,7 +45,7 @@
|
||||
<xsd:attribute name="enabled" type="xsd:boolean" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="router-proxy">
|
||||
<xsd:complexType name="fragments">
|
||||
<xsd:attribute name="enabled" type="xsd:boolean" />
|
||||
<xsd:attribute name="path" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
@ -81,7 +81,7 @@
|
||||
|
||||
<service id="templating.helper.actions" class="%templating.helper.actions.class%">
|
||||
<tag name="templating.helper" alias="actions" />
|
||||
<argument type="service" id="http_content_renderer" />
|
||||
<argument type="service" id="fragment.handler" />
|
||||
</service>
|
||||
|
||||
<service id="templating.helper.code" class="%templating.helper.code.class%">
|
||||
|
@ -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 @@ use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||
*/
|
||||
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())
|
||||
|
@ -15,12 +15,12 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
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 @@ class HttpRenderingStrategyPassTest extends \PHPUnit_Framework_TestCase
|
||||
->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 @@ class HttpRenderingStrategyPassTest extends \PHPUnit_Framework_TestCase
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($definition));
|
||||
|
||||
$pass = new HttpRenderingStrategyPass();
|
||||
$pass = new FragmentRendererPass();
|
||||
$pass->process($builder);
|
||||
}
|
||||
|
||||
@ -65,20 +65,20 @@ class HttpRenderingStrategyPassTest extends \PHPUnit_Framework_TestCase
|
||||
$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 @@ class HttpRenderingStrategyPassTest extends \PHPUnit_Framework_TestCase
|
||||
->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())
|
||||
{
|
@ -98,9 +98,9 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
'field_name' => '_token',
|
||||
),
|
||||
'esi' => array('enabled' => false),
|
||||
'router_proxy' => array(
|
||||
'fragments' => array(
|
||||
'enabled' => false,
|
||||
'path' => '/_proxy',
|
||||
'path' => '/_fragment',
|
||||
),
|
||||
'profiler' => array(
|
||||
'enabled' => false,
|
||||
|
@ -90,7 +90,7 @@
|
||||
|
||||
<service id="twig.extension.httpkernel" class="%twig.extension.httpkernel.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument type="service" id="http_content_renderer" />
|
||||
<argument type="service" id="fragment.handler" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
|
||||
|
@ -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
|
||||
|
@ -20,8 +20,8 @@ namespace Symfony\Component\HttpKernel\Controller;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @see Symfony\Component\HttpKernel\HttpContentRenderer
|
||||
* @see Symfony\Component\HttpKernel\RenderingStrategy\RenderingStrategyInterface
|
||||
* @see Symfony\Component\HttpKernel\FragmentRenderer
|
||||
* @see Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface
|
||||
*/
|
||||
class ControllerReference
|
||||
{
|
||||
|
@ -20,32 +20,35 @@ use Symfony\Component\HttpKernel\UriSigner;
|
||||
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 <fabien@symfony.com>
|
||||
*/
|
||||
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 @@ class RouterProxyListener implements EventSubscriberInterface
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
|
||||
if ($this->proxyPath !== rawurldecode($request->getPathInfo())) {
|
||||
if ($this->fragmentPath !== rawurldecode($request->getPathInfo())) {
|
||||
return;
|
||||
}
|
||||
|
@ -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 @@ use Symfony\Component\HttpKernel\HttpCache\Esi;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
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 @@ class EsiRenderingStrategy extends ProxyAwareRenderingStrategy
|
||||
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'] : '');
|
@ -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 <fabien@symfony.com>
|
||||
*
|
||||
* @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 @@ class HttpContentRenderer implements EventSubscriberInterface
|
||||
* * 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 @@ class HttpContentRenderer implements EventSubscriberInterface
|
||||
// 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 @@ class HttpContentRenderer implements EventSubscriberInterface
|
||||
|
||||
$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']);
|
||||
}
|
||||
|
@ -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 @@ use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @see Symfony\Component\HttpKernel\HttpContentRenderer
|
||||
* @see Symfony\Component\HttpKernel\FragmentRenderer
|
||||
*/
|
||||
interface RenderingStrategyInterface
|
||||
interface FragmentRendererInterface
|
||||
{
|
||||
/**
|
||||
* Renders a URI and returns the Response content.
|
@ -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 @@ use Symfony\Component\HttpKernel\UriSigner;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class HIncludeRenderingStrategy extends ProxyAwareRenderingStrategy
|
||||
class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
{
|
||||
protected $templating;
|
||||
|
||||
@ -61,7 +61,7 @@ class HIncludeRenderingStrategy extends ProxyAwareRenderingStrategy
|
||||
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;
|
@ -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\HttpKernelInterface;
|
||||
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 <fabien@symfony.com>
|
||||
*/
|
||||
class DefaultRenderingStrategy extends ProxyAwareRenderingStrategy
|
||||
class InlineFragmentRenderer extends RoutableFragmentRenderer
|
||||
{
|
||||
private $kernel;
|
||||
|
||||
@ -45,7 +45,7 @@ class DefaultRenderingStrategy extends ProxyAwareRenderingStrategy
|
||||
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 @@ class DefaultRenderingStrategy extends ProxyAwareRenderingStrategy
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'default';
|
||||
return 'inline';
|
||||
}
|
||||
}
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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 @@ abstract class ProxyAwareRenderingStrategy implements RenderingStrategyInterface
|
||||
|
||||
$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, '', '&'));
|
||||
}
|
||||
}
|
@ -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 @@ class RouterProxyListenerTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ class RouterProxyListenerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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 @@ class RouterProxyListenerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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 @@ class RouterProxyListenerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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 @@ class RouterProxyListenerTest extends \PHPUnit_Framework_TestCase
|
||||
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);
|
@ -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 @@ class EsiRenderingStrategyTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ class EsiRenderingStrategyTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
|
||||
$this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
|
||||
$this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
|
||||
$this->assertEquals('<esi:include src="http://localhost/_proxy?_path=_format%3Dhtml%26_controller%3Dmain_controller" alt="http://localhost/_proxy?_path=_format%3Dhtml%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent());
|
||||
$this->assertEquals('<esi:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller" alt="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dalt_controller" />', $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;
|
||||
}
|
||||
}
|
@ -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 @@ class HttpContentRendererTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @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 @@ class HttpContentRendererTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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 @@ class HttpContentRendererTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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 @@ class HttpContentRendererTest extends \PHPUnit_Framework_TestCase
|
||||
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 @@ class HttpContentRendererTest extends \PHPUnit_Framework_TestCase
|
||||
->method('getRequest')
|
||||
->will($this->returnValue(Request::create('/')))
|
||||
;
|
||||
$renderer->onKernelRequest($event);
|
||||
$handler->onKernelRequest($event);
|
||||
|
||||
return $renderer;
|
||||
return $handler;
|
||||
}
|
||||
}
|
@ -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 @@ class HIncludeRenderingStrategyTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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('<hx:include src="http://localhost/_proxy?_path=_format%3Dhtml%26_controller%3Dmain_controller&_hash=ctQ5X4vzZnFmmPiqIqnBkVr%2B%2B10%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
|
||||
$this->assertEquals('<hx:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller&_hash=VI25qJj8J0qveB3bGKPhsJtexKg%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
|
||||
}
|
||||
|
||||
public function testRenderWithUri()
|
||||
{
|
||||
$strategy = new HIncludeRenderingStrategy();
|
||||
$strategy = new HIncludeFragmentRenderer();
|
||||
$this->assertEquals('<hx:include src="/foo"></hx:include>', $strategy->render('/foo', Request::create('/'))->getContent());
|
||||
|
||||
$strategy = new HIncludeRenderingStrategy(null, new UriSigner('foo'));
|
||||
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
|
||||
$this->assertEquals('<hx:include src="/foo"></hx:include>', $strategy->render('/foo', Request::create('/'))->getContent());
|
||||
}
|
||||
|
||||
public function testRenderWhithDefault()
|
||||
{
|
||||
// only default
|
||||
$strategy = new HIncludeRenderingStrategy();
|
||||
$strategy = new HIncludeFragmentRenderer();
|
||||
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $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('<hx:include src="/foo">global_default</hx:include>', $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('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
|
||||
}
|
||||
}
|
@ -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 @@ class DefaultRenderingStrategyTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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 @@ class DefaultRenderingStrategyTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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 @@ class DefaultRenderingStrategyTest extends \PHPUnit_Framework_TestCase
|
||||
;
|
||||
|
||||
$kernel = new HttpKernel(new EventDispatcher(), $resolver);
|
||||
$renderer = new DefaultRenderingStrategy($kernel);
|
||||
$renderer = new InlineFragmentRenderer($kernel);
|
||||
|
||||
// simulate a main request with output buffering
|
||||
ob_start();
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user