Basic functionality

This commit is contained in:
2022-03-12 16:25:30 +01:00
parent f3beaa64cf
commit acc21b7b24
137 changed files with 12647 additions and 5089 deletions

63
app/ui/Control/TModuleUtils.php Executable file
View File

@@ -0,0 +1,63 @@
<?php declare(strict_types = 1);
namespace App\UI\Control;
use App\Model\Exception\Runtime\InvalidStateException;
use App\Modules\Base\BasePresenter;
/**
* @mixin BasePresenter
*/
trait TModuleUtils
{
/**
* Gets module name
*/
public function getModuleName(): string
{
$name = $this->getName();
// Validate presenter has a proper name
if ($name === null) {
throw new InvalidStateException('Presenter doesn\'t have a name');
}
$parts = explode(':', $name);
return current($parts);
}
/**
* Is current module active?
*
* @param string $module Module name
*/
public function isModuleCurrent(string $module): bool
{
return strpos($this->getAction(true), $module) !== false;
}
/**
* Gets template dir
*/
public function getTemplateDir(): string
{
$fileName = $this->getReflection()->getFileName();
// Validate if class is not in PHP core
if ($fileName === false) {
throw new InvalidStateException('Class is defined in the PHP core or in a PHP extension');
}
$realpath = realpath(dirname($fileName) . '/../templates');
// Validate if file exists
if ($realpath === false) {
throw new InvalidStateException('File does not exist');
}
return $realpath;
}
}