Create TemplateEngineAwareTrait
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Potter\Template\Engine\Aware;
|
||||||
|
|
||||||
|
use \Potter\Aware\AwareInterface;
|
||||||
|
use \Potter\Template\Engine\TemplateEngineInterface;
|
||||||
|
|
||||||
|
trait TemplateEngineAwareTrait
|
||||||
|
{
|
||||||
|
private const string TEMPLATE_ENGINE = 'templateEngine';
|
||||||
|
|
||||||
|
abstract public function get(string $key): mixed;
|
||||||
|
|
||||||
|
final public function getTemplateEngine(): TemplateEngineInterface
|
||||||
|
{
|
||||||
|
return $this->get(self::TEMPLATE_ENGINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function has(string $key): bool;
|
||||||
|
|
||||||
|
final public function hasTemplateEngine(): bool
|
||||||
|
{
|
||||||
|
return $this->has(self::TEMPLATE_ENGINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected function set(string $key, mixed $value): mixed;
|
||||||
|
|
||||||
|
final public function setTemplateEngine(TemplateEngineInterface $templateEngine): TemplateEngineInterface
|
||||||
|
{
|
||||||
|
return $this->set(self::TEMPLATE_ENGINE, $templateEngine);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected function unset(string $key): void;
|
||||||
|
|
||||||
|
final public function unsetTemplateEngine(): void
|
||||||
|
{
|
||||||
|
$this->unset(self::TEMPLATE_ENGINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function with(string $key, mixed $value): AwareInterface;
|
||||||
|
|
||||||
|
final public function withTemplateEngine(TemplateEngineInterface $templateEngine): TemplateEngineAwareInterface
|
||||||
|
{
|
||||||
|
return $this->with(self::TEMPLATE_ENGINE, $templateEngine);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function without(string $key): AwareInterface;
|
||||||
|
|
||||||
|
final public function withoutTemplateEngine(): TemplateEngineAwareInterface
|
||||||
|
{
|
||||||
|
return $this->without(self::TEMPLATE_ENGINE);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user