Init
This commit is contained in:
35
app/model/Latte/FilterExecutor.php
Normal file
35
app/model/Latte/FilterExecutor.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use Latte\Engine;
|
||||
|
||||
final class FilterExecutor
|
||||
{
|
||||
|
||||
/** @var Engine */
|
||||
private $latte;
|
||||
|
||||
public function __construct(Engine $latte)
|
||||
{
|
||||
$this->latte = $latte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $name, array $args)
|
||||
{
|
||||
return $this->latte->invokeFilter($name, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get(string $name)
|
||||
{
|
||||
return $this->latte->invokeFilter($name, []);
|
||||
}
|
||||
|
||||
}
|
||||
30
app/model/Latte/Filters.php
Normal file
30
app/model/Latte/Filters.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use Nette\Neon\Neon;
|
||||
use Nette\StaticClass;
|
||||
use Nette\Utils\Json;
|
||||
|
||||
final class Filters
|
||||
{
|
||||
|
||||
use StaticClass;
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function neon($value): string
|
||||
{
|
||||
return Neon::encode($value, Neon::BLOCK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function json($value): string
|
||||
{
|
||||
return Json::encode($value);
|
||||
}
|
||||
|
||||
}
|
||||
16
app/model/Latte/Macros.php
Normal file
16
app/model/Latte/Macros.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use Latte\Compiler;
|
||||
use Latte\Macros\MacroSet;
|
||||
|
||||
final class Macros extends MacroSet
|
||||
{
|
||||
|
||||
public static function register(Compiler $compiler): void
|
||||
{
|
||||
$compiler = new static($compiler);
|
||||
}
|
||||
|
||||
}
|
||||
51
app/model/Latte/TemplateFactory.php
Normal file
51
app/model/Latte/TemplateFactory.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use App\Model\Security\SecurityUser;
|
||||
use Nette\Application\UI\Control;
|
||||
use Nette\Bridges\ApplicationLatte\LatteFactory;
|
||||
use Nette\Bridges\ApplicationLatte\Template;
|
||||
use Nette\Bridges\ApplicationLatte\TemplateFactory as NetteTemplateFactory;
|
||||
use Nette\Caching\IStorage;
|
||||
use Nette\Http\IRequest;
|
||||
|
||||
final class TemplateFactory extends NetteTemplateFactory
|
||||
{
|
||||
|
||||
/** @var LatteFactory */
|
||||
private $latteFactory;
|
||||
|
||||
/** @var SecurityUser */
|
||||
private $user;
|
||||
|
||||
public function __construct(
|
||||
LatteFactory $latteFactory,
|
||||
IRequest $httpRequest,
|
||||
SecurityUser $user,
|
||||
IStorage $cacheStorage,
|
||||
string $templateClass = null
|
||||
)
|
||||
{
|
||||
parent::__construct($latteFactory, $httpRequest, $user, $cacheStorage, $templateClass);
|
||||
$this->latteFactory = $latteFactory;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function createTemplate(Control $control = null, string $class = null): Template
|
||||
{
|
||||
/** @var Template $template */
|
||||
$template = parent::createTemplate($control);
|
||||
|
||||
// Remove default $template->user for prevent misused
|
||||
unset($template->user);
|
||||
|
||||
// Assign new variables
|
||||
$template->_user = $this->user;
|
||||
$template->_template = $template;
|
||||
$template->_filters = new FilterExecutor($this->latteFactory->create());
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
}
|
||||
20
app/model/Latte/TemplateProperty.php
Normal file
20
app/model/Latte/TemplateProperty.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use App\Model\Security\SecurityUser;
|
||||
use App\Modules\Base\BasePresenter;
|
||||
use App\UI\Control\BaseControl;
|
||||
use Nette\Bridges\ApplicationLatte\Template;
|
||||
|
||||
/**
|
||||
* @property-read SecurityUser $_user
|
||||
* @property-read BasePresenter $presenter
|
||||
* @property-read BaseControl $control
|
||||
* @property-read string $baseUri
|
||||
* @property-read string $basePath
|
||||
* @property-read array $flashes
|
||||
*/
|
||||
final class TemplateProperty extends Template
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user