You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.5 KiB
74 lines
1.5 KiB
12 years ago
|
<?php
|
||
12 years ago
|
/**
|
||
|
* Simple file system wrapper for twig to process twig files
|
||
|
*
|
||
|
* @link http://www.yiiframework.com/
|
||
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||
|
* @license http://www.yiiframework.com/license/
|
||
|
*/
|
||
12 years ago
|
|
||
|
namespace yii\twig;
|
||
|
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
12 years ago
|
* Twig view file loader class.
|
||
12 years ago
|
*
|
||
|
* @author dev-mraj <dev.meghraj@gmail.com>
|
||
|
*/
|
||
12 years ago
|
class TwigSimpleFileLoader implements \Twig_LoaderInterface
|
||
|
{
|
||
12 years ago
|
/**
|
||
|
* @var string Path to directory
|
||
|
*/
|
||
|
private $_dir;
|
||
|
|
||
12 years ago
|
/**
|
||
|
* @param string $dir path to directory
|
||
12 years ago
|
*/
|
||
|
public function __construct($dir)
|
||
|
{
|
||
12 years ago
|
$this->_dir = $dir;
|
||
12 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Compare a file's freshness with previously stored timestamp
|
||
|
*
|
||
|
* @param $name string file name to check
|
||
|
* @param $time int timestamp to compare with
|
||
12 years ago
|
* @return boolean true if file is still fresh and not changes, false otherwise
|
||
12 years ago
|
*/
|
||
|
public function isFresh($name, $time)
|
||
|
{
|
||
12 years ago
|
return filemtime($this->getFilePath($name)) <= $time;
|
||
12 years ago
|
}
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Get the source of given file name
|
||
12 years ago
|
*
|
||
12 years ago
|
* @param string $name file name
|
||
12 years ago
|
* @return string contents of given file name
|
||
|
*/
|
||
|
public function getSource($name)
|
||
|
{
|
||
|
return file_get_contents($this->getFilePath($name));
|
||
|
}
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Get unique key that can represent this file uniquely among other files.
|
||
|
* @param string $name
|
||
12 years ago
|
* @return string
|
||
|
*/
|
||
|
public function getCacheKey($name)
|
||
|
{
|
||
|
return $this->getFilePath($name);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* internally used to get absolute path of given file name
|
||
12 years ago
|
* @param string $name file name
|
||
12 years ago
|
* @return string absolute path of file
|
||
|
*/
|
||
|
protected function getFilePath($name){
|
||
12 years ago
|
return $this->_dir . '/' . $name;
|
||
12 years ago
|
}
|
||
12 years ago
|
}
|