use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
use Org\Mxchange\CoreFramework\Result\Database\CachedDatabaseResult;
use Org\Mxchange\CoreFramework\State\Stateable;
-use Org\Mxchange\CoreFramework\Stream\Input\InputStream;
use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
-use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
use \stdClass;
use \InvalidArgumentException;
-use \Iterator;
use \ReflectionClass;
use \SplFileInfo;
*/
private $realClass = __CLASS__;
- /**
- * Instance of an Iterator class
- */
- private $iteratorInstance = NULL;
-
- /**
- * An instance of a InputStream class
- */
- private $inputStreamInstance = NULL;
-
- /**
- * An instance of a OutputStream class
- */
- private $outputStreamInstance = NULL;
-
/**
* An instance of a database wrapper class
*/
return $this->wrapperInstance;
}
- /**
- * Getter for a InputStream instance
- *
- * @param $inputStreamInstance The InputStream instance
- */
- protected final function getInputStreamInstance () {
- return $this->inputStreamInstance;
- }
-
- /**
- * Setter for a InputStream instance
- *
- * @param $inputStreamInstance The InputStream instance
- * @return void
- */
- protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
- $this->inputStreamInstance = $inputStreamInstance;
- }
-
- /**
- * Getter for a OutputStream instance
- *
- * @param $outputStreamInstance The OutputStream instance
- */
- protected final function getOutputStreamInstance () {
- return $this->outputStreamInstance;
- }
-
- /**
- * Setter for a OutputStream instance
- *
- * @param $outputStreamInstance The OutputStream instance
- * @return void
- */
- protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
- $this->outputStreamInstance = $outputStreamInstance;
- }
-
- /**
- * Setter for Iterator instance
- *
- * @param $iteratorInstance An instance of an Iterator
- * @return void
- */
- protected final function setIteratorInstance (Iterator $iteratorInstance) {
- $this->iteratorInstance = $iteratorInstance;
- }
-
- /**
- * Getter for Iterator instance
- *
- * @return $iteratorInstance An instance of an Iterator
- */
- public final function getIteratorInstance () {
- return $this->iteratorInstance;
- }
-
/**
* Setter for state instance
*
use Org\Mxchange\CoreFramework\Lists\Listable;
use Org\Mxchange\CoreFramework\Registry\Registerable;
use Org\Mxchange\CoreFramework\Task\Taskable;
+use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
use Org\Mxchange\CoreFramework\Visitor\Visitable;
use Org\Mxchange\CoreFramework\Visitor\Visitor;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
+ // Load traits
+ use IteratorTrait;
+
// Exception constants
const EXCEPTION_TASK_IS_INVALID = 0xb00;
use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
+use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
// Import SPL stuff
use \SplFileInfo;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseIndex extends BaseFrameworkSystem {
+ // Load traits
+ use IteratorTrait;
+
/**
* Magic for this index
*/
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
use Org\Mxchange\CoreFramework\Visitor\Visitable;
// Import SPL stuff
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate, Countable {
+ // Load traits
+ use IteratorTrait;
+
// Exception constants
const EXCEPTION_GROUP_ALREADY_ADDED = 0xf20;
const EXCEPTION_GROUP_NOT_FOUND = 0xf21;
// Set it here
$this->setIteratorInstance($iteratorInstance);
- } // END - if
+ }
// And return it
return $iteratorInstance;
* @param $groupName Group to check if found in list
* @return $isset Whether the group is valid
*/
- public function isGroupSet ($groupName) {
+ public function isGroupSet (string $groupName) {
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName);
return isset($this->listGroups[$groupName]);
}
* @return void
* @throws ListGroupAlreadyAddedException If the given group is already added
*/
- public function addGroup ($groupName) {
+ public function addGroup (string $groupName) {
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
// Is the group already added?
if ($this->isGroupSet($groupName)) {
// Throw the exception here
throw new ListGroupAlreadyAddedException(array($this, $groupName), self::EXCEPTION_GROUP_ALREADY_ADDED);
- } // END - if
+ }
// Add the group which is a simple array
$this->listGroups[$groupName] = ObjectFactory::createObjectByConfiguredName('list_group_class');
* @return void
* @throws NoListGroupException If the given group is not found
*/
- public function addInstance ($groupName, $subGroup, Visitable $visitableInstance) {
+ public function addInstance (string $groupName, string $subGroup, Visitable $visitableInstance) {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ',subGroup=' . $subGroup . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!');
if (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
- } // END - if
+ }
// Is the sub group there?
if (!$this->listGroups[$groupName]->isGroupSet($subGroup)) {
// Automatically add it
$this->listGroups[$groupName]->addGroup($subGroup);
- } // END - if
+ }
// Generate the hash
$hash = $this->generateHash($groupName, $subGroup, $visitableInstance);
if ((!is_null($list)) && (!$this->isGroupSet($list))) {
// Throw the exception here
throw new NoListGroupException(array($this, $list), self::EXCEPTION_GROUP_NOT_FOUND);
- } // END - if
+ }
// Init array
$array = [];
if (!is_null($list)) {
// Then get it as well
$array = $this->listGroups[$list]->getArrayFromList(NULL);
- } // END - if
+ }
// Walk through all entries
foreach ($this->listIndex as $hash) {
// Add it
array_push($array, $this->listEntries[$hash]);
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: hash=' . $hash . ',array(' . count($array) . ')=' . print_r($array, true) . ' - ADDED!');
- } // END - if
- } // END - foreach
+ }
+ }
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ',[]=' . count($array) . ' - EXIT!');
* @return void
* @throws NoListGroupException If the given group is not found
*/
- public function addEntry ($groupName, $entry) {
+ public function addEntry (string $groupName, $entry) {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
if (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
- } // END - if
+ }
// Generate hash
$hash = $this->generateHash($groupName, $groupName, $entry);
* @return void
* @throws NoListGroupException If the given group is not found
*/
- public function removeEntry ($groupName, $entry) {
+ public function removeEntry (string $groupName, $entry) {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
if (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
- } // END - if
+ }
// Generate hash
$hash = $this->generateHash($groupName, $groupName, $entry);
* @param $entry An entry of any type
* @return $hash The generated
*/
- private function generateHash ($groupName, $subGroup, $entry) {
+ private function generateHash (string $groupName, string $subGroup, $entry) {
// Created entry, 'null' is default
$entry2 = 'null';
foreach ($groupNames as $groupName) {
// Clear this group
$this->clearGroup($groupName);
- } // END - foreach
+ }
}
/**
* @param $groupName Name of an existing group to clear
* @return void
*/
- protected function clearGroup ($groupName) {
+ protected function clearGroup (string $groupName) {
// Does this group exist?
if (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
- } // END - if
+ }
// Then clear this group list
$this->listGroups[$groupName]->clearList();
if (!$this->isHashValid($hash)) {
// Throw an exception here
throw new InvalidListHashException(array($this, $hash, $hashIndex), self::EXCEPTION_INVALID_HASH);
- } // END - if
+ }
// Now copy the entry
$entry = $this->listEntries[$hash];
* @return $entries The array with all entries
* @throws NoListGroupException If the specified group is invalid
*/
- public function getArrayFromProtocolInstance ($groupName) {
+ public function getArrayFromProtocolInstance (string $groupName) {
// Is the group valid?
if (!$this->isGroupSet($groupName)) {
// Throw the exception here
throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
- } // END - if
+ }
// Init the entries' array
$entries = [];
// Skip to next one
$iteratorInstance->next();
- } // END - while
+ }
// Return the list
return $entries;
if (!$this->isHashValid($hash)) {
// Throw an exception here, hashIndex is unknown at this point
throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH);
- } // END - if
+ }
// Set the entry
$this->listEntries[$hash] = $entryArray;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Generic\NullPointerException;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
// Import SPL stuff
use \IteratorAggregate;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Registerable, IteratorAggregate {
+ // Load traits
+ use IteratorTrait;
+
/**
* Glue for generating a registry key
*/
const REGISTRY_KEY_GLUE = '_';
- /**
- * Instance of this class
- */
- private static $registryInstance = NULL;
-
/**
* Protected constructor
*
use Org\Mxchange\CoreFramework\Index\Indexable;
use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
use Org\Mxchange\CoreFramework\Stacker\BaseStacker;
+use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseFileStack extends BaseStacker {
+ // Load traits
+ use IteratorTrait;
+
// Exception codes
const EXCEPTION_BAD_MAGIC = 0xe100;
* @param $groupName Group to check if found in list
* @return $isset Whether the group is valid
*/
- function isGroupSet ($groupName);
+ function isGroupSet (string $groupName);
/**
* Adds the given group or if already added issues a ListGroupAlreadyAddedException
* @return void
* @throws ListGroupAlreadyAddedException If the given group is already added
*/
- function addGroup ($groupName);
+ function addGroup (string $groupName);
/**
* Adds the given instance to list group and sub group
* @return void
* @throws NoListGroupException If the given group is not found
*/
- function addInstance ($groupName, $subGroup, Visitable $visitableInstance);
+ function addInstance (string $groupName, string $subGroup, Visitable $visitableInstance);
/**
* Adds the given entry to list group
* @return void
* @throws NoListGroupException If the given group is not found
*/
- function addEntry ($groupName, $entry);
+ function addEntry (string $groupName, $entry);
/**
* Updates the given entry by hash with given array
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Traits\Iterator;
+
+// Import SPL stuff
+use \Iterator;
+
+/**
+ * A trait for iterators
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+trait IteratorTrait {
+ /**
+ * Instance of an Iterator class
+ */
+ private $iteratorInstance = NULL;
+
+ /**
+ * Setter for Iterator instance
+ *
+ * @param $iteratorInstance An instance of an Iterator
+ * @return void
+ */
+ protected final function setIteratorInstance (Iterator $iteratorInstance) {
+ $this->iteratorInstance = $iteratorInstance;
+ }
+
+ /**
+ * Getter for Iterator instance
+ *
+ * @return $iteratorInstance An instance of an Iterator
+ */
+ public final function getIteratorInstance () {
+ return $this->iteratorInstance;
+ }
+
+}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Traits\Stream\Input;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Stream\Input\InputStream;
+
+/**
+ * A trait for input stream classes
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+trait InputStreamTrait {
+ /**
+ * An instance of a InputStream class
+ */
+ private $inputStreamInstance = NULL;
+
+ /**
+ * Getter for a InputStream instance
+ *
+ * @param $inputStreamInstance An instance of an InputStream class
+ */
+ protected final function getInputStreamInstance () {
+ return $this->inputStreamInstance;
+ }
+
+ /**
+ * Setter for a InputStream instance
+ *
+ * @param $inputStreamInstance An instance of an InputStream class
+ * @return void
+ */
+ protected final function setInputStreamInstance (InputStream $inputStreamInstance) {
+ $this->inputStreamInstance = $inputStreamInstance;
+ }
+
+}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Traits\Stream\Output;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
+
+/**
+ * A trait for output stream classes
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+trait OutputStreamTrait {
+ /**
+ * An instance of a OutputStream class
+ */
+ private $outputStreamInstance = NULL;
+
+ /**
+ * Getter for a OutputStream instance
+ *
+ * @param $outputStreamInstance An instance of an OutputStream class
+ */
+ protected final function getOutputStreamInstance () {
+ return $this->outputStreamInstance;
+ }
+
+ /**
+ * Setter for a OutputStream instance
+ *
+ * @param $outputStreamInstance An instance of an OutputStream class
+ * @return void
+ */
+ protected final function setOutputStreamInstance (OutputStream $outputStreamInstance) {
+ $this->outputStreamInstance = $outputStreamInstance;
+ }
+
+}