From 08a87724c74b484fa616e74e5ed85124450e936f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 2 Dec 2020 20:29:39 +0100 Subject: [PATCH] Continued: - used more traits than direct instances + getter/setter - added missing "import" lines - updated core framework MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../socket/class_SocketContainer.php | 35 +++--------- .../package/class_NetworkPackageHandler.php | 6 +- .../helper/class_BaseHubSystemHelper.php | 29 +--------- .../hub/classes/info/class_BaseInfo.php | 27 +-------- .../work_units/class_BaseUnitProducer.php | 56 ++----------------- .../class_BaseCommunicatorState.php | 1 + .../states/crawler/class_BaseCrawlerState.php | 1 + .../cruncher/class_BaseCruncherState.php | 1 + .../classes/states/dht/class_BaseDhtState.php | 1 + .../states/miner/class_BaseMinerState.php | 1 + .../states/node/class_BaseNodeState.php | 1 + .../states/peer/class_BasePeerState.php | 1 + .../hub/classes/tags/class_BaseTag.php | 29 ++-------- core | 2 +- 14 files changed, 33 insertions(+), 158 deletions(-) diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index eb2ad4bd9..d6eaa232c 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -6,19 +6,18 @@ namespace Org\Shipsimu\Hub\Container\Socket; use Org\Shipsimu\Hub\Container\BaseHubContainer; use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; use Org\Shipsimu\Hub\Factory\Socket\SocketFactory; +use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Helper\Connection\BaseConnectionHelper; use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper; use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Listener\BaseListener; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Generic\NullPointerException; -use Org\Mxchange\CoreFramework\Helper\Helper; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Socket\InvalidSocketException; use Org\Mxchange\CoreFramework\Socket\NoSocketErrorDetectedException; @@ -26,6 +25,7 @@ use Org\Mxchange\CoreFramework\Socket\SocketBindingException; use Org\Mxchange\CoreFramework\Socket\SocketConnectionException; use Org\Mxchange\CoreFramework\Socket\SocketOperationException; use Org\Mxchange\CoreFramework\Socket\UnsupportedSocketErrorHandlerException; +use Org\Mxchange\CoreFramework\Traits\Helper\HelperTrait; use Org\Mxchange\CoreFramework\Utils\String\StringUtils; use Org\Mxchange\CoreFramework\Visitor\Visitable; use Org\Mxchange\CoreFramework\Visitor\Visitor; @@ -59,6 +59,9 @@ use \SplFileInfo; * along with this program. If not, see . */ class SocketContainer extends BaseHubContainer implements StorableSocket, Visitable, Registerable { + // Load traits + use HelperTrait; + /** * Socket protocol: * - 'tcp' for TCP/IPv4 connections @@ -116,11 +119,6 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita */ private $socketResource = false; - /** - * A helper instance for the form - */ - private $helperInstance = NULL; - /** * Protected constructor * @@ -230,7 +228,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita */ public function shutdownSocket () { // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getSocketResource() . ' with state ' . $this->getPrintableState() . ' ...'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getSocketResource() . ' with state ' . $this->getHelperInstance()->getPrintableState() . ' ...'); // Get a visitor instance $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class'); @@ -253,7 +251,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita */ public function halfShutdownSocket () { // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Half-shutting down socket resource ' . $this->getSocketResource() . ' with state ' . $this->getPrintableState() . ' ...'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Half-shutting down socket resource ' . $this->getSocketResource() . ' with state ' . $this->getHelperInstance()->getPrintableState() . ' ...'); // Get a visitor instance $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class'); @@ -1535,23 +1533,4 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita return $this->socketResource; } - /** - * Setter for helper instance - * - * @param $helperInstance An instance of a helper class - * @return void - */ - protected final function setHelperInstance (Helper $helperInstance) { - $this->helperInstance = $helperInstance; - } - - /** - * Getter for helper instance - * - * @return $helperInstance An instance of a helper class - */ - public final function getHelperInstance () { - return $this->helperInstance; - } - } diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 492248644..6e4ebeb56 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -39,6 +39,7 @@ use Org\Mxchange\CoreFramework\Feature\FrameworkFeature; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Socket\InvalidSocketException; +use Org\Mxchange\CoreFramework\State\UnexpectedStateException; use Org\Mxchange\CoreFramework\Traits\Crypto\CryptoTrait; use Org\Mxchange\CoreFramework\Traits\Visitor\VisitorTrait; use Org\Mxchange\CoreFramework\Visitor\Visitable; @@ -530,9 +531,10 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $nextPackageInstance = $this->getStackInstance()->popNamed($stackerName); // Compare both hashes - if ($nextPackageInstance->getPackageHash() != $packageInstance->getPackageHash()) { + //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE))); + if ($nextPackageInstance->getContentHash() != $packageInstance->getContentHash()) { // Hash is not matching - throw new InvalidArgumentException(sprintf('Hashes "%s" and "%s" are mismatching.', $packageInstance->getPackageHash(), $nextPackageInstance->getPackageHash())); + throw new InvalidArgumentException(sprintf('Hashes "%s" and "%s" are mismatching.', $packageInstance->getContentHash(), $nextPackageInstance->getContentHash())); } // Temporary set the new status diff --git a/application/hub/classes/helper/class_BaseHubSystemHelper.php b/application/hub/classes/helper/class_BaseHubSystemHelper.php index 959863a61..2bac436a9 100644 --- a/application/hub/classes/helper/class_BaseHubSystemHelper.php +++ b/application/hub/classes/helper/class_BaseHubSystemHelper.php @@ -5,9 +5,6 @@ namespace Org\Shipsimu\Hub\Helper; // Import application-specific stuff use Org\Shipsimu\Hub\Generic\BaseHubSystem; -// Import framework stuff -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; - /** * A general hub helper class. This class does not extend BaseHelper. * @@ -30,7 +27,7 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseHubSystemHelper extends BaseHubSystem implements HubHelper { +abstract class BaseHubSystemHelper extends BaseHubSystem implements HubHelper { /** * Recipient id */ @@ -46,11 +43,6 @@ class BaseHubSystemHelper extends BaseHubSystem implements HubHelper { */ private $packageTags = []; - /** - * Template engine instance - */ - private $templateInstance = NULL; - /** * Protected constructor * @@ -117,25 +109,6 @@ class BaseHubSystemHelper extends BaseHubSystem implements HubHelper { $this->packageTags = $packageTags; } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a template engine class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a template engine class - */ - public final function getTemplateInstance () { - return $this->templateInstance; - } - /** * Tries to determine the used protocol for this package (this helper is helping to send out) * diff --git a/application/hub/classes/info/class_BaseInfo.php b/application/hub/classes/info/class_BaseInfo.php index 200ccbc85..102e91965 100644 --- a/application/hub/classes/info/class_BaseInfo.php +++ b/application/hub/classes/info/class_BaseInfo.php @@ -6,7 +6,7 @@ namespace Org\Shipsimu\Hub\Information; use Org\Shipsimu\Hub\Generic\BaseHubSystem; // Import framework stuff -use Org\Mxchange\CoreFramework\Helper\Helper; +use Org\Mxchange\CoreFramework\Traits\Helper\HelperTrait; /** * A general Info class @@ -31,10 +31,8 @@ use Org\Mxchange\CoreFramework\Helper\Helper; * along with this program. If not, see . */ abstract class BaseInfo extends BaseHubSystem { - /** - * A helper instance for the form - */ - private $helperInstance = NULL; + // Load traits + use HelperTrait; /** * Protected constructor @@ -47,23 +45,4 @@ abstract class BaseInfo extends BaseHubSystem { parent::__construct($className); } - /** - * Setter for helper instance - * - * @param $helperInstance An instance of a helper class - * @return void - */ - protected final function setHelperInstance (Helper $helperInstance) { - $this->helperInstance = $helperInstance; - } - - /** - * Getter for helper instance - * - * @return $helperInstance An instance of a helper class - */ - public final function getHelperInstance () { - return $this->helperInstance; - } - } diff --git a/application/hub/classes/producer/cruncher/work_units/class_BaseUnitProducer.php b/application/hub/classes/producer/cruncher/work_units/class_BaseUnitProducer.php index 8091aff6f..0b67d945e 100644 --- a/application/hub/classes/producer/cruncher/work_units/class_BaseUnitProducer.php +++ b/application/hub/classes/producer/cruncher/work_units/class_BaseUnitProducer.php @@ -6,8 +6,8 @@ namespace Org\Shipsimu\Hub\Producer\Cruncher\Unit; use Org\Shipsimu\Hub\Producer\Cruncher\BaseCruncherProducer; // Import framework stuff -use Org\Mxchange\CoreFramework\Helper\Helper; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Helper\HelperTrait; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; /** * A general UnitProducer class @@ -32,6 +32,10 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ abstract class BaseUnitProducer extends BaseCruncherProducer { + // Load traits + use HelperTrait; + use CompileableTemplateTrait; + /** * Work/test unit status */ @@ -45,16 +49,6 @@ abstract class BaseUnitProducer extends BaseCruncherProducer { const UNIT_TYPE_TEST_UNIT = 'test_unit'; const UNIT_TYPE_TEST_WORK = 'work_unit'; - /** - * Template engine instance - */ - private $templateInstance = NULL; - - /** - * A helper instance for the form - */ - private $helperInstance = NULL; - /** * Protected constructor * @@ -66,42 +60,4 @@ abstract class BaseUnitProducer extends BaseCruncherProducer { parent::__construct($className); } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a template engine class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a template engine class - */ - protected final function getTemplateInstance () { - return $this->templateInstance; - } - - /** - * Setter for helper instance - * - * @param $helperInstance An instance of a helper class - * @return void - */ - protected final function setHelperInstance (Helper $helperInstance) { - $this->helperInstance = $helperInstance; - } - - /** - * Getter for helper instance - * - * @return $helperInstance An instance of a helper class - */ - public final function getHelperInstance () { - return $this->helperInstance; - } - } diff --git a/application/hub/classes/states/communicator/class_BaseCommunicatorState.php b/application/hub/classes/states/communicator/class_BaseCommunicatorState.php index 072fe2dda..8b1ca9206 100644 --- a/application/hub/classes/states/communicator/class_BaseCommunicatorState.php +++ b/application/hub/classes/states/communicator/class_BaseCommunicatorState.php @@ -7,6 +7,7 @@ use Org\ShipSimu\Hub\Communicator\Communicator; // Import framework stuff use Org\Mxchange\CoreFramework\State\BaseState; +use Org\Mxchange\CoreFramework\State\UnexpectedStateException; /** * A general communicator state class diff --git a/application/hub/classes/states/crawler/class_BaseCrawlerState.php b/application/hub/classes/states/crawler/class_BaseCrawlerState.php index db30dfb76..f5d1d6535 100644 --- a/application/hub/classes/states/crawler/class_BaseCrawlerState.php +++ b/application/hub/classes/states/crawler/class_BaseCrawlerState.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Crawler\State; // Import framework stuff use Org\Mxchange\CoreFramework\State\BaseState; +use Org\Mxchange\CoreFramework\State\UnexpectedStateException; /** * A general crawler state class diff --git a/application/hub/classes/states/cruncher/class_BaseCruncherState.php b/application/hub/classes/states/cruncher/class_BaseCruncherState.php index af24a5a64..82c9969ac 100644 --- a/application/hub/classes/states/cruncher/class_BaseCruncherState.php +++ b/application/hub/classes/states/cruncher/class_BaseCruncherState.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Cruncher\State; // Import framework stuff use Org\Mxchange\CoreFramework\State\BaseState; +use Org\Mxchange\CoreFramework\State\UnexpectedStateException; /** * A general cruncher state class diff --git a/application/hub/classes/states/dht/class_BaseDhtState.php b/application/hub/classes/states/dht/class_BaseDhtState.php index 1f50132bf..ed338938e 100644 --- a/application/hub/classes/states/dht/class_BaseDhtState.php +++ b/application/hub/classes/states/dht/class_BaseDhtState.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\State\Dht; // Import framework stuff use Org\Mxchange\CoreFramework\State\BaseState; +use Org\Mxchange\CoreFramework\State\UnexpectedStateException; /** * A general DHT state class diff --git a/application/hub/classes/states/miner/class_BaseMinerState.php b/application/hub/classes/states/miner/class_BaseMinerState.php index 4d7d5f3f2..0a00fd948 100644 --- a/application/hub/classes/states/miner/class_BaseMinerState.php +++ b/application/hub/classes/states/miner/class_BaseMinerState.php @@ -8,6 +8,7 @@ use Org\Shipsimu\Hub\State\Miner\MinerInitState; // Import framework stuff use Org\Mxchange\CoreFramework\State\BaseState; +use Org\Mxchange\CoreFramework\State\UnexpectedStateException; /** * A general miner state class diff --git a/application/hub/classes/states/node/class_BaseNodeState.php b/application/hub/classes/states/node/class_BaseNodeState.php index 432b027c0..3cb4588d4 100644 --- a/application/hub/classes/states/node/class_BaseNodeState.php +++ b/application/hub/classes/states/node/class_BaseNodeState.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\State\Node; // Import framework stuff use Org\Mxchange\CoreFramework\State\BaseState; +use Org\Mxchange\CoreFramework\State\UnexpectedStateException; /** * A general node state class diff --git a/application/hub/classes/states/peer/class_BasePeerState.php b/application/hub/classes/states/peer/class_BasePeerState.php index 931a055d0..6c608f265 100644 --- a/application/hub/classes/states/peer/class_BasePeerState.php +++ b/application/hub/classes/states/peer/class_BasePeerState.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\State\Peer; // Import framework stuff use Org\Mxchange\CoreFramework\State\BaseState; +use Org\Mxchange\CoreFramework\State\UnexpectedStateException; /** * A general peer state class diff --git a/application/hub/classes/tags/class_BaseTag.php b/application/hub/classes/tags/class_BaseTag.php index 82c02929c..510523660 100644 --- a/application/hub/classes/tags/class_BaseTag.php +++ b/application/hub/classes/tags/class_BaseTag.php @@ -7,7 +7,7 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; // Import framework stuff use Org\Mxchange\CoreFramework\Registry\Registerable; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; +use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait; /** * A general Tags class @@ -32,16 +32,14 @@ use Org\Mxchange\CoreFramework\Template\CompileableTemplate; * along with this program. If not, see . */ abstract class BaseTag extends BaseHubSystem implements Registerable { + // Load traits + use CompileableTemplateTrait; + /** * An array with all tags */ private $tags = []; - /** - * Template engine instance - */ - private $templateInstance = NULL; - /** * Protected constructor * @@ -72,23 +70,4 @@ abstract class BaseTag extends BaseHubSystem implements Registerable { return $this->tags; } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a template engine class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a template engine class - */ - protected final function getTemplateInstance () { - return $this->templateInstance; - } - } diff --git a/core b/core index 2a3f63506..6187a6c39 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 2a3f6350600cf6ad214923c57aef772dc5c0cb76 +Subproject commit 6187a6c39a906ce7ae3ae89cdbc4f6a59a69535d -- 2.39.5