|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Blitz PHP framework. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2022 Dimitri Sitchet Tomkeu <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace BlitzPHP\View\Adapters; |
|
13
|
|
|
|
|
14
|
|
|
use Jenssegers\Blade\Blade; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class BladeAdapter extends AbstractAdapter |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritDoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
protected string $ext = 'blade.php'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Instance Blade |
|
25
|
|
|
* |
|
26
|
|
|
* @var Blade |
|
27
|
|
|
*/ |
|
28
|
|
|
private $engine; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritDoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(protected array $config, $viewPathLocator = null, protected bool $debug = BLITZ_DEBUG) |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct($config, $viewPathLocator, $debug); |
|
36
|
|
|
|
|
37
|
|
|
$this->engine = new Blade( |
|
38
|
|
|
$this->viewPath ?: VIEW_PATH, |
|
39
|
|
|
$this->config['cache_path'] ?? VIEW_CACHE_PATH . 'blade' . DIRECTORY_SEPARATOR |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$this->configure(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritDoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
public function render(string $view, ?array $options = null, ?bool $saveData = null): string |
|
49
|
|
|
{ |
|
50
|
|
|
$view = str_replace([$this->viewPath, ' '], '', $view); |
|
51
|
|
|
|
|
52
|
|
|
$this->renderVars['start'] = microtime(true); |
|
53
|
|
|
|
|
54
|
|
|
$this->renderVars['view'] = $view; |
|
55
|
|
|
$this->renderVars['options'] = $options ?? []; |
|
56
|
|
|
|
|
57
|
|
|
$this->renderVars['file'] = $this->getRenderedFile($options, $this->renderVars['view'], $this->ext); |
|
58
|
|
|
|
|
59
|
|
|
$output = $this->engine->render($this->renderVars['view'], $this->data); |
|
60
|
|
|
|
|
61
|
|
|
$this->logPerformance($this->renderVars['start'], microtime(true), $this->renderVars['view']); |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
return $this->decorate($output); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Configure le moteur de template |
|
68
|
|
|
*/ |
|
69
|
|
|
private function configure(): void |
|
70
|
|
|
{ |
|
71
|
|
|
if (isset($this->config['configure']) && is_callable($this->config['configure'])) { |
|
72
|
|
|
$newInstance = $this->config['configure']($this->engine); |
|
73
|
|
|
if ($newInstance instanceof Blade) { |
|
74
|
|
|
$this->engine = $newInstance; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$directives = (array) ($this->config['directives'] ?? []); |
|
79
|
|
|
|
|
80
|
|
|
foreach ($directives as $name => $callable) { |
|
81
|
|
|
if (is_callable($callable)) { |
|
82
|
|
|
$this->engine->directive($name, $callable); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$if = (array) ($this->config['if'] ?? []); |
|
87
|
|
|
|
|
88
|
|
|
foreach ($if as $name => $callable) { |
|
89
|
|
|
if (is_callable($callable)) { |
|
90
|
|
|
$this->engine->if($name, $callable); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths