2017-04-25 22:50:19 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create Smarty view object.
|
|
|
|
*/
|
|
|
|
class ViewFactory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create Smarty view object.
|
|
|
|
*
|
2017-04-25 22:52:05 +00:00
|
|
|
* @param Container $container Slim dependency container
|
|
|
|
* @param Request $request PSR-7 request
|
2017-04-25 22:50:19 +00:00
|
|
|
*
|
|
|
|
* @return Smarty
|
|
|
|
*/
|
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)) {
|
|
|
|
$request = $container['request'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = new Smarty(__DIR__.'/../templates/');
|
|
|
|
|
|
|
|
$smartyPlugins = new SmartyPlugins($container['router'], $request->getUri());
|
|
|
|
$view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
|
|
|
|
$view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);
|
|
|
|
|
|
|
|
$view->registerPlugin('modifier', 'noscheme', 'Smarty_Modifier_noscheme');
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
}
|