I rightly do not know what this all is
This commit is contained in:
parent
af6b2b752e
commit
287c1f67c5
78 changed files with 3484 additions and 3365 deletions
|
|
@ -1,17 +1,17 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GamesShop\Templates;
|
||||
|
||||
use GamesShop\Login\UserPermission;
|
||||
|
||||
final class NavigationHeader
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $title,
|
||||
public readonly string $link,
|
||||
public readonly UserPermission $minimumPermission,
|
||||
)
|
||||
{
|
||||
}
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GamesShop\Templates;
|
||||
|
||||
use GamesShop\Login\UserPermission;
|
||||
|
||||
final class NavigationHeader
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $title,
|
||||
public readonly string $link,
|
||||
public readonly UserPermission $minimumPermission,
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GamesShop\Templates;
|
||||
|
||||
final class ResourceEntry
|
||||
{
|
||||
/**
|
||||
* @param string[] $js
|
||||
* @param string[] $css
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly array $js,
|
||||
public readonly array $css,
|
||||
) { }
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GamesShop\Templates;
|
||||
|
||||
final class ResourceEntry
|
||||
{
|
||||
/**
|
||||
* @param string[] $js
|
||||
* @param string[] $css
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly array $js,
|
||||
public readonly array $css,
|
||||
) { }
|
||||
}
|
||||
|
|
@ -1,51 +1,51 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GamesShop\Templates;
|
||||
|
||||
use Exception;
|
||||
use GamesShop\Paths;
|
||||
|
||||
final class ResourceIndex
|
||||
{
|
||||
private const string PATH = Paths::SOURCE_PATH . '/file-index.json';
|
||||
|
||||
/**
|
||||
* @var ResourceEntry[]
|
||||
*/
|
||||
private array $resources = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$fileContents = file_get_contents(self::PATH);
|
||||
$index = json_decode($fileContents, true);
|
||||
|
||||
foreach ($index as $entryKey => $resource) {
|
||||
$js = $resource['js'];
|
||||
if (is_string($js)) {
|
||||
$js = [$js];
|
||||
}
|
||||
|
||||
$css = $resource['css'];
|
||||
if (is_string($css)) {
|
||||
$css = [$css];
|
||||
}
|
||||
|
||||
$this->resources[$entryKey] = new ResourceEntry(
|
||||
$js, $css
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getResource(string $entry): ResourceEntry
|
||||
{
|
||||
if (!array_key_exists($entry, $this->resources)) {
|
||||
throw new Exception("Entry '$entry' not found");
|
||||
}
|
||||
|
||||
return $this->resources[$entry];
|
||||
}
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GamesShop\Templates;
|
||||
|
||||
use Exception;
|
||||
use GamesShop\Paths;
|
||||
|
||||
final class ResourceIndex
|
||||
{
|
||||
private const string PATH = Paths::SOURCE_PATH . '/file-index.json';
|
||||
|
||||
/**
|
||||
* @var ResourceEntry[]
|
||||
*/
|
||||
private array $resources = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$fileContents = file_get_contents(self::PATH);
|
||||
$index = json_decode($fileContents, true);
|
||||
|
||||
foreach ($index as $entryKey => $resource) {
|
||||
$js = $resource['js'];
|
||||
if (is_string($js)) {
|
||||
$js = [$js];
|
||||
}
|
||||
|
||||
$css = $resource['css'];
|
||||
if (is_string($css)) {
|
||||
$css = [$css];
|
||||
}
|
||||
|
||||
$this->resources[$entryKey] = new ResourceEntry(
|
||||
$js, $css
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getResource(string $entry): ResourceEntry
|
||||
{
|
||||
if (!array_key_exists($entry, $this->resources)) {
|
||||
throw new Exception("Entry '$entry' not found");
|
||||
}
|
||||
|
||||
return $this->resources[$entry];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +1,34 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GamesShop\Templates;
|
||||
|
||||
use GamesShop\Login\LoginHandler;
|
||||
use GamesShop\Paths;
|
||||
use League\Plates\Engine;
|
||||
|
||||
final class TemplateEngine extends Engine
|
||||
{
|
||||
private const string TEMPLATES_PATH = Paths::SOURCE_PATH . '/templates';
|
||||
|
||||
public function __construct(
|
||||
private ResourceIndex $resourceIndex,
|
||||
LoginHandler $loginHandler,
|
||||
)
|
||||
{
|
||||
parent::__construct(self::TEMPLATES_PATH, 'php');
|
||||
$this->addData([
|
||||
'resources' => $this->resourceIndex,
|
||||
'activeUser' => $loginHandler->isLoggedIn() ? $loginHandler->getCurrentUser() : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function renderPage(string $page, array $data = array())
|
||||
{
|
||||
return parent::render("pages/$page", $data);
|
||||
}
|
||||
|
||||
public function renderErrorPage(int $error) {
|
||||
return self::renderPage('error', [ 'errorCode' => $error ]);
|
||||
}
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GamesShop\Templates;
|
||||
|
||||
use GamesShop\Login\LoginHandler;
|
||||
use GamesShop\Paths;
|
||||
use League\Plates\Engine;
|
||||
|
||||
final class TemplateEngine extends Engine
|
||||
{
|
||||
private const string TEMPLATES_PATH = Paths::SOURCE_PATH . '/templates';
|
||||
|
||||
public function __construct(
|
||||
private ResourceIndex $resourceIndex,
|
||||
LoginHandler $loginHandler,
|
||||
)
|
||||
{
|
||||
parent::__construct(self::TEMPLATES_PATH, 'php');
|
||||
$this->addData([
|
||||
'resources' => $this->resourceIndex,
|
||||
'activeUser' => $loginHandler->isLoggedIn() ? $loginHandler->getCurrentUser() : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function renderPage(string $page, array $data = array())
|
||||
{
|
||||
return parent::render("pages/$page", $data);
|
||||
}
|
||||
|
||||
public function renderErrorPage(int $error) {
|
||||
return self::renderPage('error', [ 'errorCode' => $error ]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue