]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/factories/class_BaseFactory.php
Continued:
[core.git] / framework / main / classes / factories / class_BaseFactory.php
index cf65d4ae55361b307cfa039b9bb4d1e48bf43b23..5b16ef500c963df9286d3cad54af59073ba95068 100644 (file)
@@ -10,7 +10,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
  *
  * @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 - 2020 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -27,7 +27,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class BaseFactory extends BaseFrameworkSystem {
+abstract class BaseFactory extends BaseFrameworkSystem {
        /**
         * Total objects generated
         */
@@ -36,7 +36,7 @@ class BaseFactory extends BaseFrameworkSystem {
        /**
         * Counter of all objects
         */
-       private static $objectCounters = array();
+       private static $objectCounters = [];
 
        /**
         * Protected constructor
@@ -44,7 +44,7 @@ class BaseFactory extends BaseFrameworkSystem {
         * @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);
        }
@@ -52,21 +52,21 @@ class BaseFactory extends BaseFrameworkSystem {
        /**
         * Count given object
         *
-        * @param       $className      Name of the class we shall count
+        * @param       $fullClassName  Name of the class we shall count
         */
-       protected static final function countObject ($className) {
+       protected static final function countObject (string $fullClassName) {
                // 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]++;
        }
 
        /**
@@ -87,4 +87,15 @@ class BaseFactory extends BaseFrameworkSystem {
                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
+        */
+       protected static final function isClassCounted (string $fullClassName) {
+               // Return isset() result
+               return isset(self::$objectCounters[$fullClassName]);
+       }
+
 }