Move Smarty view creation to ViewFactory class
This commit is contained in:
parent
4d104c852f
commit
0e7aaea9fc
3 changed files with 47 additions and 23 deletions
41
classes/ViewFactory.php
Normal file
41
classes/ViewFactory.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* ViewFactory class.
|
||||
*/
|
||||
namespace Alltube;
|
||||
|
||||
use Slim\Container;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Views\Smarty;
|
||||
use Slim\Views\SmartyPlugins;
|
||||
|
||||
/**
|
||||
* Create Smarty view object.
|
||||
*/
|
||||
class ViewFactory
|
||||
{
|
||||
/**
|
||||
* Create Smarty view object.
|
||||
*
|
||||
* @param Container $container Slim dependency container
|
||||
* @param Request $request PSR-7 request
|
||||
*
|
||||
* @return Smarty
|
||||
*/
|
||||
public static function create(Container $container, Request $request = null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue