Skip to content
This repository
Browse code

merged branch kbond/hinclude (PR #3259)

Commits
-------

cea2c7e removed unneeded local variable
924f378 updated changelog
72d5805 changed route name
41cc0d6 [FrameworkBundle] added support for HInclude

Discussion
----------

[FrameworkBundle] added support for HInclude

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: discuss
Example: https://github.com/kbond/symfony-standard/tree/hinclude

**Reopened this as I broke #2903**

References:

 - http://groups.google.com/group/symfony-devs/browse_thread/thread/b74e587d6f2f87b0
 - http://groups.google.com/group/symfony-devs/browse_thread/thread/8776a9833d4a5f79
 - #2903
 - #2865

[![Build Status](https://secure.travis-ci.org/kbond/symfony.png?branch=hinclude)](http://travis-ci.org/kbond/symfony)

---------------------------------------------------------------------------

by kbond at 2012-02-11T20:27:22Z

unless there is anything else I think this is ready, want me to squash again?

---------------------------------------------------------------------------

by fabpot at 2012-02-11T21:07:33Z

@kbond: Can you add some information about the changes in the CHANGELOG?

---------------------------------------------------------------------------

by Tobion at 2012-02-11T21:33:32Z

Do I see it correctly that we cannot set a default template on a per hinclude tag basis? But only global?
That's not really usefull when javascript is disabled because it should resemble the content to be included as an alternative.

---------------------------------------------------------------------------

by stof at 2012-02-11T21:42:15Z

@Tobion currently it is not possible. But changing the content on a tag basis may require changing the way the render tag look like (as there is no content in the tag currently) so this needs further discussion and @fabpot said he wants to merge a first implementation without it. See the discussion above.
  • Loading branch information...
commit 4a0057fd5646a5aaa4f0a0b08411572955dfd9aa 2 parents 803fba8 + cea2c7e
Fabien Potencier fabpot authored
1  CHANGELOG-2.1.md
Source Rendered
@@ -41,6 +41,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
41 41 * changed the default profiler storage to use the filesystem instead of SQLite
42 42 * added support for placeholders in route defaults and requirements (replaced by the value set in the service container)
43 43 * added Filesystem component as a dependency
  44 + * added support for hinclude (use ``standalone: 'js'`` in render tag)
44 45
45 46 ### MonologBundle
46 47
1  src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -211,6 +211,7 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode)
211 211 ->children()
212 212 ->scalarNode('assets_version')->defaultValue(null)->end()
213 213 ->scalarNode('assets_version_format')->defaultValue('%%s?%%s')->end()
  214 + ->scalarNode('hinclude_default_template')->defaultNull()->end()
214 215 ->arrayNode('form')
215 216 ->addDefaultsIfNotSet()
216 217 ->fixXmlConfig('resource')
1  src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -335,6 +335,7 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
335 335
336 336 $container->setParameter('templating.helper.code.file_link_format', isset($links[$ide]) ? $links[$ide] : $ide);
337 337 $container->setParameter('templating.helper.form.resources', $config['form']['resources']);
  338 + $container->setParameter('templating.hinclude.default_template', $config['hinclude_default_template']);
338 339
339 340 if ($container->getParameter('kernel.debug')) {
340 341 $loader->load('templating_debug.xml');
27 src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
@@ -114,7 +114,7 @@ public function render($controller, array $options = array())
114 114 $this->esiSupport = $this->container->has('esi') && $this->container->get('esi')->hasSurrogateEsiCapability($this->container->get('request'));
115 115 }
116 116
117   - if ($this->esiSupport && $options['standalone']) {
  117 + if ($this->esiSupport && (true === $options['standalone'] || 'esi' === $options['standalone'])) {
118 118 $uri = $this->generateInternalUri($controller, $options['attributes'], $options['query']);
119 119
120 120 $alt = '';
@@ -125,6 +125,17 @@ public function render($controller, array $options = array())
125 125 return $this->container->get('esi')->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']);
126 126 }
127 127
  128 + if ('js' === $options['standalone']) {
  129 + $uri = $this->generateInternalUri($controller, $options['attributes'], $options['query'], false);
  130 + $defaultContent = null;
  131 +
  132 + if ($template = $this->container->getParameter('templating.hinclude.default_template')) {
  133 + $defaultContent = $this->container->get('templating')->render($template);
  134 + }
  135 +
  136 + return $this->renderHIncludeTag($uri, $defaultContent);
  137 + }
  138 +
128 139 $request = $this->container->get('request');
129 140
130 141 // controller or URI?
@@ -185,14 +196,14 @@ public function render($controller, array $options = array())
185 196 *
186 197 * @return string An internal URI
187 198 */
188   - public function generateInternalUri($controller, array $attributes = array(), array $query = array())
  199 + public function generateInternalUri($controller, array $attributes = array(), array $query = array(), $secure = true)
189 200 {
190 201 if (0 === strpos($controller, '/')) {
191 202 return $controller;
192 203 }
193 204
194 205 $path = http_build_query($attributes);
195   - $uri = $this->container->get('router')->generate('_internal', array(
  206 + $uri = $this->container->get('router')->generate($secure ? '_internal' : '_internal_public', array(
196 207 'controller' => $controller,
197 208 'path' => $path ?: 'none',
198 209 '_format' => $this->container->get('request')->getRequestFormat(),
@@ -204,4 +215,14 @@ public function generateInternalUri($controller, array $attributes = array(), ar
204 215
205 216 return $uri;
206 217 }
  218 +
  219 + /**
  220 + * Renders an HInclude tag.
  221 + *
  222 + * @param string $uri A URI
  223 + */
  224 + public function renderHIncludeTag($uri, $defaultContent = null)
  225 + {
  226 + return sprintf('<hx:include src="%s">%s</hx:include>', $uri, $defaultContent);
  227 + }
207 228 }
8 src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml
@@ -4,7 +4,13 @@
4 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 5 xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
6 6
7   - <route id="_internal" pattern="/{controller}/{path}.{_format}">
  7 + <route id="_internal" pattern="/secure/{controller}/{path}.{_format}">
  8 + <default key="_controller">FrameworkBundle:Internal:index</default>
  9 + <requirement key="path">.+</requirement>
  10 + <requirement key="_format">[^.]+</requirement>
  11 + </route>
  12 +
  13 + <route id="_internal_public" pattern="/{controller}/{path}.{_format}">
8 14 <default key="_controller">FrameworkBundle:Internal:index</default>
9 15 <requirement key="path">.+</requirement>
10 16 <requirement key="_format">[^.]+</requirement>

0 comments on commit 4a0057f

Please sign in to comment.
Something went wrong with that request. Please try again.