]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/factories/objects/class_ObjectFactory.php
Continued:
[core.git] / framework / main / classes / factories / objects / class_ObjectFactory.php
index b10907b53e53795695f6ea2f9984300264b9a214..c081b6bd322943a54205be72217bc53cb5747729 100644 (file)
@@ -35,12 +35,12 @@ class ObjectFactory extends BaseFactory {
        /**
         * Protected constructor
         *
-        * @param       $fullClassName  Name of this class
+        * @param       $className      Name of this class
         * @return      void
         */
-       protected function __construct ($fullClassName = __CLASS__) {
+       protected function __construct (string $className = __CLASS__) {
                // Call parent constructor
-               parent::__construct($fullClassName);
+               parent::__construct($className);
        }
 
        /**
@@ -48,18 +48,18 @@ class ObjectFactory extends BaseFactory {
         * the class was not found. No parameters for the object are currently
         * supported.
         *
-        * @param       $fullClassName                  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 ($fullClassName, array $args = []) {
+       public static final function createObjectByName (string $fullClassName, array $args = []) {
                // Is the class name valid and is the class there?
                if (empty($fullClassName)) {
                        // Throw an exception here
-                       throw new InvalidArgumentException('Parameter "className" is empty');
-               } elseif (!class_exists($fullClassName)) {
+                       throw new InvalidArgumentException('Parameter "fullClassName" is empty');
+               } elseif (!self::isClassCounted($fullClassName) && !class_exists($fullClassName)) {
                        // First get an instance of this factory
                        $factoryInstance = new ObjectFactory();
 
@@ -74,13 +74,13 @@ class ObjectFactory extends BaseFactory {
                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', $fullClassName));
-               } // END - if
+               }
 
                // Create method name
                $methodName = sprintf('create%s', self::stripNamespaceFromClassName($fullClassName));
 
                // Run the user function
-               $objectInstance = call_user_func_array(array($fullClassName, $methodName), $args);
+               $objectInstance = call_user_func_array([$fullClassName, $methodName], $args);
 
                // Count this one up
                self::countObject($fullClassName);
@@ -92,13 +92,13 @@ class ObjectFactory extends BaseFactory {
        /**
         * Creates an object by it's configured name
         *
-        * @param       $configEnttry           Configuration entry to read
+        * @param       $configKey              Configuration key to read
         * @param       $args                           Arguments in an indexed array
         * @return      $objectInstance         An instance of the requested object
         */
-       public static final function createObjectByConfiguredName ($configEntry, array $args = []) {
+       public static final function createObjectByConfiguredName (string $configKey, array $args = []) {
                // Read the configuration entry
-               $fullClassName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry);
+               $fullClassName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configKey);
 
                // Send this to the other factory...
                $objectInstance = self::createObjectByName($fullClassName, $args);
@@ -115,7 +115,7 @@ class ObjectFactory extends BaseFactory {
         * @param       $fullClassName  Class name with namespace
         * @return      $shortClassName Stripped class name (no namespace)
         */
-       private static function stripNamespaceFromClassName ($fullClassName) {
+       private static function stripNamespaceFromClassName (string $fullClassName) {
                // The class name should contain at least 2 back-slashes, so split at them
                $classNameParts = explode("\\", $fullClassName);