1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
5
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
6
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
7
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
8
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
9
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
10
|
|
|
* THE SOFTWARE. |
11
|
|
|
* |
12
|
|
|
* This software consists of voluntary contributions made by many individuals |
13
|
|
|
* and is licensed under the MIT license. |
14
|
|
|
* |
15
|
|
|
* Copyright (c) 2014-2016 Yuuki Takezawa |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Ytake\LaravelSmarty\Engines; |
20
|
|
|
|
21
|
|
|
use Illuminate\View\View; |
22
|
|
|
use Ytake\LaravelSmarty\SmartyFactory; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class SmartyTemplate |
26
|
|
|
* |
27
|
|
|
* @author yuuki.takezawa <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
29
|
|
|
*/ |
30
|
|
|
class SmartyTemplate extends \Smarty_Internal_Template |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function _subTemplateRegister() |
36
|
|
|
{ |
37
|
|
|
foreach ($this->compiled->includes as $name => $count) { |
38
|
|
|
// @codeCoverageIgnoreStart |
39
|
|
|
if (isset($this->smarty->_cache['subTplInfo'][$name])) { |
40
|
|
|
$this->smarty->_cache['subTplInfo'][$name] += $count; |
41
|
|
|
} else { |
42
|
|
|
$this->smarty->_cache['subTplInfo'][$name] = $count; |
43
|
|
|
} |
44
|
|
|
// @codeCoverageIgnoreEnd |
45
|
|
|
$this->dispatch(new self($name, $this->smarty)); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \Smarty_Internal_Template $template |
51
|
|
|
*/ |
52
|
|
|
protected function dispatch(\Smarty_Internal_Template $template) |
53
|
|
|
{ |
54
|
|
|
/** @var SmartyFactory $viewFactory */ |
55
|
|
|
$viewFactory = $this->smarty->getViewFactory(); |
56
|
|
|
$name = $this->normalizeName($template, $viewFactory); |
57
|
|
|
$view = new View( |
58
|
|
|
$viewFactory, |
59
|
|
|
$viewFactory->getEngineResolver()->resolve('smarty'), |
60
|
|
|
$name, |
61
|
|
|
$template->source->filepath, |
62
|
|
|
[] |
63
|
|
|
); |
64
|
|
|
$viewFactory->callCreator($view); |
65
|
|
|
$viewFactory->callComposer($view); |
66
|
|
|
foreach ($view->getData() as $key => $data) { |
67
|
|
|
$this->assign($key, $data); |
68
|
|
|
} |
69
|
|
|
unset($template); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param \Smarty_Internal_Template $template |
74
|
|
|
* @param SmartyFactory $viewFactory |
75
|
|
|
* |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
protected function normalizeName( |
79
|
|
|
\Smarty_Internal_Template $template, |
80
|
|
|
SmartyFactory $viewFactory |
81
|
|
|
) { |
82
|
|
|
$name = str_replace('.' . $viewFactory->getSmartyFileExtension(), '', $template->source->name); |
83
|
|
|
|
84
|
|
|
return str_replace('/', '.', $name); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|