init
This commit is contained in:
85
vendor/yiisoft/yii2-smarty/CHANGELOG.md
vendored
Normal file
85
vendor/yiisoft/yii2-smarty/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
Yii Framework 2 smarty extension Change Log
|
||||
===========================================
|
||||
|
||||
2.0.7 April 25, 2018
|
||||
--------------------
|
||||
|
||||
- Bug #23: Fixed widget registration and rendering code generation inside subtemplates (eymerich)
|
||||
- Enh #25: Give a choice to use SmartyBC class (a761208)
|
||||
|
||||
|
||||
2.0.6 March 18, 2017
|
||||
--------------------
|
||||
|
||||
- Bug #17: Updated Composer constraints to reflect the fact that it requires Smarty 3 (samdark)
|
||||
|
||||
|
||||
2.0.5 March 17, 2016
|
||||
--------------------
|
||||
|
||||
- Bug #12: Fixed SmartyException thrown when using multiple `{use}` for functions and blocks in inherited templates (freezy-sk)
|
||||
|
||||
|
||||
2.0.4 May 26, 2015
|
||||
------------------
|
||||
|
||||
- Bug #8: Fixed `functionRegisterJsFile` position parameter (TomassunGitHub, samdark)
|
||||
|
||||
2.0.3 March 01, 2015
|
||||
--------------------
|
||||
|
||||
- Bug #6845: Fixed incorrect implementation of `{registerCssFile` and `{registerJsFile` (TomassunGitHub, samdark)
|
||||
- Bug #6991: Fixed exception when using `{use class='yii\bootstrap\Nav' type='function'}` (ivanlemeshev)
|
||||
|
||||
|
||||
2.0.2 January 11, 2015
|
||||
----------------------
|
||||
|
||||
- no changes in this release.
|
||||
|
||||
|
||||
2.0.1 December 07, 2014
|
||||
-----------------------
|
||||
|
||||
- Bug #5748: `{path` was generating absolute URLs instead of relative ones (samdark, motzel)
|
||||
|
||||
|
||||
2.0.0 October 12, 2014
|
||||
----------------------
|
||||
|
||||
- no changes in this release.
|
||||
|
||||
|
||||
2.0.0-rc September 27, 2014
|
||||
---------------------------
|
||||
|
||||
- Enh #4619 (samdark, hwmaier)
|
||||
- New functions:
|
||||
- `url` generates absolute URL.
|
||||
- `set` allows setting commonly used view parameters: `title`, `theme` and `layout`.
|
||||
- `meta` registers meta tag.
|
||||
- `registerJsFile` registers JavaScript file.
|
||||
- `registerCssFile` registers CSS file.
|
||||
- `use` allows importing classes to the template and optionally provides these as functions and blocks.
|
||||
- New blocks:
|
||||
- `title`.
|
||||
- `description`.
|
||||
- `registerJs`.
|
||||
- `registerCss`.
|
||||
- New modifier `void` that allows calling functions and ignoring result.
|
||||
- Moved most of Yii custom syntax into `\yii\smarty\Extension` class that could be extended via `extensionClass` property.
|
||||
- Added ability to set Smarty options via config using `options`.
|
||||
- Added `imports` property that accepts an array of classes imported into template namespace.
|
||||
- Added `widgets` property that can be used to import widgets as Smarty tags.
|
||||
- `Yii::$app->params['paramKey']` values are now accessible as Smarty config variables `{#paramKey#}`.
|
||||
- Added ability to use Yii aliases in `extends` and `require`.
|
||||
|
||||
2.0.0-beta April 13, 2014
|
||||
-------------------------
|
||||
|
||||
- no changes in this release.
|
||||
|
||||
2.0.0-alpha, December 1, 2013
|
||||
-----------------------------
|
||||
|
||||
- Initial release.
|
||||
32
vendor/yiisoft/yii2-smarty/LICENSE.md
vendored
Normal file
32
vendor/yiisoft/yii2-smarty/LICENSE.md
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
The Yii framework is free software. It is released under the terms of
|
||||
the following BSD License.
|
||||
|
||||
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Yii Software LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
26
vendor/yiisoft/yii2-smarty/Makefile
vendored
Normal file
26
vendor/yiisoft/yii2-smarty/Makefile
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
# default versions to test against
|
||||
# these can be overridden by setting the environment variables in the shell
|
||||
PHP_VERSION=php-5.6.8
|
||||
YII_VERSION=dev-master
|
||||
|
||||
# ensure all the configuration variables above are in environment of the shell commands below
|
||||
export
|
||||
|
||||
help:
|
||||
@echo "make test - run phpunit tests using a docker environment"
|
||||
# @echo "make clean - stop docker and remove container"
|
||||
|
||||
test: docker-php
|
||||
composer require "yiisoft/yii2:${YII_VERSION}" --prefer-dist
|
||||
composer install --prefer-dist
|
||||
docker run --rm=true -v $(shell pwd):/opt/test yiitest/php:${PHP_VERSION} phpunit --verbose --color
|
||||
|
||||
docker-php: dockerfiles
|
||||
cd tests/docker/php && sh build.sh
|
||||
|
||||
dockerfiles:
|
||||
test -d tests/docker || git clone https://github.com/cebe/jenkins-test-docker tests/docker
|
||||
cd tests/docker && git checkout -- . && git pull
|
||||
mkdir -p tests/dockerids
|
||||
|
||||
61
vendor/yiisoft/yii2-smarty/README.md
vendored
Normal file
61
vendor/yiisoft/yii2-smarty/README.md
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<p align="center">
|
||||
<a href="https://www.smarty.net/" target="_blank">
|
||||
<img src="https://www.smarty.net/images/logo.png" height="74px">
|
||||
</a>
|
||||
<h1 align="center">Smarty Extension for Yii 2</h1>
|
||||
<br>
|
||||
</p>
|
||||
|
||||
This extension provides a `ViewRender` that would allow you to use [Smarty](http://www.smarty.net/) view template engine
|
||||
with [Yii framework 2.0](http://www.yiiframework.com).
|
||||
|
||||
For license information check the [LICENSE](LICENSE.md)-file.
|
||||
|
||||
Documentation is at [docs/guide/README.md](docs/guide/README.md).
|
||||
|
||||
[](https://packagist.org/packages/yiisoft/yii2-smarty)
|
||||
[](https://packagist.org/packages/yiisoft/yii2-smarty)
|
||||
[](https://travis-ci.org/yiisoft/yii2-smarty)
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
|
||||
|
||||
Either run
|
||||
|
||||
```
|
||||
php composer.phar require --prefer-dist yiisoft/yii2-smarty
|
||||
```
|
||||
|
||||
or add
|
||||
|
||||
```json
|
||||
"yiisoft/yii2-smarty": "~2.0.0"
|
||||
```
|
||||
|
||||
to the require section of your composer.json.
|
||||
|
||||
Note that the smarty composer package is distributed using subversion so you may need to install subversion.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
To use this extension, simply add the following code in your application configuration:
|
||||
|
||||
```php
|
||||
return [
|
||||
//....
|
||||
'components' => [
|
||||
'view' => [
|
||||
'renderers' => [
|
||||
'tpl' => [
|
||||
'class' => 'yii\smarty\ViewRenderer',
|
||||
//'cachePath' => '@runtime/Smarty/cache',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
```
|
||||
38
vendor/yiisoft/yii2-smarty/composer.json
vendored
Normal file
38
vendor/yiisoft/yii2-smarty/composer.json
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "yiisoft/yii2-smarty",
|
||||
"description": "The Smarty integration for the Yii framework",
|
||||
"keywords": ["yii2", "smarty", "renderer"],
|
||||
"type": "yii2-extension",
|
||||
"license": "BSD-3-Clause",
|
||||
"support": {
|
||||
"issues": "https://github.com/yiisoft/yii2-smarty/issues",
|
||||
"forum": "http://www.yiiframework.com/forum/",
|
||||
"wiki": "http://www.yiiframework.com/wiki/",
|
||||
"irc": "irc://irc.freenode.net/yii",
|
||||
"source": "https://github.com/yiisoft/yii2-smarty"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alexander Makarov",
|
||||
"email": "sam@rmcreative.ru"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"yiisoft/yii2": "~2.0.0",
|
||||
"smarty/smarty": "~3.1.0"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "https://asset-packagist.org"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {"yii\\smarty\\": "src"}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
438
vendor/yiisoft/yii2-smarty/src/Extension.php
vendored
Normal file
438
vendor/yiisoft/yii2-smarty/src/Extension.php
vendored
Normal file
@@ -0,0 +1,438 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\smarty;
|
||||
|
||||
use Smarty;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\StringHelper;
|
||||
use yii\helpers\Url;
|
||||
use yii\web\View;
|
||||
|
||||
/**
|
||||
* Extension provides Yii-specific syntax for Smarty templates.
|
||||
*
|
||||
* @author Alexander Makarov <sam@rmcreative.ru>
|
||||
* @author Henrik Maier <hwmaier@gmail.com>
|
||||
*/
|
||||
class Extension
|
||||
{
|
||||
/**
|
||||
* @var ViewRenderer
|
||||
*/
|
||||
protected $viewRenderer;
|
||||
/**
|
||||
* @var Smarty
|
||||
*/
|
||||
protected $smarty;
|
||||
|
||||
|
||||
/**
|
||||
* @param ViewRenderer $viewRenderer
|
||||
* @param Smarty $smarty
|
||||
*/
|
||||
public function __construct($viewRenderer, $smarty)
|
||||
{
|
||||
$this->viewRenderer = $viewRenderer;
|
||||
$smarty = $this->smarty = $smarty;
|
||||
|
||||
$smarty->registerPlugin('function', 'path', [$this, 'functionPath']);
|
||||
$smarty->registerPlugin('function', 'url', [$this, 'functionUrl']);
|
||||
$smarty->registerPlugin('function', 'set', [$this, 'functionSet']);
|
||||
$smarty->registerPlugin('function', 'meta', [$this, 'functionMeta']);
|
||||
$smarty->registerPlugin('function', 'registerJsFile', [$this, 'functionRegisterJsFile']);
|
||||
$smarty->registerPlugin('function', 'registerCssFile', [$this, 'functionRegisterCssFile']);
|
||||
$smarty->registerPlugin('block', 'title', [$this, 'blockTitle']);
|
||||
$smarty->registerPlugin('block', 'description', [$this, 'blockDescription']);
|
||||
$smarty->registerPlugin('block', 'registerJs', [$this, 'blockJavaScript']);
|
||||
$smarty->registerPlugin('block', 'registerCss', [$this, 'blockCss']);
|
||||
$smarty->registerPlugin('compiler', 'use', [$this, 'compilerUse']);
|
||||
$smarty->registerPlugin('modifier', 'void', [$this, 'modifierVoid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty template function to get relative URL for using in links
|
||||
*
|
||||
* Usage is the following:
|
||||
*
|
||||
* {path route='blog/view' alias=$post.alias user=$user.id}
|
||||
*
|
||||
* where route is Yii route and the rest of parameters are passed as is.
|
||||
*
|
||||
* @param array $params
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function functionPath($params, \Smarty_Internal_Template $template)
|
||||
{
|
||||
if (!isset($params['route'])) {
|
||||
trigger_error("path: missing 'route' parameter");
|
||||
}
|
||||
|
||||
array_unshift($params, $params['route']) ;
|
||||
unset($params['route']);
|
||||
|
||||
return Url::to($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty template function to get absolute URL for using in links
|
||||
*
|
||||
* Usage is the following:
|
||||
*
|
||||
* {url route='blog/view' alias=$post.alias user=$user.id}
|
||||
*
|
||||
* where route is Yii route and the rest of parameters are passed as is.
|
||||
*
|
||||
* @param array $params
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function functionUrl($params, \Smarty_Internal_Template $template)
|
||||
{
|
||||
if (!isset($params['route'])) {
|
||||
trigger_error("path: missing 'route' parameter");
|
||||
}
|
||||
|
||||
array_unshift($params, $params['route']) ;
|
||||
unset($params['route']);
|
||||
|
||||
return Url::to($params, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty compiler function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {use class="app\assets\AppAsset"}
|
||||
* {use class="yii\helpers\Html"}
|
||||
* {use class='yii\widgets\ActiveForm' type='block'}
|
||||
* {use class='@app\widgets\MyWidget' as='my_widget' type='function'}
|
||||
*
|
||||
* Supported attributes: class, as, type. Type defaults to 'static'.
|
||||
*
|
||||
* @param $params
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function compilerUse($params, $template)
|
||||
{
|
||||
if (!isset($params['class'])) {
|
||||
trigger_error("use: missing 'class' parameter");
|
||||
}
|
||||
// Compiler plugin parameters may include quotes, so remove them
|
||||
foreach ($params as $key => $value) {
|
||||
$params[$key] = trim($value, '\'""');
|
||||
}
|
||||
|
||||
$class = $params['class'];
|
||||
$alias = ArrayHelper::getValue($params, 'as', StringHelper::basename($params['class']));
|
||||
$type = ArrayHelper::getValue($params, 'type', 'static');
|
||||
|
||||
if (!isset($this->smarty->registered_plugins[$type][$alias])) {
|
||||
// Register the class during compile time
|
||||
$this->smarty->registerClass($alias, $class);
|
||||
|
||||
// Skip already registered block and function
|
||||
if ($type === 'block') {
|
||||
// Register widget tag during compile time
|
||||
$this->viewRenderer->widgets['blocks'][$alias] = $class;
|
||||
// Register widget tag during compile time
|
||||
$this->smarty->registerPlugin('block', $alias, [$this->viewRenderer, '_widget_block__' . $alias]);
|
||||
} elseif ($type === 'function') {
|
||||
// Register widget tag during compile time
|
||||
$this->viewRenderer->widgets['functions'][$alias] = $class;
|
||||
// Register widget tag during compile time
|
||||
$this->smarty->registerPlugin('function', $alias, [$this->viewRenderer, '_widget_function__' . $alias]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type === 'block') {
|
||||
// Inject code to re-register widget tag during run-time
|
||||
return <<<PHP
|
||||
<?php
|
||||
\$viewRenderer=\$_smarty_tpl->default_template_handler_func[0];
|
||||
\$viewRenderer->widgets['blocks']['$alias'] = '$class';
|
||||
try {
|
||||
\$_smarty_tpl->registerPlugin('block', '$alias', [\$viewRenderer, '_widget_block__$alias']);
|
||||
}
|
||||
catch (SmartyException \$e) {
|
||||
/* Ignore already registered exception during first execution after compilation */
|
||||
}
|
||||
?>
|
||||
PHP;
|
||||
} elseif ($type === 'function') {
|
||||
// Inject code to re-register widget tag during run-time
|
||||
return <<<PHP
|
||||
<?php
|
||||
\$viewRenderer=\$_smarty_tpl->default_template_handler_func[0];
|
||||
\$viewRenderer->widgets['functions']['$alias'] = '$class';
|
||||
try {
|
||||
\$_smarty_tpl->registerPlugin('function', '$alias', [\$viewRenderer, '_widget_function__$alias']);
|
||||
}
|
||||
catch (SmartyException \$e) {
|
||||
/* Ignore already registered exception during first execution after compilation */
|
||||
}
|
||||
?>
|
||||
PHP;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty modifier plugin
|
||||
* Converts any output to void
|
||||
* @param mixed $arg
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function modifierVoid($arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {set title="My Page"}
|
||||
* {set theme="frontend"}
|
||||
* {set layout="main.tpl"}
|
||||
*
|
||||
* Supported attributes: title, theme, layout
|
||||
*
|
||||
* @param $params
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function functionSet($params, $template)
|
||||
{
|
||||
if (isset($params['title'])) {
|
||||
$template->tpl_vars['this']->value->title = Yii::$app->getView()->title = ArrayHelper::remove($params, 'title');
|
||||
}
|
||||
if (isset($params['theme'])) {
|
||||
$template->tpl_vars['this']->value->theme = Yii::$app->getView()->theme = ArrayHelper::remove($params, 'theme');
|
||||
}
|
||||
if (isset($params['layout'])) {
|
||||
Yii::$app->controller->layout = ArrayHelper::remove($params, 'layout');
|
||||
}
|
||||
|
||||
// We must have consumed all allowed parameters now, otherwise raise error
|
||||
if (!empty($params)) {
|
||||
trigger_error('set: Unsupported parameter attribute');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {meta keywords="Yii,PHP,Smarty,framework"}
|
||||
*
|
||||
* Supported attributes: any; all attributes are passed as
|
||||
* parameter array to Yii's registerMetaTag function.
|
||||
*
|
||||
* @param $params
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function functionMeta($params, $template)
|
||||
{
|
||||
$key = isset($params['name']) ? $params['name'] : null;
|
||||
|
||||
Yii::$app->getView()->registerMetaTag($params, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty block function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {title} Web Site Login {/title}
|
||||
*
|
||||
* Supported attributes: none.
|
||||
*
|
||||
* @param $params
|
||||
* @param $content
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param $repeat
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function blockTitle($params, $content, $template, &$repeat)
|
||||
{
|
||||
if ($content !== null) {
|
||||
Yii::$app->getView()->title = $content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty block function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {description}
|
||||
* The text between the opening and closing tags is added as
|
||||
* meta description tag to the page output.
|
||||
* {/description}
|
||||
*
|
||||
* Supported attributes: none.
|
||||
*
|
||||
* @param $params
|
||||
* @param $content
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param $repeat
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function blockDescription($params, $content, $template, &$repeat)
|
||||
{
|
||||
if ($content !== null) {
|
||||
// Clean-up whitespace and newlines
|
||||
$content = preg_replace('/\s+/', ' ', trim($content));
|
||||
|
||||
Yii::$app->getView()->registerMetaTag(['name' => 'description',
|
||||
'content' => $content],
|
||||
'description');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {registerJsFile url='http://maps.google.com/maps/api/js?sensor=false' position='POS_END'}
|
||||
*
|
||||
* Supported attributes: url, key, depends, position and valid HTML attributes for the script tag.
|
||||
* Refer to Yii documentation for details.
|
||||
* The position attribute is passed as text without the class prefix.
|
||||
* Default is 'POS_END'.
|
||||
*
|
||||
* @param $params
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function functionRegisterJsFile($params, $template)
|
||||
{
|
||||
if (!isset($params['url'])) {
|
||||
trigger_error("registerJsFile: missing 'url' parameter");
|
||||
}
|
||||
|
||||
$url = ArrayHelper::remove($params, 'url');
|
||||
$key = ArrayHelper::remove($params, 'key', null);
|
||||
if (isset($params['position'])) {
|
||||
$params['position'] = $this->getViewConstVal($params['position'], View::POS_END);
|
||||
}
|
||||
|
||||
Yii::$app->getView()->registerJsFile($url, $params, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty block function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {registerJs key='show' position='POS_LOAD'}
|
||||
* $("span.show").replaceWith('<div class="show">');
|
||||
* {/registerJs}
|
||||
*
|
||||
* Supported attributes: key, position. Refer to Yii documentation for details.
|
||||
* The position attribute is passed as text without the class prefix.
|
||||
* Default is 'POS_READY'.
|
||||
*
|
||||
* @param $params
|
||||
* @param $content
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param $repeat
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function blockJavaScript($params, $content, $template, &$repeat)
|
||||
{
|
||||
if ($content !== null) {
|
||||
$key = isset($params['key']) ? $params['key'] : null;
|
||||
$position = isset($params['position']) ? $params['position'] : null;
|
||||
|
||||
Yii::$app->getView()->registerJs($content,
|
||||
$this->getViewConstVal($position, View::POS_READY),
|
||||
$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {registerCssFile url='@assets/css/normalizer.css'}
|
||||
*
|
||||
* Supported attributes: url, key, depends and valid HTML attributes for the link tag.
|
||||
* Refer to Yii documentation for details.
|
||||
*
|
||||
* @param $params
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function functionRegisterCssFile($params, $template)
|
||||
{
|
||||
if (!isset($params['url'])) {
|
||||
trigger_error("registerCssFile: missing 'url' parameter");
|
||||
}
|
||||
|
||||
$url = ArrayHelper::remove($params, 'url');
|
||||
$key = ArrayHelper::remove($params, 'key', null);
|
||||
|
||||
Yii::$app->getView()->registerCssFile($url, $params, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty block function plugin
|
||||
* Usage is the following:
|
||||
*
|
||||
* {registerCss}
|
||||
* div.header {
|
||||
* background-color: #3366bd;
|
||||
* color: white;
|
||||
* }
|
||||
* {/registerCss}
|
||||
*
|
||||
* Supported attributes: key and valid HTML attributes for the style tag.
|
||||
* Refer to Yii documentation for details.
|
||||
*
|
||||
* @param $params
|
||||
* @param $content
|
||||
* @param \Smarty_Internal_Template $template
|
||||
* @param $repeat
|
||||
* @return string
|
||||
* @note Even though this method is public it should not be called directly.
|
||||
*/
|
||||
public function blockCss($params, $content, $template, &$repeat)
|
||||
{
|
||||
if ($content !== null) {
|
||||
$key = isset($params['key']) ? $params['key'] : null;
|
||||
|
||||
Yii::$app->getView()->registerCss($content, $params, $key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to convert a textual constant identifier to a View class
|
||||
* integer constant value.
|
||||
*
|
||||
* @param string $string Constant identifier name
|
||||
* @param int $default Default value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getViewConstVal($string, $default)
|
||||
{
|
||||
$val = @constant('yii\web\View::' . $string);
|
||||
return isset($val) ? $val : $default;
|
||||
}
|
||||
}
|
||||
277
vendor/yiisoft/yii2-smarty/src/ViewRenderer.php
vendored
Normal file
277
vendor/yiisoft/yii2-smarty/src/ViewRenderer.php
vendored
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\smarty;
|
||||
|
||||
use Yii;
|
||||
use Smarty;
|
||||
use yii\web\View;
|
||||
use yii\base\Widget;
|
||||
use yii\base\ViewRenderer as BaseViewRenderer;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* SmartyViewRenderer allows you to use Smarty templates in views.
|
||||
*
|
||||
* @author Alexander Makarov <sam@rmcreative.ru>
|
||||
* @author Henrik Maier <hwmaier@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class ViewRenderer extends BaseViewRenderer
|
||||
{
|
||||
/**
|
||||
* @var string the directory or path alias pointing to where Smarty cache will be stored.
|
||||
*/
|
||||
public $cachePath = '@runtime/Smarty/cache';
|
||||
/**
|
||||
* @var string the directory or path alias pointing to where Smarty compiled templates will be stored.
|
||||
*/
|
||||
public $compilePath = '@runtime/Smarty/compile';
|
||||
/**
|
||||
* @var array Add additional directories to Smarty's search path for plugins.
|
||||
*/
|
||||
public $pluginDirs = [];
|
||||
/**
|
||||
* @var array Class imports similar to the use tag
|
||||
*/
|
||||
public $imports = [];
|
||||
/**
|
||||
* @var array Widget declarations
|
||||
*/
|
||||
public $widgets = ['functions' => [], 'blocks' => []];
|
||||
/**
|
||||
* @var array additional Smarty options
|
||||
* @see http://www.smarty.net/docs/en/api.variables.tpl
|
||||
*/
|
||||
public $options = [];
|
||||
/**
|
||||
* @var string extension class name
|
||||
*/
|
||||
public $extensionClass = '\yii\smarty\Extension';
|
||||
/**
|
||||
* @var string The Smarty class
|
||||
* @since 2.0.7
|
||||
*/
|
||||
public $smartyClass = '\Smarty';
|
||||
|
||||
/**
|
||||
* @var Smarty The Smarty object used for rendering
|
||||
*/
|
||||
protected $smarty;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates and configures the Smarty object.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->smarty = new $this->smartyClass();
|
||||
|
||||
$this->smarty->setCompileDir(Yii::getAlias($this->compilePath));
|
||||
$this->smarty->setCacheDir(Yii::getAlias($this->cachePath));
|
||||
|
||||
foreach ($this->options as $key => $value) {
|
||||
$this->smarty->$key = $value;
|
||||
}
|
||||
|
||||
$this->smarty->setTemplateDir([
|
||||
dirname(Yii::$app->getView()->getViewFile()),
|
||||
Yii::$app->getViewPath(),
|
||||
]);
|
||||
|
||||
// Add additional plugin dirs from configuration array, apply Yii's dir convention
|
||||
foreach ($this->pluginDirs as &$dir) {
|
||||
$dir = $this->resolveTemplateDir($dir);
|
||||
}
|
||||
$this->smarty->addPluginsDir($this->pluginDirs);
|
||||
|
||||
if (isset($this->imports)) {
|
||||
foreach(($this->imports) as $tag => $class) {
|
||||
$this->smarty->registerClass($tag, $class);
|
||||
}
|
||||
}
|
||||
// Register block widgets specified in configuration array
|
||||
if (isset($this->widgets['blocks'])) {
|
||||
foreach(($this->widgets['blocks']) as $tag => $class) {
|
||||
$this->smarty->registerPlugin('block', $tag, [$this, '_widget_block__' . $tag]);
|
||||
$this->smarty->registerClass($tag, $class);
|
||||
}
|
||||
}
|
||||
// Register function widgets specified in configuration array
|
||||
if (isset($this->widgets['functions'])) {
|
||||
foreach(($this->widgets['functions']) as $tag => $class) {
|
||||
$this->smarty->registerPlugin('function', $tag, [$this, '_widget_function__' . $tag]);
|
||||
$this->smarty->registerClass($tag, $class);
|
||||
}
|
||||
}
|
||||
|
||||
new $this->extensionClass($this, $this->smarty);
|
||||
|
||||
$this->smarty->default_template_handler_func = [$this, 'aliasHandler'];
|
||||
}
|
||||
|
||||
/**
|
||||
* The directory can be specified in Yii's standard convention
|
||||
* using @, // and / prefixes or no prefix for view relative directories.
|
||||
*
|
||||
* @param string $dir directory name to be resolved
|
||||
* @return string the resolved directory name
|
||||
*/
|
||||
protected function resolveTemplateDir($dir)
|
||||
{
|
||||
if (strncmp($dir, '@', 1) === 0) {
|
||||
// e.g. "@app/views/dir"
|
||||
$dir = Yii::getAlias($dir);
|
||||
} elseif (strncmp($dir, '//', 2) === 0) {
|
||||
// e.g. "//layouts/dir"
|
||||
$dir = Yii::$app->getViewPath() . DIRECTORY_SEPARATOR . ltrim($dir, '/');
|
||||
} elseif (strncmp($dir, '/', 1) === 0) {
|
||||
// e.g. "/site/dir"
|
||||
if (Yii::$app->controller !== null) {
|
||||
$dir = Yii::$app->controller->module->getViewPath() . DIRECTORY_SEPARATOR . ltrim($dir, '/');
|
||||
} else {
|
||||
// No controller, what to do?
|
||||
}
|
||||
} else {
|
||||
// relative to view file
|
||||
$dir = dirname(Yii::$app->getView()->getViewFile()) . DIRECTORY_SEPARATOR . $dir;
|
||||
}
|
||||
|
||||
return $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mechanism to pass a widget's tag name to the callback function.
|
||||
*
|
||||
* Using a magic function call would not be necessary if Smarty would
|
||||
* support closures. Smarty closure support is announced for 3.2,
|
||||
* until its release magic function calls are used to pass the
|
||||
* tag name to the callback.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @throws InvalidConfigException
|
||||
* @throws \BadMethodCallException
|
||||
* @return string
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$methodInfo = explode('__', $method);
|
||||
if (count($methodInfo) === 2) {
|
||||
$alias = $methodInfo[1];
|
||||
if (isset($this->widgets['functions'][$alias])) {
|
||||
if (($methodInfo[0] === '_widget_function') && (count($args) === 2)) {
|
||||
return $this->widgetFunction($this->widgets['functions'][$alias], $args[0], $args[1]);
|
||||
}
|
||||
} elseif (isset($this->widgets['blocks'][$alias])) {
|
||||
if (($methodInfo[0] === '_widget_block') && (count($args) === 4)) {
|
||||
return $this->widgetBlock($this->widgets['blocks'][$alias], $args[0], $args[1], $args[2], $args[3]);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidConfigException('Widget "' . $alias . '" not declared.');
|
||||
}
|
||||
}
|
||||
|
||||
throw new \BadMethodCallException('Method does not exist: ' . $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty plugin callback function to support widget as Smarty blocks.
|
||||
* This function is not called directly by Smarty but through a
|
||||
* magic __call wrapper.
|
||||
*
|
||||
* Example usage is the following:
|
||||
*
|
||||
* {ActiveForm assign='form' id='login-form'}
|
||||
* {$form->field($model, 'username')}
|
||||
* {$form->field($model, 'password')->passwordInput()}
|
||||
* <div class="form-group">
|
||||
* <input type="submit" value="Login" class="btn btn-primary" />
|
||||
* </div>
|
||||
* {/ActiveForm}
|
||||
*/
|
||||
private function widgetBlock($class, $params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
// Check if this is the opening ($content is null) or closing tag.
|
||||
if ($content === null) {
|
||||
$params['class'] = $class;
|
||||
// Figure out where to put the result of the widget call, if any
|
||||
$assign = ArrayHelper::remove($params, 'assign', false);
|
||||
ob_start();
|
||||
ob_implicit_flush(false);
|
||||
$widget = Yii::createObject($params);
|
||||
Widget::$stack[] = $widget;
|
||||
if ($assign) {
|
||||
$template->assign($assign, $widget);
|
||||
}
|
||||
} else {
|
||||
$widget = array_pop(Widget::$stack);
|
||||
echo $content;
|
||||
$out = $widget->run();
|
||||
return ob_get_clean() . $out;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty plugin callback function to support widgets as Smarty functions.
|
||||
* This function is not called directly by Smarty but through a
|
||||
* magic __call wrapper.
|
||||
*
|
||||
* Example usage is the following:
|
||||
*
|
||||
* {GridView dataProvider=$provider}
|
||||
*
|
||||
*/
|
||||
private function widgetFunction($class, $params, \Smarty_Internal_Template $template)
|
||||
{
|
||||
$repeat = false;
|
||||
$this->widgetBlock($class, $params, null, $template, $repeat); // $widget->init(...)
|
||||
return $this->widgetBlock($class, $params, '', $template, $repeat); // $widget->run()
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
/* @var $template \Smarty_Internal_Template */
|
||||
$template = $this->smarty->createTemplate($file, null, null, empty($params) ? null : $params, false);
|
||||
|
||||
// Make Yii params available as smarty config variables
|
||||
$template->config_vars = Yii::$app->params;
|
||||
|
||||
$template->assign('app', \Yii::$app);
|
||||
$template->assign('this', $view);
|
||||
|
||||
return $template->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves Yii alias into file path
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $name
|
||||
* @param string $content
|
||||
* @param string $modified
|
||||
* @param Smarty $smarty
|
||||
* @return bool|string path to file or false if it's not found
|
||||
*/
|
||||
public function aliasHandler($type, $name, &$content, &$modified, Smarty $smarty)
|
||||
{
|
||||
$file = Yii::getAlias($name);
|
||||
return is_file($file) ? $file : false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user