2014-05-14 13:24:20 +00:00
|
|
|
<?php namespace Cms\Twig;
|
|
|
|
|
|
2015-06-05 07:43:32 +00:00
|
|
|
use Event;
|
2014-05-14 13:24:20 +00:00
|
|
|
use Twig_LoaderInterface;
|
|
|
|
|
use Cms\Classes\CmsObject;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class implements a Twig template loader for the CMS.
|
|
|
|
|
*
|
|
|
|
|
* @package october\cms
|
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
|
*/
|
|
|
|
|
class Loader implements Twig_LoaderInterface
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var \Cms\Classes\CmsCompoundObject A CMS object to load the template from.
|
|
|
|
|
*/
|
|
|
|
|
protected $obj;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets a CMS object to load the template from.
|
2014-05-17 23:20:14 +00:00
|
|
|
* @param \Cms\Classes\CmsObject $obj Specifies the CMS object.
|
2014-05-14 13:24:20 +00:00
|
|
|
*/
|
|
|
|
|
public function setObject(CmsObject $obj)
|
|
|
|
|
{
|
|
|
|
|
$this->obj = $obj;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-05 07:43:32 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the Twig content string.
|
|
|
|
|
* This step is cached internally by Twig.
|
|
|
|
|
*/
|
2014-05-14 13:24:20 +00:00
|
|
|
public function getSource($name)
|
|
|
|
|
{
|
2015-06-05 07:43:32 +00:00
|
|
|
$content = $this->obj->getTwigContent();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Extensibility
|
|
|
|
|
*/
|
|
|
|
|
$dataHolder = (object) ['content' => $content];
|
|
|
|
|
|
|
|
|
|
Event::fire('cms.template.processTwigContent', [$this->obj, $dataHolder]);
|
|
|
|
|
|
|
|
|
|
return $dataHolder->content;
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-05 07:43:32 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the Twig cache key.
|
|
|
|
|
*/
|
2014-05-14 13:24:20 +00:00
|
|
|
public function getCacheKey($name)
|
|
|
|
|
{
|
|
|
|
|
return $this->obj->getFullPath();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-05 07:43:32 +00:00
|
|
|
/**
|
|
|
|
|
* Determines if the content is fresh.
|
|
|
|
|
*/
|
2014-05-14 13:24:20 +00:00
|
|
|
public function isFresh($name, $time)
|
|
|
|
|
{
|
2016-01-02 02:41:57 +00:00
|
|
|
return $this->obj->mtime <= $time;
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
2014-10-10 23:42:04 +00:00
|
|
|
}
|