Skip to content

Commit 53e5e9a

Browse files
committed
Обработка namespaces Твига
1 parent fbf3e54 commit 53e5e9a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Services/Twig/TwigService.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,30 @@ public function addPath(string $path) : void
118118
* @param string $cachePath Путь к кэшу (серверный).
119119
*
120120
* @return Environment
121+
* @throws LoaderError Ошибки Твига.
121122
*/
122123
private function initTwig(
123124
FilesystemLoader $loader,
124125
string $debug,
125126
string $cachePath
126127
) : Environment {
127128

129+
$allPaths = $loader->getPaths();
130+
131+
if (array_key_exists('paths', $this->twigOptions)) {
132+
foreach ($this->twigOptions['paths'] as $path => $namespace) {
133+
if (in_array(trim($path), $allPaths, true)) {
134+
continue;
135+
}
136+
137+
if (!$namespace) {
138+
$loader->addPath($path);
139+
} else {
140+
$loader->addPath($path, $namespace);
141+
}
142+
}
143+
}
144+
128145
return new Environment(
129146
$loader,
130147
[

0 commit comments

Comments
 (0)