Skip to content

Commit

Permalink
Make twig-bridge optional
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Oct 6, 2023
1 parent 5aa461f commit ed8ec49
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
9 changes: 7 additions & 2 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"scan-files" : ["bin/twig-cs-fixer"],
"symbol-whitelist" : [
"Twig\\Extra\\Cache\\TokenParser\\CacheTokenParser",
"Symfony\\UX\\TwigComponent\\TwigComponentBundle"
"Symfony\\Bridge\\Twig\\TokenParser\\DumpTokenParser",
"Symfony\\Bridge\\Twig\\TokenParser\\FormThemeTokenParser",
"Symfony\\Bridge\\Twig\\TokenParser\\StopwatchTokenParser",
"Symfony\\Bridge\\Twig\\TokenParser\\TransDefaultDomainTokenParser",
"Symfony\\Bridge\\Twig\\TokenParser\\TransTokenParser",
"Symfony\\UX\\TwigComponent\\TwigComponentBundle",
"Twig\\Extra\\Cache\\TokenParser\\CacheTokenParser"
]
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"composer-runtime-api": "^2.0.0",
"symfony/console": "^5.4.9 || ^6.0",
"symfony/finder": "^5.4 || ^6.0",
"symfony/twig-bridge": "^5.4 || ^6.0",
"twig/twig": "^2.14.0 || ^3.0.5",
"webmozart/assert": "^1.10"
},
Expand All @@ -35,9 +34,10 @@
"phpunit/phpunit": "^9.5.26 || ^10.0.9",
"psalm/plugin-phpunit": "^0.18.4",
"psalm/plugin-symfony": "^5.0.0",
"rector/rector": "^0.17.0",
"rector/rector": "^0.18.0",
"symfony/filesystem": "^5.4 || ^6.0",
"symfony/process": "^5.4 || ^6.0",
"symfony/twig-bridge": "^5.4 || ^6.0",
"symfony/ux-twig-component": "^2.8.0",
"twig/cache-extra": "^3.2",
"vimeo/psalm": "^5.2.0"
Expand Down
21 changes: 15 additions & 6 deletions src/Environment/StubbedEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ public function __construct(
) {
parent::__construct(new ArrayLoader());

$this->addTokenParser(new DumpTokenParser());
$this->addTokenParser(new FormThemeTokenParser());
$this->addTokenParser(new StopwatchTokenParser(true));
$this->addTokenParser(new TransDefaultDomainTokenParser());
$this->addTokenParser(new TransTokenParser());

// Optional dependency
if (class_exists(DumpTokenParser::class)) {
$this->addTokenParser(new DumpTokenParser());
}
if (class_exists(FormThemeTokenParser::class)) {
$this->addTokenParser(new FormThemeTokenParser());
}
if (class_exists(StopwatchTokenParser::class)) {
$this->addTokenParser(new StopwatchTokenParser(true));
}
if (class_exists(TransDefaultDomainTokenParser::class)) {
$this->addTokenParser(new TransDefaultDomainTokenParser());
}
if (class_exists(TransTokenParser::class)) {
$this->addTokenParser(new TransTokenParser());
}
if (class_exists(CacheTokenParser::class)) {
$this->addTokenParser(new CacheTokenParser());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function generateDiff(string $contents, string $filePath): string
throw new LogicException('Cannot get the current working directory.');
}

$cwd = $cwd.\DIRECTORY_SEPARATOR;
$cwd .= \DIRECTORY_SEPARATOR;
if (str_starts_with($filePath, $cwd)) {
$filename = substr($filePath, \strlen($cwd));
} else {
Expand Down

0 comments on commit ed8ec49

Please sign in to comment.