Init
This commit is contained in:
16
app/ui/Control/BaseControl.php
Normal file
16
app/ui/Control/BaseControl.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\UI\Control;
|
||||
|
||||
use App\Model\Latte\TemplateProperty;
|
||||
use App\Modules\Base\BasePresenter;
|
||||
use Nette\Application\UI\Control;
|
||||
|
||||
/**
|
||||
* @property-read TemplateProperty $template
|
||||
* @property-read BasePresenter $presenter
|
||||
*/
|
||||
abstract class BaseControl extends Control
|
||||
{
|
||||
|
||||
}
|
||||
49
app/ui/Control/TFlashMessage.php
Normal file
49
app/ui/Control/TFlashMessage.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\UI\Control;
|
||||
|
||||
use App\Modules\Base\BasePresenter;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @mixin BasePresenter
|
||||
*/
|
||||
trait TFlashMessage
|
||||
{
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param string $message
|
||||
* @param string $type
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
|
||||
*/
|
||||
public function flashMessage($message, $type = 'info'): stdClass
|
||||
{
|
||||
if ($this->isAjax()) {
|
||||
$this->redrawControl('flashes');
|
||||
}
|
||||
|
||||
return parent::flashMessage($message, $type);
|
||||
}
|
||||
|
||||
public function flashInfo(string $message): stdClass
|
||||
{
|
||||
return $this->flashMessage($message, 'info');
|
||||
}
|
||||
|
||||
public function flashSuccess(string $message): stdClass
|
||||
{
|
||||
return $this->flashMessage($message, 'success');
|
||||
}
|
||||
|
||||
public function flashWarning(string $message): stdClass
|
||||
{
|
||||
return $this->flashMessage($message, 'warning');
|
||||
}
|
||||
|
||||
public function flashError(string $message): stdClass
|
||||
{
|
||||
return $this->flashMessage($message, 'danger');
|
||||
}
|
||||
|
||||
}
|
||||
63
app/ui/Control/TModuleUtils.php
Normal file
63
app/ui/Control/TModuleUtils.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
19
app/ui/Control/TTranslate.php
Normal file
19
app/ui/Control/TTranslate.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\UI\Control;
|
||||
|
||||
use App\Modules\Base\BasePresenter;
|
||||
use Nette\Localization\ITranslator;
|
||||
|
||||
/**
|
||||
* @mixin BasePresenter
|
||||
*/
|
||||
trait TTranslate
|
||||
{
|
||||
|
||||
protected function _(string $message): string // phpcs:ignore
|
||||
{
|
||||
return $this->getContext()->getByType(ITranslator::class)->translate($message);
|
||||
}
|
||||
|
||||
}
|
||||
31
app/ui/Form/BaseForm.php
Normal file
31
app/ui/Form/BaseForm.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\UI\Form;
|
||||
|
||||
use Nette\Application\UI\Form;
|
||||
use Nette\Forms\Controls\TextInput;
|
||||
|
||||
class BaseForm extends Form
|
||||
{
|
||||
|
||||
public function addFloat(string $name, ?string $label = null): TextInput
|
||||
{
|
||||
$input = self::addText($name, $label);
|
||||
$input->addCondition(self::FILLED)
|
||||
->addRule(self::MAX_LENGTH, null, 255)
|
||||
->addRule(self::FLOAT);
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function addNumeric(string $name, ?string $label = null): TextInput
|
||||
{
|
||||
$input = self::addText($name, $label);
|
||||
$input->addCondition(self::FILLED)
|
||||
->addRule(self::MAX_LENGTH, null, 255)
|
||||
->addRule(self::NUMERIC);
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
}
|
||||
23
app/ui/Form/FormFactory.php
Normal file
23
app/ui/Form/FormFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\UI\Form;
|
||||
|
||||
final class FormFactory
|
||||
{
|
||||
|
||||
private function create(): BaseForm
|
||||
{
|
||||
return new BaseForm();
|
||||
}
|
||||
|
||||
public function forFrontend(): BaseForm
|
||||
{
|
||||
return $this->create();
|
||||
}
|
||||
|
||||
public function forBackend(): BaseForm
|
||||
{
|
||||
return $this->create();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user