-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
CompileInclude.php
97 lines (86 loc) · 2.61 KB
/
CompileInclude.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*
* Copyright (c) 2014-2016 Yuuki Takezawa
*
*/
namespace Ytake\LaravelSmarty\Compilers;
use Illuminate\View\View;
use Illuminate\Contracts\View\Factory;
/**
* Class CompileInclude
*
* @author yuuki.takezawa <yuuki.takezawa@comnect.jp.net>
* @license http://opensource.org/licenses/MIT MIT
*/
class CompileInclude extends \Smarty_Internal_Compile_Include implements Compilable
{
/** @var Factory|\Ytake\LaravelSmarty\SmartyFactory */
protected $viewFactory;
/** @var array */
protected $laravelViewData;
/**
* {@inheritdoc}
*/
public function compile($args, \Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter)
{
foreach ($args as $arg) {
if (isset($arg['file'])) {
$viewName = $this->normalizeTemplateName($arg['file']);
$this->dispatch($viewName);
}
}
return parent::compile($args, $compiler, $parameter);
}
/**
* @param Factory $factory
*/
public function setViewFactory(Factory $factory)
{
$this->viewFactory = $factory;
}
/**
* @param array $data
*/
public function setLaravelViewData(array $data)
{
$this->laravelViewData = $data;
}
/**
* @param string $name
*
* @return string
*/
protected function normalizeTemplateName($name)
{
$fileInfo = new \SplFileInfo($name);
$path = ($fileInfo->getPath() === '') ? null : $fileInfo->getPath() . '/';
$viewPathInfo = $path . $fileInfo->getBasename('.' . $fileInfo->getExtension());
return trim(str_replace('/', '.', $viewPathInfo), '"');
}
/**
* @param $name
*/
protected function dispatch($name)
{
$view = new View(
$this->viewFactory,
$this->viewFactory->getEngineResolver()->resolve('smarty'),
$name,
null,
[]
);
$this->viewFactory->callCreator($view);
$this->viewFactory->callComposer($view);
}
}