public function testRenderWithDefaultText()
 {
     $engine = $this->getMock('Symfony\\Component\\Templating\\EngineInterface');
     $engine->expects($this->once())->method('exists')->with('default')->will($this->throwException(new \InvalidArgumentException()));
     // only default
     $strategy = new HIncludeFragmentRenderer($engine);
     $this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
 }
 public function testRenderWithAttributesOptions()
 {
     // with id
     $strategy = new HIncludeFragmentRenderer();
     $this->assertEquals('<hx:include src="/foo" id="bar">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'id' => 'bar'))->getContent());
     // with attributes
     $strategy = new HIncludeFragmentRenderer();
     $this->assertEquals('<hx:include src="/foo" p1="v1" p2="v2">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'attributes' => array('p1' => 'v1', 'p2' => 'v2')))->getContent());
     // with id & attributes
     $strategy = new HIncludeFragmentRenderer();
     $this->assertEquals('<hx:include src="/foo" p1="v1" p2="v2" id="bar">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'id' => 'bar', 'attributes' => array('p1' => 'v1', 'p2' => 'v2')))->getContent());
 }
 public function testRenderWhithDefault()
 {
     // only default
     $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 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 HIncludeFragmentRenderer(null, null, 'global_default');
     $this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
 }
 /**
  * {@inheritdoc}
  */
 public function render($uri, Request $request, array $options = array())
 {
     // setting the templating cannot be done in the constructor
     // as it would lead to an infinite recursion in the service container
     if (!$this->hasTemplating()) {
         $this->setTemplating($this->container->get('templating'));
     }
     return parent::render($uri, $request, $options);
 }
 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;
     });
 }
Ejemplo n.º 6
0
 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;
     };
 }