1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | */ |
||
5 | |||
6 | namespace Mvc5\Plugins; |
||
7 | |||
8 | use Mvc5\Template\TemplateLayout; |
||
9 | use Mvc5\Template\TemplateModel; |
||
10 | |||
11 | use function constant; |
||
12 | use function defined; |
||
13 | |||
14 | use const Mvc5\{ LAYOUT, TEMPLATE_MODEL, VIEW_MODEL }; |
||
15 | |||
16 | trait View |
||
17 | { |
||
18 | /** |
||
19 | * @param array $vars |
||
20 | * @param string|null $template |
||
21 | * @param string $model |
||
22 | * @return TemplateLayout|mixed |
||
23 | */ |
||
24 | 1 | protected function layout(array $vars = [], string $template = null, string $model = LAYOUT) : TemplateLayout |
|
25 | { |
||
26 | 1 | return $this->model($vars, $template, $model); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param array $vars |
||
31 | * @param string|null $template |
||
32 | * @param string|null $model |
||
33 | * @return TemplateModel|mixed |
||
34 | */ |
||
35 | 6 | protected function model(array $vars = [], string $template = null, string $model = null) : TemplateModel |
|
36 | { |
||
37 | 6 | !$model && $model = defined('static::VIEW_MODEL') ? constant('static::VIEW_MODEL') : VIEW_MODEL; |
|
38 | |||
39 | 6 | !$template && defined('static::TEMPLATE') && $template = constant('static::TEMPLATE'); |
|
40 | |||
41 | 6 | $template && $vars[TEMPLATE_MODEL] = $template; |
|
42 | |||
43 | 6 | return !$vars ? $this->plugin($model) : $this->plugin($model)->with($vars); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param string|mixed $plugin |
||
48 | * @param array $args |
||
49 | * @param callable|null $callback |
||
50 | * @return mixed |
||
51 | */ |
||
52 | protected abstract function plugin($plugin, array $args = [], callable $callback = null); |
||
53 | |||
54 | /** |
||
55 | * @param string|null $template |
||
56 | * @param array $vars |
||
57 | * @return TemplateModel|mixed |
||
58 | */ |
||
59 | 3 | protected function view(string $template = null, array $vars = []) : TemplateModel |
|
60 | { |
||
61 | 3 | return $this->model($vars, $template); |
|
62 | } |
||
63 | } |
||
64 |