2019-11-13 12:02:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Factories;
|
|
|
|
|
|
|
|
use App\Web\View;
|
|
|
|
use Psr\Container\ContainerInterface as Container;
|
|
|
|
use Slim\Factory\ServerRequestCreatorFactory;
|
|
|
|
use Twig\Environment;
|
|
|
|
use Twig\Loader\FilesystemLoader;
|
|
|
|
use Twig\TwigFunction;
|
|
|
|
|
|
|
|
class ViewFactory
|
|
|
|
{
|
|
|
|
public static function createAppInstance(Container $container)
|
|
|
|
{
|
|
|
|
$config = $container->get('config');
|
|
|
|
$loader = new FilesystemLoader(BASE_DIR.'resources/templates');
|
|
|
|
|
2019-11-21 17:00:47 +00:00
|
|
|
$twig = new Environment($loader, [
|
2019-11-20 17:49:31 +00:00
|
|
|
'cache' => BASE_DIR.'resources/cache/twig',
|
|
|
|
'autoescape' => 'html',
|
|
|
|
'debug' => $config['debug'],
|
2019-11-13 12:02:31 +00:00
|
|
|
'auto_reload' => $config['debug'],
|
2019-11-21 17:00:47 +00:00
|
|
|
]);
|
2019-11-13 12:02:31 +00:00
|
|
|
|
2019-11-19 12:59:17 +00:00
|
|
|
$request = ServerRequestCreatorFactory::determineServerRequestCreator()->createServerRequestFromGlobals();
|
2019-11-13 12:02:31 +00:00
|
|
|
|
|
|
|
$twig->addGlobal('config', $config);
|
|
|
|
$twig->addGlobal('request', $request);
|
2019-11-17 18:48:37 +00:00
|
|
|
$twig->addGlobal('session', $container->get('session'));
|
2019-11-13 12:02:31 +00:00
|
|
|
$twig->addGlobal('current_lang', $container->get('lang')->getLang());
|
2019-11-13 22:31:48 +00:00
|
|
|
$twig->addGlobal('maxUploadSize', stringToBytes(ini_get('post_max_size')));
|
2019-11-13 12:02:31 +00:00
|
|
|
$twig->addGlobal('PLATFORM_VERSION', PLATFORM_VERSION);
|
|
|
|
|
|
|
|
$twig->addFunction(new TwigFunction('route', 'route'));
|
|
|
|
$twig->addFunction(new TwigFunction('lang', 'lang'));
|
|
|
|
$twig->addFunction(new TwigFunction('urlFor', 'urlFor'));
|
|
|
|
$twig->addFunction(new TwigFunction('asset', 'asset'));
|
|
|
|
$twig->addFunction(new TwigFunction('mime2font', 'mime2font'));
|
|
|
|
$twig->addFunction(new TwigFunction('queryParams', 'queryParams'));
|
|
|
|
$twig->addFunction(new TwigFunction('isDisplayableImage', 'isDisplayableImage'));
|
2019-11-19 12:59:17 +00:00
|
|
|
$twig->addFunction(new TwigFunction('inPath', 'inPath'));
|
2019-11-13 12:02:31 +00:00
|
|
|
|
|
|
|
return new View($twig);
|
|
|
|
}
|
|
|
|
|
2019-11-20 17:49:31 +00:00
|
|
|
public static function createInstallerInstance(Container $container)
|
|
|
|
{
|
2019-11-13 12:02:31 +00:00
|
|
|
$config = $container->get('config');
|
2019-11-21 17:00:47 +00:00
|
|
|
$loader = new FilesystemLoader([BASE_DIR.'install/templates', BASE_DIR.'resources/templates']);
|
2019-11-13 12:02:31 +00:00
|
|
|
|
2019-11-21 17:00:47 +00:00
|
|
|
$twig = new Environment($loader, [
|
2019-11-20 17:49:31 +00:00
|
|
|
'cache' => false,
|
|
|
|
'autoescape' => 'html',
|
|
|
|
'debug' => $config['debug'],
|
2019-11-13 12:02:31 +00:00
|
|
|
'auto_reload' => $config['debug'],
|
2019-11-21 17:00:47 +00:00
|
|
|
]);
|
2019-11-13 12:02:31 +00:00
|
|
|
|
2019-11-19 12:59:17 +00:00
|
|
|
$request = ServerRequestCreatorFactory::determineServerRequestCreator()->createServerRequestFromGlobals();
|
2019-11-13 12:02:31 +00:00
|
|
|
|
|
|
|
$twig->addGlobal('config', $config);
|
|
|
|
$twig->addGlobal('request', $request);
|
2019-11-19 11:32:58 +00:00
|
|
|
$twig->addGlobal('session', $container->get('session'));
|
2019-11-13 12:02:31 +00:00
|
|
|
$twig->addGlobal('PLATFORM_VERSION', PLATFORM_VERSION);
|
|
|
|
|
|
|
|
return new View($twig);
|
|
|
|
}
|
2019-11-20 17:49:31 +00:00
|
|
|
}
|