[FrameworkBundle] added support for HInclude
This commit is contained in:
parent
0914a38e74
commit
41cc0d6db7
@ -205,6 +205,7 @@ class Configuration implements ConfigurationInterface
|
||||
->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')
|
||||
|
@ -332,6 +332,7 @@ class FrameworkExtension extends Extension
|
||||
|
||||
$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');
|
||||
|
@ -114,7 +114,7 @@ class HttpKernel extends BaseHttpKernel
|
||||
$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 @@ class HttpKernel extends BaseHttpKernel
|
||||
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 @@ class HttpKernel extends BaseHttpKernel
|
||||
*
|
||||
* @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 @@ class HttpKernel extends BaseHttpKernel
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an HInclude tag.
|
||||
*
|
||||
* @param string $uri A URI
|
||||
*/
|
||||
public function renderHIncludeTag($uri, $defaultContent = null)
|
||||
{
|
||||
$html = sprintf('<hx:include src="%s">%s</hx:include>', $uri, $defaultContent);
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
@ -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">
|
||||
|
||||
<route id="_internal" pattern="/{controller}/{path}.{_format}">
|
||||
<route id="_internal" pattern="/secure/{controller}/{path}.{_format}">
|
||||
<default key="_controller">FrameworkBundle:Internal:index</default>
|
||||
<requirement key="path">.+</requirement>
|
||||
<requirement key="_format">[^.]+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="_internal_unsecure" pattern="/{controller}/{path}.{_format}">
|
||||
<default key="_controller">FrameworkBundle:Internal:index</default>
|
||||
<requirement key="path">.+</requirement>
|
||||
<requirement key="_format">[^.]+</requirement>
|
||||
|
Reference in New Issue
Block a user