Skip to content

Commit

Permalink
Check Twig environment on demand. Fix #46.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-teck committed Oct 11, 2020
1 parent e2a2990 commit 49f4ce1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"symfony/filesystem": "^2.7 || ^3.4 || ^4.0",
"twig/twig": "^1.41 || ^2.12"
},
"conflict": {
"drush/drush": "< 10.3.2"
},
"bin": [
"bin/dcg"
],
Expand Down
19 changes: 0 additions & 19 deletions src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,3 @@ function dcg_get_twig_environment($loader) {
}
return $environment;
}

// Determine major Twig version.
// \Twig\Environment::MAJOR_VERSION is not suitable here because of
// https://github.com/twigphp/Twig/pull/2945
// Use this workaround as drupal/drupal is locked on Twig 1.38.
list($twig_major_version) = sscanf(Environment::VERSION, '%d.%d.%d');

// \Twig\Environment::tokenize() signature has been changed in Twig 2, so that
// it is not possible to maintain the same \Twig\Environment sub-class for both
// Twig versions.
$twig_environment_class = sprintf('DrupalCodeGenerator\Twig\Twig%dEnvironment', $twig_major_version);
if (!class_exists('DrupalCodeGenerator\Twig\TwigEnvironment')) {
class_alias($twig_environment_class, 'DrupalCodeGenerator\Twig\TwigEnvironment');
}

// Legacy TwigEnvironment class is still used in Drush.
if (!class_exists('DrupalCodeGenerator\TwigEnvironment')) {
class_alias($twig_environment_class, 'DrupalCodeGenerator\TwigEnvironment');
}

0 comments on commit 49f4ce1

Please sign in to comment.