namespace Org\Mxchange\CoreFramework\Factory;
// Import framework stuff
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A general (base) factory
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
/**
* Counter of all objects
*/
- private static $objectCounters = array();
+ private static $objectCounters = [];
/**
* Protected constructor
* @param $className Name of the real class (not BaseFactory)
* @return void
*/
- protected function __construct ($className) {
+ protected function __construct (string $className) {
// Call parent constructor
parent::__construct($className);
}
/**
* Count given object
*
- * @param $className Name of the class we shall count
+ * @param $fullClassName Name of the class we shall count
+ * @return void
+ * @throws InvalidArgumentException If a parameter is not valid
*/
- protected static final function countObject ($className) {
+ protected static final function countObject (string $fullClassName) {
+ // Is the parameter valid?
+ if (empty($fullClassName)) {
+ // No empty class name
+ throw new InvalidArgumentException('fullClassName is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
// Count it up in total sum
self::$total++;
// Do we have an entry?
- if (!isset(self::$objectCounters[$className])) {
+ if (!self::isClassCounted($fullClassName)) {
// No, then generate one
- self::$objectCounters[$className] = 0;
- } // END - if
+ self::$objectCounters[$fullClassName] = 0;
+ }
// Count it up again
- //* NOISY-DEBUG: */ print __METHOD__.': className=' .$className . PHP_EOL;
- self::$objectCounters[$className]++;
+ //* NOISY-DEBUG: */ print __METHOD__.': className=' .$fullClassName . PHP_EOL;
+ self::$objectCounters[$fullClassName]++;
}
/**
return self::$objectCounters;
}
+ /**
+ * Checks whether given full class name is already counted
+ *
+ * @param $fullClassName Full name of class
+ * @return $isCounted Whether given class name is counted
+ * @throws InvalidArgumentException If a parameter is not valid
+ */
+ public static final function isClassCounted (string $fullClassName) {
+ // Is the parameter valid?
+ if (empty($fullClassName)) {
+ // No empty class name
+ throw new InvalidArgumentException('fullClassName is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ }
+
+ // Return isset() result
+ return isset(self::$objectCounters[$fullClassName]);
+ }
+
}