Browse Source

fixes code style.

tags/2.0.0-beta
dev-meghraj 11 years ago
parent
commit
b1a1458d70
  1. 2
      extensions/yii/twig/CHANGELOG.md
  2. 60
      extensions/yii/twig/TwigSimpleFileLoader.php
  3. 5
      extensions/yii/twig/ViewRenderer.php
  4. 7
      extensions/yii/twig/ViewRendererStaticClassProxy.php

2
extensions/yii/twig/CHANGELOG.md

@ -5,9 +5,9 @@ Yii Framework 2 twig extension Change Log
----------------------------
- no changes in this release.
- Add File based Twig loader for better caching and usability of twig's file based function
2.0.0 alpha, December 1, 2013
-----------------------------
- Initial release.
- Add more features like in old and file based loader for twig files

60
extensions/yii/twig/TwigSimpleFileLoader.php

@ -1,9 +1,17 @@
<?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
* Twig view file loader class.
*
* @author dev-mraj <dev.meghraj@gmail.com>
* @version 1.0.0
@ -11,26 +19,58 @@ namespace yii\twig;
class TwigSimpleFileLoader implements \Twig_LoaderInterface {
/**
* Path to directory where all file exists
* @var string
* @var string Path to directory
*/
private $dir;
private $_dir;
public function __construct($dir){
$this->dir=$dir;
/*
* @param @dir string path to directory
*/
public function __construct($dir)
{
$this->_dir=$dir;
}
public function isFresh($name, $time){
/**
* 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;
}
public function getSource($name){
/**
* 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));
}
public function getCacheKey($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;
return $this->_dir.'/'.$name;
}
}

5
extensions/yii/twig/ViewRenderer.php

@ -13,6 +13,7 @@ use Yii;
use yii\base\View;
use yii\base\ViewRenderer as BaseViewRenderer;
use yii\helpers\Html;
use yii\twig\TwigSimpleFileLoader;
/**
* TwigViewRenderer allows you to use Twig templates in views.
@ -76,7 +77,7 @@ class ViewRenderer extends BaseViewRenderer
public $lexerOptions = [];
/**
* @var \Twig_Environment
* @var \Twig_Environment twig environment object that do all rendering twig templates
*/
public $twig;
@ -85,7 +86,6 @@ class ViewRenderer extends BaseViewRenderer
$this->twig = new \Twig_Environment(null, array_merge([
'cache' => Yii::getAlias($this->cachePath),
'auto_reload' => true,
'charset' => Yii::$app->charset,
], $this->options));
@ -95,6 +95,7 @@ class ViewRenderer extends BaseViewRenderer
$this->twig->addExtension(new $extension());
}
}
// Adding custom globals (objects or static classes)
if (!empty($this->globals)) {
$this->addGlobals($this->globals);

7
extensions/yii/twig/ViewRendererStaticClassProxy.php

@ -1,4 +1,11 @@
<?php
/**
* Twig view renderer class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\twig;

Loading…
Cancel
Save