Skip to content

Commit 3f704ce

Browse files
committed
fix: twig
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 43e8602 commit 3f704ce

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

scoper.inc.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,28 @@
2626
->notName('autoload.php')
2727
->in('vendor'),
2828
],
29+
'patchers' => [
30+
// patchers for twig
31+
static function (string $filePath, string $prefix, string $content): string {
32+
// correct use statements in generated templates
33+
if (preg_match('%twig/src/Node/ModuleNode\\.php$%', $filePath)) {
34+
return str_replace('"use Twig\\', '"use ' . str_replace('\\', '\\\\', $prefix) . '\\\\Twig\\', $content);
35+
}
36+
37+
// correctly scope function calls to twig_... globals (which will not be globals anymore) in strings
38+
if (strpos($filePath, 'twig/twig') !== false
39+
|| preg_match('/\\.php$/', $filePath)
40+
) {
41+
$content = preg_replace("/([^'\"])(_?twig_[a-z_0-9]+)\\(/", '${1}\\OCA\\Libresign\\Vendor\\\${2}(', $content);
42+
43+
$content = preg_replace("/'(_?twig_[a-z_0-9]+)([('])/", '\'\\OCA\\Libresign\\vendor\\\${1}${2}', $content);
44+
$content = preg_replace("/\"(_?twig_[a-z_0-9]+)([(\"])/", '"\\\\\\OCA\\\\\\Libresign\\\\\\Vendor\\\\\\\${1}${2}', $content);
45+
46+
$content = preg_replace("/([^\\\\])(_?twig_[a-z_0-9]+)\(\"/", '${1}\\\\\\OCA\\\\\\Libresign\\\\\\Vendor\\\\\\\${2}("', $content);
47+
$content = preg_replace("/([^\\\\])(_?twig_[a-z_0-9]+)\('/", '${1}\\OCA\\Libresign\\Vendor\\\${2}(\'', $content);
48+
}
49+
50+
return $content;
51+
},
52+
],
2953
];

0 commit comments

Comments
 (0)