Alexander Makarov
11 years ago
4 changed files with 288 additions and 11 deletions
@ -0,0 +1,76 @@
|
||||
<?php |
||||
/** |
||||
* 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/ |
||||
*/ |
||||
|
||||
namespace yii\twig; |
||||
|
||||
|
||||
/** |
||||
* Twig view file loader class. |
||||
* |
||||
* @author dev-mraj <dev.meghraj@gmail.com> |
||||
* @version 1.0.0 |
||||
*/ |
||||
class TwigSimpleFileLoader implements \Twig_LoaderInterface { |
||||
|
||||
/** |
||||
* @var string Path to directory |
||||
*/ |
||||
private $_dir; |
||||
|
||||
/* |
||||
* @param @dir string path to directory |
||||
*/ |
||||
public function __construct($dir) |
||||
{ |
||||
$this->_dir=$dir; |
||||
} |
||||
|
||||
/** |
||||
* Compare a file's freshness with previously stored timestamp |
||||
* |
||||
* @param $name string file name to check |
||||
* @param $time int timestamp to compare with |
||||
* @return bool true if file is still fresh and not changes, false otherwise |
||||
*/ |
||||
public function isFresh($name, $time) |
||||
{ |
||||
return filemtime($this->getFilePath($name))<=$time; |
||||
} |
||||
|
||||
/** |
||||
* get the source of given file name |
||||
* |
||||
* @param $name string file name |
||||
* @return string contents of given file name |
||||
*/ |
||||
public function getSource($name) |
||||
{ |
||||
return file_get_contents($this->getFilePath($name)); |
||||
} |
||||
|
||||
/** |
||||
* get a unique key that can represent this file uniquely among other files. |
||||
* @param $name |
||||
* @return string |
||||
*/ |
||||
public function getCacheKey($name) |
||||
{ |
||||
return $this->getFilePath($name); |
||||
} |
||||
|
||||
/** |
||||
* internally used to get absolute path of given file name |
||||
* @param $name string file name |
||||
* @return string absolute path of file |
||||
*/ |
||||
protected function getFilePath($name){ |
||||
return $this->_dir.'/'.$name; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
<?php |
||||
/** |
||||
* Twig view renderer class file. |
||||
* |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright © 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\twig; |
||||
|
||||
/** |
||||
* Class-proxy for static classes |
||||
* Needed because you can't pass static class to Twig other way |
||||
* |
||||
* @author Leonid Svyatov <leonid@svyatov.ru> |
||||
* @version 1.0.0 |
||||
*/ |
||||
class ViewRendererStaticClassProxy |
||||
{ |
||||
private $_staticClassName; |
||||
|
||||
public function __construct($staticClassName) { |
||||
$this->_staticClassName = $staticClassName; |
||||
} |
||||
|
||||
public function __get($property) |
||||
{ |
||||
$class = new \ReflectionClass($this->_staticClassName); |
||||
return $class->getStaticPropertyValue($property); |
||||
} |
||||
|
||||
public function __set($property, $value) |
||||
{ |
||||
$class = new \ReflectionClass($this->_staticClassName); |
||||
$class->setStaticPropertyValue($property, $value); |
||||
return $value; |
||||
} |
||||
|
||||
public function __call($method, $arguments) |
||||
{ |
||||
return call_user_func_array(array($this->_staticClassName, $method), $arguments); |
||||
} |
||||
} |
Loading…
Reference in new issue