/** * @expectedException \LogicException */ public function testRenderAltControllerReferenceWithoutSignerThrowsException() { $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); $request = Request::create('/'); $request->setLocale('fr'); $request->headers->set('Surrogate-Capability', 'ESI/1.0'); $strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller'))); }
public function testRender() { $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); $request = Request::create('/'); $request->headers->set('Surrogate-Capability', 'ESI/1.0'); $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/_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()); }
public function renderEsi($params, $template = null) { $path = $this->getParam($params, 'path'); $alt = $this->getParam($params, 'alt'); $ignore_errors = $this->getParam($params, 'ignore_errors'); $comment = $this->getParam($params, 'comment'); if (null === $path) { return; } $response = $this->esiFragmentRender->render($path, $this->requestStack->getCurrentRequest(), array('alt' => $alt, 'ignore_errors' => $ignore_errors, 'comment' => $comment)); if (!$response->isSuccessful()) { return null; } return $response->getContent(); }
protected function generateFragmentUri(ControllerReference $reference, Request $request) { if (!isset($this->fragmentUriGenerator)) { $this->fragmentUriGenerator = new FragmentUriGenerator(); } $this->fragmentUriGenerator->generateFragmentUri($reference, $request); return parent::generateFragmentUri($reference, $request); }
public function register(Application $app) { if (!class_exists('Symfony\\Component\\HttpFoundation\\RequestStack')) { throw new \LogicException('The HTTP Fragment service provider only works with Symfony 2.4+.'); } $app['fragment.handler'] = $app->share(function ($app) { if (Kernel::VERSION_ID >= 20800) { return new FragmentHandler($app['request_stack'], $app['fragment.renderers'], $app['debug']); } return new FragmentHandler($app['fragment.renderers'], $app['debug'], $app['request_stack']); }); $app['fragment.renderer.inline'] = $app->share(function ($app) { $renderer = new InlineFragmentRenderer($app['kernel'], $app['dispatcher']); $renderer->setFragmentPath($app['fragment.path']); return $renderer; }); $app['fragment.renderer.hinclude'] = $app->share(function ($app) { $renderer = new HIncludeFragmentRenderer(null, $app['uri_signer'], $app['fragment.renderer.hinclude.global_template'], $app['charset']); $renderer->setFragmentPath($app['fragment.path']); return $renderer; }); $app['fragment.renderer.esi'] = $app->share(function ($app) { $renderer = new EsiFragmentRenderer($app['http_cache.esi'], $app['fragment.renderer.inline']); $renderer->setFragmentPath($app['fragment.path']); return $renderer; }); $app['fragment.listener'] = $app->share(function ($app) { return new FragmentListener($app['uri_signer'], $app['fragment.path']); }); $app['uri_signer'] = $app->share(function ($app) { return new UriSigner($app['uri_signer.secret']); }); $app['uri_signer.secret'] = md5(__DIR__); $app['fragment.path'] = '/_fragment'; $app['fragment.renderer.hinclude.global_template'] = null; $app['fragment.renderers'] = $app->share(function ($app) { $renderers = array($app['fragment.renderer.inline'], $app['fragment.renderer.hinclude']); if (isset($app['http_cache.esi'])) { $renderers[] = $app['fragment.renderer.esi']; } return $renderers; }); }
public function register(Container $app) { $app['fragment.handler'] = function ($app) { if (Kernel::VERSION_ID >= 20800) { return new FragmentHandler($app['request_stack'], $app['fragment.renderers'], $app['debug']); } return new FragmentHandler($app['fragment.renderers'], $app['debug'], $app['request_stack']); }; $app['fragment.renderer.inline'] = function ($app) { $renderer = new InlineFragmentRenderer($app['kernel'], $app['dispatcher']); $renderer->setFragmentPath($app['fragment.path']); return $renderer; }; $app['fragment.renderer.hinclude'] = function ($app) { $renderer = new HIncludeFragmentRenderer(null, $app['uri_signer'], $app['fragment.renderer.hinclude.global_template'], $app['charset']); $renderer->setFragmentPath($app['fragment.path']); return $renderer; }; $app['fragment.renderer.esi'] = function ($app) { $renderer = new EsiFragmentRenderer($app['http_cache.esi'], $app['fragment.renderer.inline']); $renderer->setFragmentPath($app['fragment.path']); return $renderer; }; $app['fragment.listener'] = function ($app) { return new FragmentListener($app['uri_signer'], $app['fragment.path']); }; $app['uri_signer'] = function ($app) { return new UriSigner($app['uri_signer.secret']); }; $app['uri_signer.secret'] = md5(__DIR__); $app['fragment.path'] = '/_fragment'; $app['fragment.renderer.hinclude.global_template'] = null; $app['fragment.renderers'] = function ($app) { $renderers = array($app['fragment.renderer.inline'], $app['fragment.renderer.hinclude']); if (isset($app['http_cache.esi'])) { $renderers[] = $app['fragment.renderer.esi']; } return $renderers; }; }