]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 31 Jan 2020 01:33:10 +0000 (02:33 +0100)
committerRoland Häder <roland@mxchange.org>
Fri, 31 Jan 2020 01:33:10 +0000 (02:33 +0100)
- $className means only the short class name, better use $fullClassName instead
  to make it clear that also the namespace is included

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/factories/class_BaseFactory.php
framework/main/classes/factories/objects/class_ObjectFactory.php

index d5d4b79d67bc2359be6d10cd0ec03ca4e585e089..d8ad02ff274a17aba730a8e851618df89b1f19ed 100644 (file)
@@ -41,32 +41,32 @@ abstract class BaseFactory extends BaseFrameworkSystem {
        /**
         * Protected constructor
         *
-        * @param       $className      Name of the real class (not BaseFactory)
+        * @param       $fullClassName  Name of the real class (not BaseFactory)
         * @return      void
         */
-       protected function __construct ($className) {
+       protected function __construct ($fullClassName) {
                // Call parent constructor
-               parent::__construct($className);
+               parent::__construct($fullClassName);
        }
 
        /**
         * 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 ($fullClassName) {
                // Count it up in total sum
                self::$total++;
 
                // Do we have an entry?
-               if (!isset(self::$objectCounters[$className])) {
+               if (!isset(self::$objectCounters[$fullClassName])) {
                        // No, then generate one
-                       self::$objectCounters[$className] = 0;
+                       self::$objectCounters[$fullClassName] = 0;
                } // END - if
 
                // 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]++;
        }
 
        /**
index 6bc459ae7306b438a39450f3220e8ee9294ff1fb..c0c4552dcab0f8640b74b678652e4c7aa9f03899 100644 (file)
@@ -35,12 +35,12 @@ class ObjectFactory extends BaseFactory {
        /**
         * Protected constructor
         *
-        * @param       $className      Name of this class
+        * @param       $fullClassName  Name of this class
         * @return      void
         */
-       protected function __construct ($className = __CLASS__) {
+       protected function __construct ($fullClassName = __CLASS__) {
                // Call parent constructor
-               parent::__construct($className);
+               parent::__construct($fullClassName);
        }
 
        /**
@@ -48,42 +48,42 @@ class ObjectFactory extends BaseFactory {
         * the class was not found. No parameters for the object are currently
         * supported.
         *
-        * @param       $className                      Name of the class we shall construct
+        * @param       $fullClassName                  Name of the class we shall construct
         * @param       $args                           Arguments in an indexed array
         * @return      $objectInstance         An instance of the requested object
         * @throws      NoClassException        If the requested class was not found
         * @throws      InvalidArgumentException        If className is empty or the name not following naming-convention
         */
-       public static final function createObjectByName ($className, array $args = array()) {
+       public static final function createObjectByName ($fullClassName, array $args = array()) {
                // Is the class name valid and is the class there?
-               if (empty($className)) {
+               if (empty($fullClassName)) {
                        // Throw an exception here
                        throw new InvalidArgumentException('Parameter "className" is empty');
-               } elseif (!class_exists($className)) {
+               } elseif (!class_exists($fullClassName)) {
                        // First get an instance of this factory
                        $factoryInstance = new ObjectFactory();
 
                        // Then throw an exception
-                       throw new NoClassException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
+                       throw new NoClassException(array($factoryInstance, $fullClassName), self::EXCEPTION_CLASS_NOT_FOUND);
                }
 
                // Split class name on backslash to check naming-convention
-               $classNameParts = explode("\\", $className);
+               $classNameParts = explode("\\", $fullClassName);
 
                // Okay, does it follow naming-convention?
                if (count($classNameParts) < 4) {
                        // Namespaces are missing
-                       throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Tld\Domain\Project\Package[\SubPackage...]\SomeFooBar', $className));
+                       throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Tld\Domain\Project\Package[\SubPackage...]\SomeFooBar', $fullClassName));
                } // END - if
 
                // Create method name
-               $methodName = sprintf('create%s', self::stripNamespaceFromClassName($className));
+               $methodName = sprintf('create%s', self::stripNamespaceFromClassName($fullClassName));
 
                // Run the user function
-               $objectInstance = call_user_func_array(array($className, $methodName), $args);
+               $objectInstance = call_user_func_array(array($fullClassName, $methodName), $args);
 
                // Count this one up
-               self::countObject($className);
+               self::countObject($fullClassName);
 
                // Return the prepared instance
                return $objectInstance;
@@ -98,10 +98,10 @@ class ObjectFactory extends BaseFactory {
         */
        public static final function createObjectByConfiguredName ($configEntry, array $args = array()) {
                // Read the configuration entry
-               $className = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry);
+               $fullClassName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry);
 
                // Send this to the other factory...
-               $objectInstance = self::createObjectByName($className, $args);
+               $objectInstance = self::createObjectByName($fullClassName, $args);
 
                // Return the instance
                return $objectInstance;
@@ -114,18 +114,11 @@ class ObjectFactory extends BaseFactory {
         *
         * @param       $fullClassName  Class name with namespace
         * @return      $shortClassName Stripped class name (no namespace)
-        * @throws      InvalidArgumentException        If the class name does not follow naming convention
         */
        private static function stripNamespaceFromClassName ($fullClassName) {
                // The class name should contain at least 2 back-slashes, so split at them
                $classNameParts = explode("\\", $fullClassName);
 
-               // At least 4 parts should be there
-               if (count($classNameParts) < 4) {
-                       // Namespace scheme is: Tld\Project\Package[\SubPackage...]
-                       throw new InvalidArgumentException($fullClassName, self::EXCEPTION_INVALID_CLASS_NAME);
-               } // END - if
-
                // Get last element
                $shortClassName = array_pop($classNameParts);