Basic functionality
This commit is contained in:
63
app/ui/Control/TModuleUtils.php
Executable file
63
app/ui/Control/TModuleUtils.php
Executable 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user