Skip to content

Commit

Permalink
added debug to esi template
Browse files Browse the repository at this point in the history
added handles to esi url
  • Loading branch information
hummer2k committed Jun 4, 2015
1 parent 9d2e444 commit d09052c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 9 deletions.
6 changes: 3 additions & 3 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
]
],
'controllers' => [
'invokables' => [
'ConVarnish\Controller\Esi' => 'ConVarnish\Controller\EsiController'
'factories' => [
'ConVarnish\Controller\Esi' => 'ConVarnish\Controller\EsiControllerFactory'
]
],
'router' => [
Expand All @@ -25,7 +25,7 @@
'options' => [
'route' => '/esi/:block',
'constraints' => [
'block' => '[A-Za-z0-9.-_]+'
'block' => '[A-Za-z0-9_.-]+'
],
'defaults' => [
'controller' => 'ConVarnish\Controller\Esi',
Expand Down
11 changes: 9 additions & 2 deletions src/ConVarnish/Controller/EsiController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace ConVarnish\Controller;

use ConLayout\Controller\Plugin\LayoutManager;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

Expand All @@ -18,11 +19,17 @@ class EsiController extends AbstractActionController
public function blockAction()
{
$blockId = $this->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);
Expand Down
19 changes: 19 additions & 0 deletions src/ConVarnish/Controller/EsiControllerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace ConVarnish\Controller;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @package ConVarnish
* @author Cornelius Adams (conlabz GmbH) <cornelius.adams@conlabz.de>
*/
class EsiControllerFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$controller = new EsiController();
return $controller;
}
}
11 changes: 10 additions & 1 deletion src/ConVarnish/Listener/InjectCacheHeaderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/ConVarnish/View/Helper/EsiUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 18 additions & 1 deletion view/con-varnish/esi.phtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
<?php
use ConLayout\Layout\LayoutInterface;
$blockId = LayoutInterface::BLOCK_ID_VAR;
$esiUrl = $this->esiUrl($this->{$blockId}, $this->__HANDLES__);
?>
<esi:include src="<?= $this->esiUrl($this->{$blockId}) ?>"/>
<?php if ($this->__DEBUG__): ?>
<!--
[ ESI START: <?= $this->{$blockId} ?> ]
[ TTL: <?= $this->__TTL__ ?> ]
<?php if (count($this->__HANDLES__)): ?>
[ Handles: <?= implode(', ', $this->__HANDLES__) ?> ]
<?php endif ?>
<?php if (count($this->__TAGS__)): ?>
[ Ban-Tags: <?= implode(', ', $this->__TAGS__) ?> ]
<?php endif ?>
[ Ban-Url: <?= $esiUrl ?> ]
-->
<?php endif; ?>
<esi:include src="<?= $esiUrl ?>"/>
<esi:remove>
<?= $this->content ?>
</esi:remove>
<?php if ($this->__DEBUG__): ?>
<!-- [ ESI STOP: <?= $this->{$blockId} ?> ] -->
<?php endif; ?>

0 comments on commit d09052c

Please sign in to comment.