Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make twig-bridge optional #134

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link

@MauricioFauth MauricioFauth Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also add this to the suggest section of composer.json.

"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