-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inital version of Twig ez_http_tag_location() function (#67)
1. Refactors Response taggers to get rid of (by now) unused configurator and reponse, in order to: 2. Expose Twig extension to have function for tagging locations Reason for picking location: It has all data needed, we need lcoation in order to be able to know which subtree to tag for (to make sure cache is cleared on subtree operations). If needed there could be a helper for contentInfo as well which loads main for you.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the ContentTaggingExtension class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformHttpCacheBundle\Twig; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Location; | ||
use EzSystems\PlatformHttpCacheBundle\ResponseTagger\ResponseTagger; | ||
use Twig_Extension; | ||
use Twig_SimpleFunction; | ||
|
||
/** | ||
* Twig content extension for eZ Publish specific usage. | ||
* Exposes helpers to play with public API objects. | ||
*/ | ||
class ContentTaggingExtension extends Twig_Extension | ||
{ | ||
/** @var \EzSystems\PlatformHttpCacheBundle\ResponseTagger\ResponseTagger */ | ||
protected $responseTagger; | ||
|
||
public function __construct(ResponseTagger $responseTagger) | ||
{ | ||
$this->responseTagger = $responseTagger; | ||
} | ||
|
||
/** | ||
* @return array|\Twig_Function[] | ||
*/ | ||
public function getFunctions() | ||
{ | ||
return [ | ||
new Twig_SimpleFunction( | ||
'ez_http_tag_location', | ||
[$this, 'tagHttpCacheForLocation'] | ||
), | ||
]; | ||
} | ||
|
||
/** | ||
* Adds tags to current response. | ||
* | ||
* @internal Function is only for use within this class (and implicit by Twig). | ||
* | ||
* @param Location $location | ||
*/ | ||
public function tagHttpCacheForLocation(Location $location) | ||
{ | ||
$this->responseTagger->tag($location); | ||
$this->responseTagger->tag($location->getContentInfo()); | ||
} | ||
} |