From 4a787059342f43abefd115bf1a054b6d41551df6 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 4 Apr 2013 00:29:17 +0400 Subject: [PATCH] Better phpdoc for view renderers, composite view renderer --- framework/renderers/CompositeViewRenderer.php | 56 +++++++++++++++++++++++++++ framework/renderers/SmartyViewRenderer.php | 15 +++++++ framework/renderers/TwigViewRenderer.php | 13 ++++++- 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 framework/renderers/CompositeViewRenderer.php diff --git a/framework/renderers/CompositeViewRenderer.php b/framework/renderers/CompositeViewRenderer.php new file mode 100644 index 0000000..a7fbcf3 --- /dev/null +++ b/framework/renderers/CompositeViewRenderer.php @@ -0,0 +1,56 @@ + + * @since 2.0 + */ +class CompositeViewRenderer extends ViewRenderer +{ + /** + * @var array a config array with the view renderer objects or the configuration arrays for + * creating the view renderers indexed by file extensions. + */ + public $renderers = array(); + + /** + * Renders a view file. + * + * This method is invoked by [[View]] whenever it tries to render a view. + * Child classes must implement this method to render the given view file. + * + * @param View $view the view object used for rendering the file. + * @param string $file the view file. + * @param array $params the parameters to be passed to the view file. + * + * @return string the rendering result + */ + public function render($view, $file, $params) + { + $ext = pathinfo($file, PATHINFO_EXTENSION); + + if($ext === 'php' || !isset($this->renderers[$ext])) { + return $view->renderPhpFile($file, $params); + } + else { + if (is_array($this->renderers[$ext])) { + $this->renderers[$ext] = Yii::createObject($this->renderers[$ext]); + } + return $this->renderers[$ext]->render($view, $file, $params); + } + } +} \ No newline at end of file diff --git a/framework/renderers/SmartyViewRenderer.php b/framework/renderers/SmartyViewRenderer.php index c2bb58c..92fa3f2 100644 --- a/framework/renderers/SmartyViewRenderer.php +++ b/framework/renderers/SmartyViewRenderer.php @@ -20,9 +20,24 @@ use \yii\base\ViewRenderer; */ class SmartyViewRenderer extends ViewRenderer { + /** + * @var string alias pointing to where Smarty code is located. + */ public $smartyDir = '@app/vendors/Smarty'; + + /** + * @var string alias pointing to where Smarty cache will be stored. + */ public $cacheDir = '@app/runtime/Smarty/cache'; + + /** + * @var string alias pointing to where Smarty compiled teamplates will be stored. + */ public $compileDir = '@app/runtime/Smarty/compile'; + + /** + * @var string file extension to use for template files + */ public $fileExtension = 'tpl'; /** @var \Smarty */ diff --git a/framework/renderers/TwigViewRenderer.php b/framework/renderers/TwigViewRenderer.php index e719ef1..d08ec99 100644 --- a/framework/renderers/TwigViewRenderer.php +++ b/framework/renderers/TwigViewRenderer.php @@ -20,12 +20,23 @@ use \yii\base\ViewRenderer; */ class TwigViewRenderer extends ViewRenderer { + /** + * @var string alias pointing to where Twig code is located. + */ public $twigDir = '@app/vendors/Twig'; + + /** + * @var string alias pointing to where Twig cache will be stored. + */ public $cacheDir = '@app/runtime/Twig/cache'; + + /** + * @var string file extension to use for template files. + */ public $fileExtension = 'twig'; /** - * @var array options + * @var array Twig options * @see http://twig.sensiolabs.org/doc/api.html#environment-options */ public $options = array();