Class 'Twig_Loader_Filesystem' not found
As the title says, I have followed the code line by line up till page 69 of the book and I get hit by the above statement.
Found the issue, the use of the Twig_Loader_Filesystem has been deprecated since Twig version 2.7, is there anyway the book can be updated to reflect on this issue? I do not expect to troubleshoot such items when working through a book. Specially one as good as this one.
Add the same issue.
Solved it with:
src/Framework/Rendering/TwigTemplateRenderer.php
<?php declare(strict_types=1);
namespace SocialNews\Framework\Rendering;
use \Twig\Environment;
final class TwigTemplateRenderer implements TemplateRenderer
{
private $twigEnvironment;
public function __construct(Environment $twigEnvironment)
{
$this->twigEnvironment = $twigEnvironment;
}
public function render(string $template, array $data = []): string
{
return $this->twigEnvironment->render($template, $data);
}
}
src/Framework/Rendering/TwigTemplateRendererFactory.php
<?php declare(strict_types=1);
namespace SocialNews\Framework\Rendering;
use \Twig\Loader\FilesystemLoader;
use \Twig\Environment;
final class TwigTemplateRendererFactory
{
public function create(): TwigTemplateRenderer
{
$loader = new FilesystemLoader();
$twigEnviroment = new Environment($loader);
return new TwigTemplateRenderer($twigEnviroment);
}
}
Hope it helps someone else.
@NCSantos was a huge help but I still was having issues (might be a me thing). Looking at Twig it required the template directory as a string. In src/Framework/Rendering/TwigTemplateRendererFactory.php I added the toString()function from TemplateDirectory.php to the argument variable:
public function create(): TwigTemplateRenderer
{
$loader = new FilesystemLoader($this->templateDirectory->toString());
....
}
Maybe a better way to do it, but it fixed it for me. This is an addition to what @NCSantos posted above.
@themagicteeth thanks much, solved it for me. I was stuck on page 83 (value objects).