2017-04-25 22:50:19 +00:00
|
|
|
<?php
|
2019-10-03 19:24:12 +00:00
|
|
|
|
2017-04-25 22:50:19 +00:00
|
|
|
/**
|
|
|
|
* ViewFactory class.
|
|
|
|
*/
|
2017-04-25 22:52:05 +00:00
|
|
|
|
2017-04-25 22:50:19 +00:00
|
|
|
namespace Alltube;
|
|
|
|
|
2017-04-25 23:08:42 +00:00
|
|
|
use Psr\Container\ContainerInterface;
|
2017-04-25 22:50:19 +00:00
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Views\Smarty;
|
|
|
|
use Slim\Views\SmartyPlugins;
|
2020-05-13 19:18:32 +00:00
|
|
|
use SmartyException;
|
2017-04-25 22:50:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create Smarty view object.
|
|
|
|
*/
|
|
|
|
class ViewFactory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create Smarty view object.
|
|
|
|
*
|
2017-11-12 15:36:44 +00:00
|
|
|
* @param ContainerInterface $container Slim dependency container
|
2020-09-27 13:53:53 +00:00
|
|
|
* @param Request|null $request PSR-7 request
|
2017-04-25 22:50:19 +00:00
|
|
|
*
|
|
|
|
* @return Smarty
|
2020-05-13 19:18:32 +00:00
|
|
|
* @throws SmartyException
|
2017-04-25 22:50:19 +00:00
|
|
|
*/
|
2017-04-25 23:08:42 +00:00
|
|
|
public static function create(ContainerInterface $container, Request $request = null)
|
2017-04-25 22:50:19 +00:00
|
|
|
{
|
|
|
|
if (!isset($request)) {
|
2020-05-13 20:28:05 +00:00
|
|
|
$request = $container->get('request');
|
2017-04-25 22:50:19 +00:00
|
|
|
}
|
|
|
|
|
2019-10-03 19:24:12 +00:00
|
|
|
$view = new Smarty(__DIR__ . '/../templates/');
|
2017-05-14 19:53:57 +00:00
|
|
|
if (in_array('https', $request->getHeader('X-Forwarded-Proto'))) {
|
|
|
|
$request = $request->withUri($request->getUri()->withScheme('https')->withPort(443));
|
|
|
|
}
|
2017-04-25 22:50:19 +00:00
|
|
|
|
2020-05-13 20:28:05 +00:00
|
|
|
/** @var LocaleManager $localeManager */
|
|
|
|
$localeManager = $container->get('locale');
|
2019-11-27 22:15:49 +00:00
|
|
|
|
2020-05-13 20:28:05 +00:00
|
|
|
$smartyPlugins = new SmartyPlugins($container->get('router'), $request->getUri()->withUserInfo(null));
|
2017-04-25 22:50:19 +00:00
|
|
|
$view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
|
|
|
|
$view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);
|
2019-11-27 22:15:49 +00:00
|
|
|
$view->registerPlugin('block', 't', [$localeManager, 'smartyTranslate']);
|
2017-04-25 22:50:19 +00:00
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
}
|