From e10c4b889b226e8138e99e8a9b4fa834f9382c9b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 2 Dec 2020 02:42:04 +0100 Subject: [PATCH] Refacuring: - moved state, template and resolver instances to distinct traits MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../main/classes/actions/class_BaseAction.php | 27 +-------- .../classes/class_BaseFrameworkSystem.php | 16 +----- .../classes/commands/class_BaseCommand.php | 55 ++----------------- .../controller/class_BaseController.php | 29 ++-------- .../class_XmlRewriterTemplateDecorator.php | 26 +-------- .../helper/html/class_BaseHtmlHelper.php | 28 +--------- .../html/forms/class_HtmlFormHelper.php | 2 +- .../html/links/class_HtmlLinkHelper.php | 2 +- .../main/classes/images/class_BaseImage.php | 39 +++---------- .../main/classes/mailer/class_BaseMailer.php | 29 ++-------- .../main/classes/menu/class_BaseMenu.php | 28 +--------- .../main/classes/parser/class_BaseParser.php | 27 +-------- .../action/class_BaseActionResolver.php | 2 +- .../command/class_BaseCommandResolver.php | 2 +- .../console/class_ConsoleCommandResolver.php | 2 +- .../html/class_HtmlCommandResolver.php | 3 +- .../image/class_ImageCommandResolver.php | 3 +- .../image/class_ImageTemplateEngine.php | 7 +-- .../mail/class_MailTemplateEngine.php | 15 ++--- .../menu/class_MenuTemplateEngine.php | 40 +++----------- .../resolver/actions/class_ActionResolver.php | 2 +- .../class_TestsConsoleCommandResolver.php | 2 +- .../traits/resolver/class_ResolverTrait.php | 55 +++++++++++++++++++ .../traits/state/class_StateableTrait.php | 54 ++++++++++++++++++ .../class_CompileableTemplateTrait.php | 55 +++++++++++++++++++ 25 files changed, 229 insertions(+), 321 deletions(-) create mode 100644 framework/main/traits/resolver/class_ResolverTrait.php create mode 100644 framework/main/traits/state/class_StateableTrait.php create mode 100644 framework/main/traits/template/class_CompileableTemplateTrait.php diff --git a/framework/main/classes/actions/class_BaseAction.php b/framework/main/classes/actions/class_BaseAction.php index 40813e41..6507cc2f 100644 --- a/framework/main/classes/actions/class_BaseAction.php +++ b/framework/main/classes/actions/class_BaseAction.php @@ -4,7 +4,7 @@ namespace Org\Mxchange\CoreFramework\Action; // Import framework stuff use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; -use Org\Mxchange\CoreFramework\Resolver\Resolver; +use Org\Mxchange\CoreFramework\Traits\Resolver\ResolverTrait; /** * A general action class. You shall extend this class if you are going to write @@ -31,10 +31,8 @@ use Org\Mxchange\CoreFramework\Resolver\Resolver; * along with this program. If not, see . */ abstract class BaseAction extends BaseFrameworkSystem { - /** - * Resolver instance - */ - private $resolverInstance = NULL; + // Load traits + use ResolverTrait; /** * Protected constructor @@ -47,23 +45,4 @@ abstract class BaseAction extends BaseFrameworkSystem { parent::__construct($className); } - /** - * Setter for resolver instance - * - * @param $resolverInstance Instance of a command resolver class - * @return void - */ - protected final function setResolverInstance (Resolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - - /** - * Getter for resolver instance - * - * @return $resolverInstance Instance of a command resolver class - */ - protected final function getResolverInstance () { - return $this->resolverInstance; - } - } diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index e64f1241..67a85fd1 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -65,11 +65,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac */ private $realClass = __CLASS__; - /** - * State instance - */ - private $stateInstance = NULL; - /** * Call-back instance */ @@ -431,16 +426,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac return $webOutputInstance; } - /** - * Setter for state instance - * - * @param $stateInstance A Stateable instance - * @return void - */ - public final function setStateInstance (Stateable $stateInstance) { - $this->stateInstance = $stateInstance; - } - /** * Getter for state instance * @@ -1777,6 +1762,7 @@ Loaded includes: * "Getter" for a printable state name * * @return $stateName Name of the node's state in a printable format + * @todo Move this class away from this monolithic place (not whole class is monolithic) */ public final function getPrintableState () { // Default is 'null' diff --git a/framework/main/classes/commands/class_BaseCommand.php b/framework/main/classes/commands/class_BaseCommand.php index 6d6a9ebc..b66cb3ff 100644 --- a/framework/main/classes/commands/class_BaseCommand.php +++ b/framework/main/classes/commands/class_BaseCommand.php @@ -8,9 +8,10 @@ use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Request\Requestable; -use Org\Mxchange\CoreFramework\Resolver\Resolver; use Org\Mxchange\CoreFramework\Response\Responseable; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Resolver\ResolverTrait; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; + /** * A general (base) command * @@ -34,15 +35,9 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ abstract class BaseCommand extends BaseFrameworkSystem { - /** - * Resolver instance - */ - private $resolverInstance = NULL; - - /** - * Template engine instance - */ - private $templateInstance = NULL; + // Load traits + use CompileableTemplateTrait; + use ResolverTrait; /** * Protected constructor @@ -55,44 +50,6 @@ abstract class BaseCommand extends BaseFrameworkSystem { parent::__construct($className); } - /** - * Setter for resolver instance - * - * @param $resolverInstance Instance of a command resolver class - * @return void - */ - protected final function setResolverInstance (Resolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - - /** - * Getter for resolver instance - * - * @return $resolverInstance Instance of a command resolver class - */ - protected final function getResolverInstance () { - return $this->resolverInstance; - } - - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a CompileableTemplate class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a CompileableTemplate class - */ - public final function getTemplateInstance () { - return $this->templateInstance; - } - /** * Initializes the template engine * diff --git a/framework/main/classes/controller/class_BaseController.php b/framework/main/classes/controller/class_BaseController.php index dc5fe704..56c0e214 100644 --- a/framework/main/classes/controller/class_BaseController.php +++ b/framework/main/classes/controller/class_BaseController.php @@ -10,8 +10,8 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Request\Requestable; -use Org\Mxchange\CoreFramework\Resolver\Resolver; use Org\Mxchange\CoreFramework\Response\Responseable; +use Org\Mxchange\CoreFramework\Traits\Resolver\ResolverTrait; /** * A generic controller class. You should extend this base class if you want to @@ -38,6 +38,9 @@ use Org\Mxchange\CoreFramework\Response\Responseable; * along with this program. If not, see . */ abstract class BaseController extends BaseFrameworkSystem implements Registerable { + // Load traits + use ResolverTrait; + // Exception constants const EXCEPTION_FILTER_CHAIN_INVALID = 0xf10; @@ -45,11 +48,6 @@ abstract class BaseController extends BaseFrameworkSystem implements Registerabl const FILTER_CHAIN_PRE_COMMAND = 'controller_pre_command'; const FILTER_CHAIN_POST_COMMAND = 'controller_post_command'; - /** - * Resolver instance - */ - private $resolverInstance = NULL; - /** * Generic filter chains */ @@ -73,25 +71,6 @@ abstract class BaseController extends BaseFrameworkSystem implements Registerabl GenericRegistry::getRegistry()->addInstance('controller', $this); } - /** - * Setter for resolver instance - * - * @param $resolverInstance Instance of a command resolver class - * @return void - */ - protected final function setResolverInstance (Resolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - - /** - * Getter for resolver instance - * - * @return $resolverInstance Instance of a command resolver class - */ - protected final function getResolverInstance () { - return $this->resolverInstance; - } - /** * Executes a command with pre and post filters * diff --git a/framework/main/classes/decorator/template/class_XmlRewriterTemplateDecorator.php b/framework/main/classes/decorator/template/class_XmlRewriterTemplateDecorator.php index 8ad5440e..b4c51bf9 100644 --- a/framework/main/classes/decorator/template/class_XmlRewriterTemplateDecorator.php +++ b/framework/main/classes/decorator/template/class_XmlRewriterTemplateDecorator.php @@ -6,6 +6,7 @@ namespace Org\Mxchange\CoreFramework\Template\Xml; use Org\Mxchange\CoreFramework\Generic\BaseDecorator; use Org\Mxchange\CoreFramework\Response\Responseable; use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; /** * A decorator for XML template engines which rewrites the XML for compacting @@ -31,10 +32,8 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableTemplate { - /** - * Template engine instance - */ - private $templateInstance = NULL; + // Load traits + use CompileableTemplateTrait; /** * Protected constructor @@ -63,25 +62,6 @@ class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableT return $templateInstance; } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a CompileableTemplate class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a CompileableTemplate class - */ - protected final function getTemplateInstance () { - return $this->templateInstance; - } - /** * Settter for variable group * diff --git a/framework/main/classes/helper/html/class_BaseHtmlHelper.php b/framework/main/classes/helper/html/class_BaseHtmlHelper.php index f2928b9b..c1f05f76 100644 --- a/framework/main/classes/helper/html/class_BaseHtmlHelper.php +++ b/framework/main/classes/helper/html/class_BaseHtmlHelper.php @@ -4,7 +4,7 @@ namespace Org\Mxchange\CoreFramework\Helper; // Import framework stuff use Org\Mxchange\CoreFramework\Helper\BaseHelper; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; /** * A general purpose web helper. You should not instance this like all the other @@ -30,11 +30,8 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ abstract class BaseHtmlHelper extends BaseHelper { - - /** - * Template engine instance - */ - private $templateInstance = NULL; + // Load traits + use CompileableTemplateTrait; /** * Protected constructor @@ -47,23 +44,4 @@ abstract class BaseHtmlHelper extends BaseHelper { parent::__construct($className); } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a CompileableTemplate class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a CompileableTemplate class - */ - public final function getTemplateInstance () { - return $this->templateInstance; - } - } diff --git a/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php b/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php index 87884e45..54422a82 100644 --- a/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php +++ b/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php @@ -83,7 +83,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @param $withForm Whether include the form tag * @return $helperInstance A preparedf instance of this helper */ - public static final function createHtmlFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false, $withForm = true) { + public static final function createHtmlFormHelper (CompileableTemplate $templateInstance, string $formName, $formId = false, bool $withForm = true) { // Get new instance $helperInstance = new HtmlFormHelper(); diff --git a/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php b/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php index dcef00c9..b97e0810 100644 --- a/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php +++ b/framework/main/classes/helper/html/links/class_HtmlLinkHelper.php @@ -73,7 +73,7 @@ class HtmlLinkHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $helperInstance A prepared instance of this helper * @throws NoConfigEntryException A deprecated exception at this point */ - public static final function createHtmlLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase = NULL) { + public static final function createHtmlLinkHelper (CompileableTemplate $templateInstance, string $linkName, $linkBase = NULL) { // Get new instance $helperInstance = new HtmlLinkHelper(); diff --git a/framework/main/classes/images/class_BaseImage.php b/framework/main/classes/images/class_BaseImage.php index df66bc4d..5ba5ce43 100644 --- a/framework/main/classes/images/class_BaseImage.php +++ b/framework/main/classes/images/class_BaseImage.php @@ -5,7 +5,7 @@ namespace Org\Mxchange\CoreFramework\Image; // Import framework stuff use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; use Org\Mxchange\CoreFramework\Registry\Registerable; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; /** * A general image class @@ -30,6 +30,9 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { + // Load traits + use CompileableTemplateTrait; + /** * Image type */ @@ -38,23 +41,23 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { /** * Width of the image */ - private $width = ''; + private $width = 0; /** * Height of the image */ - private $height = ''; + private $height = 0; /** * X/Y */ - private $x = ''; - private $y = ''; + private $x = 0; + private $y = 0; /** * Font size */ - private $fontSize = ''; + private $fontSize = 0; /** * Image string @@ -104,11 +107,6 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { */ private $groupable = 'single'; - /** - * Template engine instance - */ - private $templateInstance = NULL; - /** * Protected constructor * @@ -453,25 +451,6 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { $this->stringName = $stringName; } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a CompileableTemplate class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a CompileableTemplate class - */ - public final function getTemplateInstance () { - return $this->templateInstance; - } - /** * Finish this image by producing it * diff --git a/framework/main/classes/mailer/class_BaseMailer.php b/framework/main/classes/mailer/class_BaseMailer.php index 70c6bcd9..43d92ec0 100644 --- a/framework/main/classes/mailer/class_BaseMailer.php +++ b/framework/main/classes/mailer/class_BaseMailer.php @@ -7,7 +7,7 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Manager\Login\ManageableMember; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; /** * A general mailer class for all other mailers @@ -32,16 +32,14 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ abstract class BaseMailer extends BaseFrameworkSystem { + // Load traits + use CompileableTemplateTrait; + /** * Template name */ private $templateName = ''; - /** - * Template engine instance - */ - private $templateInstance = NULL; - /** * Protected constructor * @@ -203,23 +201,4 @@ abstract class BaseMailer extends BaseFrameworkSystem { return $this->getGenericArray('recipients'); } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a CompileableTemplate class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a CompileableTemplate class - */ - public final function getTemplateInstance () { - return $this->templateInstance; - } - } diff --git a/framework/main/classes/menu/class_BaseMenu.php b/framework/main/classes/menu/class_BaseMenu.php index 03879712..2defb635 100644 --- a/framework/main/classes/menu/class_BaseMenu.php +++ b/framework/main/classes/menu/class_BaseMenu.php @@ -8,7 +8,7 @@ use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; /** * A general menu system class @@ -33,11 +33,8 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ abstract class BaseMenu extends BaseFrameworkSystem { - - /** - * Template engine instance - */ - private $templateInstance = NULL; + // Load traits + use CompileableTemplateTrait; /** * Protected constructor @@ -50,25 +47,6 @@ abstract class BaseMenu extends BaseFrameworkSystem { parent::__construct($className); } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a CompileableTemplate class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a CompileableTemplate class - */ - public final function getTemplateInstance () { - return $this->templateInstance; - } - /** * Renders the menu by loading the base template and a menu-specific * template. diff --git a/framework/main/classes/parser/class_BaseParser.php b/framework/main/classes/parser/class_BaseParser.php index 92070b8b..7435458a 100644 --- a/framework/main/classes/parser/class_BaseParser.php +++ b/framework/main/classes/parser/class_BaseParser.php @@ -4,7 +4,7 @@ namespace Org\Mxchange\CoreFramework\Parser; // Import framework stuff use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; /** * A general Parser @@ -29,10 +29,8 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ abstract class BaseParser extends BaseFrameworkSystem { - /** - * Template engine instance - */ - private $templateInstance = NULL; + // Load traits + use CompileableTemplateTrait; /** * Protected constructor @@ -45,23 +43,4 @@ abstract class BaseParser extends BaseFrameworkSystem { parent::__construct($className); } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a CompileableTemplate class - * @return void - */ - public final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a CompileableTemplate class - */ - public final function getTemplateInstance () { - return $this->templateInstance; - } - } diff --git a/framework/main/classes/resolver/action/class_BaseActionResolver.php b/framework/main/classes/resolver/action/class_BaseActionResolver.php index 98341652..6a30c35c 100644 --- a/framework/main/classes/resolver/action/class_BaseActionResolver.php +++ b/framework/main/classes/resolver/action/class_BaseActionResolver.php @@ -76,7 +76,7 @@ abstract class BaseActionResolver extends BaseResolver { * @return $isValid Whether the given action is valid * @throws InvalidArgumentException Thrown if given action is not set */ - public function isActionValid ($namespace, $actionName) { + public function isActionValid (string $namespace, string $actionName) { // Is a action set? if (empty($namespace)) { // Then thrown an exception here diff --git a/framework/main/classes/resolver/command/class_BaseCommandResolver.php b/framework/main/classes/resolver/command/class_BaseCommandResolver.php index 53a24d61..9d5177aa 100644 --- a/framework/main/classes/resolver/command/class_BaseCommandResolver.php +++ b/framework/main/classes/resolver/command/class_BaseCommandResolver.php @@ -207,7 +207,7 @@ abstract class BaseCommandResolver extends BaseResolver { * @return $isValid Whether the given command is valid * @throws InvalidArgumentException Thrown if given command is not set */ - protected function isCommandValid ($namespace, $commandName) { + protected function isCommandValid (string $namespace, string $commandName) { // Is namespace and command name set? if (empty($namespace)) { // Then thrown an exception here diff --git a/framework/main/classes/resolver/command/console/class_ConsoleCommandResolver.php b/framework/main/classes/resolver/command/console/class_ConsoleCommandResolver.php index 7cd5109e..9d3af9fd 100644 --- a/framework/main/classes/resolver/command/console/class_ConsoleCommandResolver.php +++ b/framework/main/classes/resolver/command/console/class_ConsoleCommandResolver.php @@ -55,7 +55,7 @@ class ConsoleCommandResolver extends BaseCommandResolver implements CommandResol * @throws InvalidArgumentException Thrown if default command is not set * @throws InvalidCommandException Thrown if default command is invalid */ - public static final function createConsoleCommandResolver ($namespace, $commandName) { + public static final function createConsoleCommandResolver (string $namespace, string $commandName) { // Create the new instance $resolverInstance = new ConsoleCommandResolver(); diff --git a/framework/main/classes/resolver/command/html/class_HtmlCommandResolver.php b/framework/main/classes/resolver/command/html/class_HtmlCommandResolver.php index d28e3d83..294b68cb 100644 --- a/framework/main/classes/resolver/command/html/class_HtmlCommandResolver.php +++ b/framework/main/classes/resolver/command/html/class_HtmlCommandResolver.php @@ -58,7 +58,7 @@ class HtmlCommandResolver extends BaseCommandResolver implements CommandResolver * @throws InvalidArgumentException Thrown if default command is not set * @throws InvalidCommandException Thrown if default command is invalid */ - public static final function createHtmlCommandResolver ($commandName) { + public static final function createHtmlCommandResolver (string $commandName) { // Create the new instance $resolverInstance = new HtmlCommandResolver(); @@ -68,6 +68,7 @@ class HtmlCommandResolver extends BaseCommandResolver implements CommandResolver throw new InvalidArgumentException('Parameter "commandName" is empty'); } elseif ($resolverInstance->isCommandValid($commandName) === false) { // Invalid command found + // @TODO Missing namespace! throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); } diff --git a/framework/main/classes/resolver/command/image/class_ImageCommandResolver.php b/framework/main/classes/resolver/command/image/class_ImageCommandResolver.php index b120dc10..8baf41e6 100644 --- a/framework/main/classes/resolver/command/image/class_ImageCommandResolver.php +++ b/framework/main/classes/resolver/command/image/class_ImageCommandResolver.php @@ -58,7 +58,7 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve * @throws InvalidArgumentException Thrown if default command is not set * @throws InvalidCommandException Thrown if default command is invalid */ - public static final function createImageCommandResolver ($commandName) { + public static final function createImageCommandResolver (string $commandName) { // Create the new instance $resolverInstance = new ImageCommandResolver(); @@ -67,6 +67,7 @@ class ImageCommandResolver extends BaseCommandResolver implements CommandResolve // Then thrown an exception here throw new InvalidArgumentException('Parameter "commandName" is empty'); } elseif ($resolverInstance->isCommandValid($commandName) === false) { + // @TODO Missing namespace! // Invalid command found throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); } diff --git a/framework/main/classes/template/image/class_ImageTemplateEngine.php b/framework/main/classes/template/image/class_ImageTemplateEngine.php index d01ec650..6eeedefa 100644 --- a/framework/main/classes/template/image/class_ImageTemplateEngine.php +++ b/framework/main/classes/template/image/class_ImageTemplateEngine.php @@ -197,7 +197,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl * @return void * @throws InvalidXmlNodeException If an unknown/invalid XML node name was found */ - public function startElement ($resource, $element, array $attributes) { + public function startElement ($resource, string $element, array $attributes) { // Initial method name which will never be called... $methodName = 'initImage'; @@ -230,10 +230,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl * @return void * @throws XmlNodeMismatchException If current main node mismatches the closing one */ - public function finishElement ($resource, $nodeName) { - // Make all lower-case - $nodeName = strtolower($nodeName); - + public function finishElement ($resource, string $nodeName) { // Does this match with current main node? //* DEBUG: */ echo "END: >".$nodeName."<
\n"; if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) { diff --git a/framework/main/classes/template/mail/class_MailTemplateEngine.php b/framework/main/classes/template/mail/class_MailTemplateEngine.php index 24261f74..7406248e 100644 --- a/framework/main/classes/template/mail/class_MailTemplateEngine.php +++ b/framework/main/classes/template/mail/class_MailTemplateEngine.php @@ -43,19 +43,19 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla /** * Main nodes in the XML tree */ - private $mainNodes = array( + private $mainNodes = [ 'mail-data' - ); + ]; /** * Sub nodes in the XML tree */ - private $subNodes = array( + private $subNodes = [ 'subject-line', 'sender-address', 'recipient-address', 'message' - ); + ]; /** * Mailer instance @@ -168,7 +168,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla * @return void * @throws InvalidXmlNodeException If an unknown/invalid XML node name was found */ - public function startElement ($resource, $element, array $attributes) { + public function startElement ($resource, string $element, array $attributes) { // Initial method name which will never be called... $methodName = 'initEmail'; @@ -201,10 +201,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla * @return void * @throws XmlNodeMismatchException If current main node mismatches the closing one */ - public function finishElement ($resource, $nodeName) { - // Make all lower-case - $nodeName = strtolower($nodeName); - + public function finishElement ($resource, string $nodeName) { // Does this match with current main node? //* DEBUG: */ echo "END: >".$nodeName."<
\n"; if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) { diff --git a/framework/main/classes/template/menu/class_MenuTemplateEngine.php b/framework/main/classes/template/menu/class_MenuTemplateEngine.php index 77741274..5df5e14f 100644 --- a/framework/main/classes/template/menu/class_MenuTemplateEngine.php +++ b/framework/main/classes/template/menu/class_MenuTemplateEngine.php @@ -9,8 +9,9 @@ use Org\Mxchange\CoreFramework\Filesystem\InvalidDirectoryException; use Org\Mxchange\CoreFramework\Menu\RenderableMenu; use Org\Mxchange\CoreFramework\Parser\Parseable; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine; +use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; use Org\Mxchange\CoreFramework\Utils\String\StringUtils; // Import SPL stuff @@ -128,11 +129,6 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla */ private $menuInstance = NULL; - /** - * Template engine instance - */ - private $templateInstance = NULL; - /** * Protected constructor * @@ -223,25 +219,6 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla return $this->menuInstance; } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a CompileableTemplate class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a CompileableTemplate class - */ - public final function getTemplateInstance () { - return $this->templateInstance; - } - /** * Load a specified menu template into the engine * @@ -249,7 +226,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla * located in 'menu' by default * @return void */ - public function loadMenuTemplate ($template) { + public function loadMenuTemplate (string $template) { // Set template type $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('menu_template_type')); @@ -272,8 +249,8 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla * @param $element Element name to set as current main node * @return $currMainNode Current main node */ - private final function setCurrMainNode ($element) { - $this->curr['main_node'] = (string) $element; + private final function setCurrMainNode (string $element) { + $this->curr['main_node'] = $element; } /** @@ -303,7 +280,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla * @return void * @throws InvalidXmlNodeException If an unknown/invalid XML node name was found */ - public function startElement ($resource, $element, array $attributes) { + public function startElement ($resource, string $element, array $attributes) { // Initial method name which will never be called... $methodName = 'initMenu'; @@ -339,10 +316,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla * @return void * @throws XmlNodeMismatchException If current main node mismatches the closing one */ - public function finishElement ($resource, $nodeName) { - // Make all lower-case - $nodeName = strtolower($nodeName); - + public function finishElement ($resource, string $nodeName) { // Does this match with current main node? //* DEBUG: */ echo "END: >".$nodeName."<
\n"; if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) { diff --git a/framework/main/interfaces/resolver/actions/class_ActionResolver.php b/framework/main/interfaces/resolver/actions/class_ActionResolver.php index 79823bbe..0ef09a62 100644 --- a/framework/main/interfaces/resolver/actions/class_ActionResolver.php +++ b/framework/main/interfaces/resolver/actions/class_ActionResolver.php @@ -52,6 +52,6 @@ interface ActionResolver extends Resolver { * @return $isValid Whether the given action is valid * @throws InvalidArgumentException Thrown if namespace or action is not set */ - function isActionValid ($namespace, $actionName); + function isActionValid (string $namespace, string $actionName); } diff --git a/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php b/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php index 7c9aac58..631f1f1c 100644 --- a/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php +++ b/framework/main/tests/resolver/command/console/class_TestsConsoleCommandResolver.php @@ -54,7 +54,7 @@ class TestsConsoleCommandResolver extends BaseCommandResolver implements Command * @throws InvalidArgumentException Thrown if default command is not set * @throws InvalidCommandException Thrown if default command is invalid */ - public static final function createTestsConsoleCommandResolver ($commandName) { + public static final function createTestsConsoleCommandResolver (string $commandName) { // Create the new instance $resolverInstance = new TestsConsoleCommandResolver(); diff --git a/framework/main/traits/resolver/class_ResolverTrait.php b/framework/main/traits/resolver/class_ResolverTrait.php new file mode 100644 index 00000000..c3f0b1b6 --- /dev/null +++ b/framework/main/traits/resolver/class_ResolverTrait.php @@ -0,0 +1,55 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +trait ResolverTrait { + /** + * Resolver instance + */ + private $resolverInstance = NULL; + + /** + * Setter for resolver instance + * + * @param $resolverInstance Instance of a command resolver class + * @return void + */ + protected final function setResolverInstance (Resolver $resolverInstance) { + $this->resolverInstance = $resolverInstance; + } + + /** + * Getter for resolver instance + * + * @return $resolverInstance Instance of a command resolver class + */ + protected final function getResolverInstance () { + return $this->resolverInstance; + } + +} diff --git a/framework/main/traits/state/class_StateableTrait.php b/framework/main/traits/state/class_StateableTrait.php new file mode 100644 index 00000000..128c096f --- /dev/null +++ b/framework/main/traits/state/class_StateableTrait.php @@ -0,0 +1,54 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +trait StateableTrait { + /** + * State instance + */ + private $stateInstance = NULL; + + /** + * Setter for state instance + * + * @param $stateInstance A Stateable instance + * @return void + */ + public final function setStateInstance (Stateable $stateInstance) { + $this->stateInstance = $stateInstance; + } + + /** + * Getter for state instance + * + * @return $stateInstance A Stateable instance + */ + public final function getStateInstance () { + return $this->stateInstance; + } + +} diff --git a/framework/main/traits/template/class_CompileableTemplateTrait.php b/framework/main/traits/template/class_CompileableTemplateTrait.php new file mode 100644 index 00000000..f762b253 --- /dev/null +++ b/framework/main/traits/template/class_CompileableTemplateTrait.php @@ -0,0 +1,55 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +trait CompileableTemplateTrait { + /** + * Template engine instance + */ + private $templateInstance = NULL; + + /** + * Setter for template engine instances + * + * @param $templateInstance An instance of a CompileableTemplate class + * @return void + */ + protected final function setTemplateInstance (CompileableTemplate $templateInstance) { + $this->templateInstance = $templateInstance; + } + + /** + * Getter for template engine instances + * + * @return $templateInstance An instance of a CompileableTemplate class + */ + public final function getTemplateInstance () { + return $this->templateInstance; + } + +} -- 2.39.5