]> git.mxchange.org Git - core.git/blob - framework/main/classes/handler/class_BaseHandler.php
Continued:
[core.git] / framework / main / classes / handler / class_BaseHandler.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Handler;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
7 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
8 use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet;
9 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
10
11 // Import SPL stuff
12 use \InvalidArgumentException;
13
14 /**
15  * A general Handler
16  *
17  * @author              Roland Haeder <webmaster@shipsimu.org>
18  * @version             0.0.0
19  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
20  * @license             GNU GPL 3.0 or any newer version
21  * @link                http://www.shipsimu.org
22  *
23  * This program is free software: you can redistribute it and/or modify
24  * it under the terms of the GNU General Public License as published by
25  * the Free Software Foundation, either version 3 of the License, or
26  * (at your option) any later version.
27  *
28  * This program is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License
34  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
35  */
36 abstract class BaseHandler extends BaseFrameworkSystem implements HandleableDataSet {
37         /**
38          * Handler name
39          */
40         private $handlerName = 'invalid';
41
42         /**
43          * Protected constructor
44          *
45          * @param       $className      Name of the class
46          * @return      void
47          */
48         protected function __construct (string $className) {
49                 // Call parent constructor
50                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-HANDLER: className=%s - CONSTRUCTED!', $className));
51                 parent::__construct($className);
52
53                 // Trace message
54                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-HANDLER: EXIT!');
55         }
56
57         /**
58          * Getter for handler name
59          *
60          * @return      $handlerName    Name of this handler
61          */
62         public final function getHandlerName () {
63                 return $this->handlerName;
64         }
65
66         /**
67          * Setter for handler name
68          *
69          * @param       $handlerName    Name of this handler
70          * @return      void
71          */
72         protected final function setHandlerName (string $handlerName) {
73                 $this->handlerName = $handlerName;
74         }
75
76         /**
77          * Adds all required elements from given array into data set instance
78          *
79          * @param       $dataSetInstance        An instance of a StoreableCriteria class
80          * @param       $messageData            An array with all message data
81          * @return      void
82          * @todo        Rewrite this to use DHT
83          */
84         public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
85                 // Check parameter
86                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-HANDLER: dataSetInstance=%s,messageData()=%d - CALLED!', $dataSetInstance->__toString(), count($messageData)));
87                 if (count($messageData) == 0) {
88                         // Throw IAE
89                         throw new InvalidArgumentException('Parameter "messageData" is an empty array', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
90                 }
91
92                 // Trace message
93                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-HANDLER: EXIT!');
94         }
95
96 }