Skip to content
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
16 changes: 10 additions & 6 deletions src/Command/GenerateTypesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Parser;
use Twig\Environment;
use Twig\Extension\DebugExtension;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFilter;

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

$loader = new \Twig_Loader_Filesystem($templatePaths);
$twig = new \Twig_Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]);
$twig->addFilter(new \Twig_SimpleFilter('ucfirst', 'ucfirst'));
$twig->addFilter(new \Twig_SimpleFilter('pluralize', [Inflector::class, 'pluralize']));
$twig->addFilter(new \Twig_SimpleFilter('singularize', [Inflector::class, 'singularize']));
$loader = new FilesystemLoader($templatePaths);
$twig = new Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]);
$twig->addFilter(new TwigFilter('ucfirst', 'ucfirst'));
$twig->addFilter(new TwigFilter('pluralize', [Inflector::class, 'pluralize']));
$twig->addFilter(new TwigFilter('singularize', [Inflector::class, 'singularize']));

if ($processedConfiguration['debug']) {
$twig->addExtension(new \Twig_Extension_Debug());
$twig->addExtension(new DebugExtension());
}

$logger = new ConsoleLogger($output);
Expand Down
5 changes: 3 additions & 2 deletions src/TypesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PhpCsFixer\RuleSet;
use PhpCsFixer\Runner\Runner;
use Psr\Log\LoggerInterface;
use Twig\Environment;

/**
* Generates entity files.
Expand Down Expand Up @@ -57,7 +58,7 @@ class TypesGenerator
private const SCHEMA_ORG_SUPERSEDED_BY = 'schema:supersededBy';

/**
* @var \Twig_Environment
* @var Environment
*/
private $twig;

Expand Down Expand Up @@ -89,7 +90,7 @@ class TypesGenerator
/**
* @param \EasyRdf_Graph[] $graphs
*/
public function __construct(\Twig_Environment $twig, LoggerInterface $logger, array $graphs, CardinalitiesExtractor $cardinalitiesExtractor, GoodRelationsBridge $goodRelationsBridge)
public function __construct(Environment $twig, LoggerInterface $logger, array $graphs, CardinalitiesExtractor $cardinalitiesExtractor, GoodRelationsBridge $goodRelationsBridge)
{
if (!$graphs) {
throw new \InvalidArgumentException('At least one graph must be injected.');
Expand Down
3 changes: 2 additions & 1 deletion tests/TypesGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Psr\Log\NullLogger;
use Twig\Environment;

/**
* @author Teoh Han Hui <teohhanhui@gmail.com>
Expand All @@ -28,7 +29,7 @@ class TypesGeneratorTest extends TestCase
{
public function testGenerate(): void
{
$twigProphecy = $this->prophesize(\Twig_Environment::class);
$twigProphecy = $this->prophesize(Environment::class);
foreach ($this->getClasses() as $class) {
$twigProphecy->render('class.php.twig', Argument::that($this->getContextMatcher($class)))->willReturn()->shouldBeCalled();
}
Expand Down