From 41cc0d6db7dc44a45ad66dcb65d37ed233026e92 Mon Sep 17 00:00:00 2001 From: kbond Date: Fri, 16 Dec 2011 09:51:05 -0500 Subject: [PATCH 1/4] [FrameworkBundle] added support for HInclude --- .../DependencyInjection/Configuration.php | 1 + .../FrameworkExtension.php | 1 + .../Bundle/FrameworkBundle/HttpKernel.php | 29 +++++++++++++++++-- .../Resources/config/routing/internal.xml | 8 ++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 5762fb4c337b..65fe44a9cdb6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -205,6 +205,7 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode) ->children() ->scalarNode('assets_version')->defaultValue(null)->end() ->scalarNode('assets_version_format')->defaultValue('%%s?%%s')->end() + ->scalarNode('hinclude_default_template')->defaultNull()->end() ->arrayNode('form') ->addDefaultsIfNotSet() ->fixXmlConfig('resource') diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 2e80aea91844..e6da985e3d15 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -332,6 +332,7 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB $container->setParameter('templating.helper.code.file_link_format', isset($links[$ide]) ? $links[$ide] : $ide); $container->setParameter('templating.helper.form.resources', $config['form']['resources']); + $container->setParameter('templating.hinclude.default_template', $config['hinclude_default_template']); if ($container->getParameter('kernel.debug')) { $loader->load('templating_debug.xml'); diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index 0ab5634e8152..64dc8a895536 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -114,7 +114,7 @@ public function render($controller, array $options = array()) $this->esiSupport = $this->container->has('esi') && $this->container->get('esi')->hasSurrogateEsiCapability($this->container->get('request')); } - if ($this->esiSupport && $options['standalone']) { + if ($this->esiSupport && (true === $options['standalone'] || 'esi' === $options['standalone'])) { $uri = $this->generateInternalUri($controller, $options['attributes'], $options['query']); $alt = ''; @@ -125,6 +125,17 @@ public function render($controller, array $options = array()) return $this->container->get('esi')->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']); } + if ('js' === $options['standalone']) { + $uri = $this->generateInternalUri($controller, $options['attributes'], $options['query'], false); + $defaultContent = null; + + if ($template = $this->container->getParameter('templating.hinclude.default_template')) { + $defaultContent = $this->container->get('templating')->render($template); + } + + return $this->renderHIncludeTag($uri, $defaultContent); + } + $request = $this->container->get('request'); // controller or URI? @@ -185,14 +196,14 @@ public function render($controller, array $options = array()) * * @return string An internal URI */ - public function generateInternalUri($controller, array $attributes = array(), array $query = array()) + public function generateInternalUri($controller, array $attributes = array(), array $query = array(), $secure = true) { if (0 === strpos($controller, '/')) { return $controller; } $path = http_build_query($attributes); - $uri = $this->container->get('router')->generate('_internal', array( + $uri = $this->container->get('router')->generate($secure ? '_internal' : '_internal_unsecure', array( 'controller' => $controller, 'path' => $path ?: 'none', '_format' => $this->container->get('request')->getRequestFormat(), @@ -204,4 +215,16 @@ public function generateInternalUri($controller, array $attributes = array(), ar return $uri; } + + /** + * Renders an HInclude tag. + * + * @param string $uri A URI + */ + public function renderHIncludeTag($uri, $defaultContent = null) + { + $html = sprintf('%s', $uri, $defaultContent); + + return $html; + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml index 60c7c1c995b6..2d91092a3ee0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml @@ -4,7 +4,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - + + FrameworkBundle:Internal:index + .+ + [^.]+ + + + FrameworkBundle:Internal:index .+ [^.]+ From 72d580594f0fd4703355fa559b364859d921b505 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Sat, 11 Feb 2012 15:24:20 -0500 Subject: [PATCH 2/4] changed route name --- src/Symfony/Bundle/FrameworkBundle/HttpKernel.php | 2 +- .../FrameworkBundle/Resources/config/routing/internal.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index 64dc8a895536..7fede85bc69e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -203,7 +203,7 @@ public function generateInternalUri($controller, array $attributes = array(), ar } $path = http_build_query($attributes); - $uri = $this->container->get('router')->generate($secure ? '_internal' : '_internal_unsecure', array( + $uri = $this->container->get('router')->generate($secure ? '_internal' : '_internal_public', array( 'controller' => $controller, 'path' => $path ?: 'none', '_format' => $this->container->get('request')->getRequestFormat(), diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml index 2d91092a3ee0..46df17f7fe69 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml @@ -10,7 +10,7 @@ [^.]+ - + FrameworkBundle:Internal:index .+ [^.]+ From 924f3782420881d0e56519336e5b430004aeda09 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Sat, 11 Feb 2012 16:20:40 -0500 Subject: [PATCH 3/4] updated changelog --- CHANGELOG-2.1.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 5799a297576f..0197cb440285 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -40,6 +40,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c * changed the default profiler storage to use the filesystem instead of SQLite * added support for placeholders in route defaults and requirements (replaced by the value set in the service container) * added Filesystem component as a dependency + * added support for hinclude (use ``standalone: 'js'`` in render tag) ### SecurityBundle From cea2c7e60f72d95ad296b38979a7c1370f2260f9 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Sun, 12 Feb 2012 08:57:10 -0500 Subject: [PATCH 4/4] removed unneeded local variable --- src/Symfony/Bundle/FrameworkBundle/HttpKernel.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index 7fede85bc69e..613203dce5a1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -223,8 +223,6 @@ public function generateInternalUri($controller, array $attributes = array(), ar */ public function renderHIncludeTag($uri, $defaultContent = null) { - $html = sprintf('%s', $uri, $defaultContent); - - return $html; + return sprintf('%s', $uri, $defaultContent); } }