diff --git a/config/module.config.php b/config/module.config.php
index a8df173..ca51902 100644
--- a/config/module.config.php
+++ b/config/module.config.php
@@ -14,8 +14,8 @@
]
],
'controllers' => [
- 'invokables' => [
- 'ConVarnish\Controller\Esi' => 'ConVarnish\Controller\EsiController'
+ 'factories' => [
+ 'ConVarnish\Controller\Esi' => 'ConVarnish\Controller\EsiControllerFactory'
]
],
'router' => [
@@ -25,7 +25,7 @@
'options' => [
'route' => '/esi/:block',
'constraints' => [
- 'block' => '[A-Za-z0-9.-_]+'
+ 'block' => '[A-Za-z0-9_.-]+'
],
'defaults' => [
'controller' => 'ConVarnish\Controller\Esi',
diff --git a/src/ConVarnish/Controller/EsiController.php b/src/ConVarnish/Controller/EsiController.php
index 12e35ed..68d5665 100644
--- a/src/ConVarnish/Controller/EsiController.php
+++ b/src/ConVarnish/Controller/EsiController.php
@@ -1,6 +1,7 @@
params()->fromRoute('block');
+ $handles = $this->params()->fromQuery('handles', []);
+ /* @var $layoutManager LayoutManager */
+ $layoutManager = $this->layoutManager();
+ foreach ($handles as $handle) {
+ $layoutManager->addHandle($handle);
+ }
if (!$blockId) {
return $this->blockNotFound($blockId);
}
- $this->layoutManager()->load();
- if (!$block = $this->layoutManager()->getBlock($blockId)) {
+ $layoutManager->load();
+ if (!$block = $layoutManager->getBlock($blockId)) {
$block = $this->blockNotFound($blockId);
}
$block->setVariable('__ESI__', true);
diff --git a/src/ConVarnish/Controller/EsiControllerFactory.php b/src/ConVarnish/Controller/EsiControllerFactory.php
new file mode 100644
index 0000000..9f25caa
--- /dev/null
+++ b/src/ConVarnish/Controller/EsiControllerFactory.php
@@ -0,0 +1,19 @@
+
+ */
+class EsiControllerFactory implements FactoryInterface
+{
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ $controller = new EsiController();
+ return $controller;
+ }
+}
diff --git a/src/ConVarnish/Listener/InjectCacheHeaderListener.php b/src/ConVarnish/Listener/InjectCacheHeaderListener.php
index 61aa844..71d3f26 100644
--- a/src/ConVarnish/Listener/InjectCacheHeaderListener.php
+++ b/src/ConVarnish/Listener/InjectCacheHeaderListener.php
@@ -195,8 +195,17 @@ public function injectEsi(EventInterface $e)
}
/* @var $block ViewModel */
$block = $e->getParam('block');
- if ($block->getOption('esi')) {
+ if ($options = $block->getOption('esi')) {
$block->setTemplate(self::ESI_TEMPLATE);
+ $handles = isset($options['handles']) ? (array) $options['handles'] : [];
+ $block->setVariable('__HANDLES__', $handles);
+ if ($this->varnishOptions->getDebug()) {
+ $block->setVariables([
+ '__DEBUG__' => true,
+ '__TTL__' => isset($options['ttl']) ? $options['ttl'] : 'n/a',
+ '__TAGS__' => $block->getOption('cache_tags', [])
+ ]);
+ }
$this->injectEsiHeader();
}
}
diff --git a/src/ConVarnish/View/Helper/EsiUrl.php b/src/ConVarnish/View/Helper/EsiUrl.php
index 79f79a0..59722c5 100644
--- a/src/ConVarnish/View/Helper/EsiUrl.php
+++ b/src/ConVarnish/View/Helper/EsiUrl.php
@@ -15,11 +15,20 @@ class EsiUrl extends AbstractHelper
* @param string $blockId
* @return array|string
*/
- public function __invoke($blockId)
+ public function __invoke($blockId, array $handles = [])
{
+ $options = [];
+ if (count($handles)) {
+ $options = [
+ 'query' => [
+ 'handles' => $handles
+ ]
+ ];
+ }
$url = $this->getView()->url(
'esi',
- ['block' => $blockId]
+ ['block' => $blockId],
+ $options
);
return $url;
}
diff --git a/view/con-varnish/esi.phtml b/view/con-varnish/esi.phtml
index be7924a..cb362ee 100644
--- a/view/con-varnish/esi.phtml
+++ b/view/con-varnish/esi.phtml
@@ -1,8 +1,25 @@
esiUrl($this->{$blockId}, $this->__HANDLES__);
?>
-
+__DEBUG__): ?>
+
+
+
= $this->content ?>
+__DEBUG__): ?>
+
+