Update view factory. Add resource helper

This commit is contained in:
Maarten 2019-12-23 19:06:04 +01:00
parent 94ea72f26a
commit 246bbed148
4 changed files with 72 additions and 11 deletions

View file

@ -0,0 +1,60 @@
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* index.html */
class __TwigTemplate_bf30eb136d2e22dbcb7cf9e2f19821922b265e36f499d6793628eeb72c34338a extends Template
{
private $source;
private $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->parent = false;
$this->blocks = [
];
}
protected function doDisplay(array $context, array $blocks = [])
{
$macros = $this->macros;
// line 1
echo "Werkt het: ";
echo twig_escape_filter($this->env, ($context["test"] ?? null), "html", null, true);
}
public function getTemplateName()
{
return "index.html";
}
public function isTraitable()
{
return false;
}
public function getDebugInfo()
{
return array ( 37 => 1,);
}
public function getSourceContext()
{
return new Source("", "index.html", "C:\\Users\\maart\\PhpstormProjects\\framework\\resources\\views\\index.html");
}
}

View file

@ -44,4 +44,12 @@ class BootstrapFactory {
return null;
}
/**
* @return string
*/
public function resourcePath()
{
return "../resources/";
}
}

View file

@ -7,12 +7,12 @@ if(!function_exists('app'))
{
/**
* @param null $abstract
* @return mixed|Container
* @return \Runtime\Factory\BootstrapFactory|Container
*/
function app($abstract = null)
{
if (is_null($abstract)) {
Bootstrap::getInstance();
return Bootstrap::getInstance();
}
return Bootstrap::getInstance()->make($abstract);

View file

@ -3,22 +3,15 @@
namespace Runtime\Http\Views;
use ClassNotFoundException;
use Runtime\Exceptions\ExceptionHandler;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\ArrayLoader;
use Twig\Loader\FilesystemLoader;
class Factory implements \Runtime\Contracts\View\Factory {
/**
* @var string
*/
private $resourcesDir = '/../resources/';
/**
* @var string
*/
@ -39,9 +32,9 @@ class Factory implements \Runtime\Contracts\View\Factory {
*/
public function __construct()
{
$loader = new FilesystemLoader(getcwd() . $this->resourcesDir . 'views');
$loader = new FilesystemLoader(app()->resourcePath() . 'views');
$this->twig = new Environment($loader, [
'cache' => $this->resourcesDir . 'cache'
'cache' => app()->resourcePath() . 'cache'
]);
}