Skip to content

Commit 37bdcc7

Browse files
authored
Merge pull request #175 from maxhelias/deprecated-twig
Replacement of Twig depreciation
2 parents 0a4cb6c + 02b8e66 commit 37bdcc7

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/Command/GenerateTypesCommand.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
use Symfony\Component\Console\Logger\ConsoleLogger;
2626
use Symfony\Component\Console\Output\OutputInterface;
2727
use Symfony\Component\Yaml\Parser;
28+
use Twig\Environment;
29+
use Twig\Extension\DebugExtension;
30+
use Twig\Loader\FilesystemLoader;
31+
use Twig\TwigFilter;
2832

2933
/**
3034
* Generate entities command.
@@ -149,14 +153,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
149153
$templatePaths = $processedConfiguration['generatorTemplates'];
150154
$templatePaths[] = __DIR__.'/../../templates/';
151155

152-
$loader = new \Twig_Loader_Filesystem($templatePaths);
153-
$twig = new \Twig_Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]);
154-
$twig->addFilter(new \Twig_SimpleFilter('ucfirst', 'ucfirst'));
155-
$twig->addFilter(new \Twig_SimpleFilter('pluralize', [Inflector::class, 'pluralize']));
156-
$twig->addFilter(new \Twig_SimpleFilter('singularize', [Inflector::class, 'singularize']));
156+
$loader = new FilesystemLoader($templatePaths);
157+
$twig = new Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]);
158+
$twig->addFilter(new TwigFilter('ucfirst', 'ucfirst'));
159+
$twig->addFilter(new TwigFilter('pluralize', [Inflector::class, 'pluralize']));
160+
$twig->addFilter(new TwigFilter('singularize', [Inflector::class, 'singularize']));
157161

158162
if ($processedConfiguration['debug']) {
159-
$twig->addExtension(new \Twig_Extension_Debug());
163+
$twig->addExtension(new DebugExtension());
160164
}
161165

162166
$logger = new ConsoleLogger($output);

src/TypesGenerator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use PhpCsFixer\RuleSet;
2727
use PhpCsFixer\Runner\Runner;
2828
use Psr\Log\LoggerInterface;
29+
use Twig\Environment;
2930

3031
/**
3132
* Generates entity files.
@@ -57,7 +58,7 @@ class TypesGenerator
5758
private const SCHEMA_ORG_SUPERSEDED_BY = 'schema:supersededBy';
5859

5960
/**
60-
* @var \Twig_Environment
61+
* @var Environment
6162
*/
6263
private $twig;
6364

@@ -89,7 +90,7 @@ class TypesGenerator
8990
/**
9091
* @param \EasyRdf_Graph[] $graphs
9192
*/
92-
public function __construct(\Twig_Environment $twig, LoggerInterface $logger, array $graphs, CardinalitiesExtractor $cardinalitiesExtractor, GoodRelationsBridge $goodRelationsBridge)
93+
public function __construct(Environment $twig, LoggerInterface $logger, array $graphs, CardinalitiesExtractor $cardinalitiesExtractor, GoodRelationsBridge $goodRelationsBridge)
9394
{
9495
if (!$graphs) {
9596
throw new \InvalidArgumentException('At least one graph must be injected.');

tests/TypesGeneratorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PHPUnit\Framework\TestCase;
2121
use Prophecy\Argument;
2222
use Psr\Log\NullLogger;
23+
use Twig\Environment;
2324

2425
/**
2526
* @author Teoh Han Hui <[email protected]>
@@ -28,7 +29,7 @@ class TypesGeneratorTest extends TestCase
2829
{
2930
public function testGenerate(): void
3031
{
31-
$twigProphecy = $this->prophesize(\Twig_Environment::class);
32+
$twigProphecy = $this->prophesize(Environment::class);
3233
foreach ($this->getClasses() as $class) {
3334
$twigProphecy->render('class.php.twig', Argument::that($this->getContextMatcher($class)))->willReturn()->shouldBeCalled();
3435
}

0 commit comments

Comments
 (0)