]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/feature/class_FrameworkFeature.php
Continued:
[core.git] / framework / main / classes / feature / class_FrameworkFeature.php
index db57e5cc6759c3bd90bb775397c411eb0340c5e6..58610e4082649beacdc3cf438e33cb7e2e49665b 100644 (file)
@@ -5,11 +5,13 @@ namespace Org\Mxchange\CoreFramework\Feature;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Loader\NoClassException;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
 
 // Import SPL stuff
+use \BadMethodCallException;
 use \InvalidArgumentException;
 
 /**
@@ -83,7 +85,7 @@ class FrameworkFeature extends BaseFrameworkSystem {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FRAMEWORK-FEATURE: featureName=%s - CALLED!', $featureName));
                if (empty($featureName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "featureName" is empty');
+                       throw new InvalidArgumentException('Parameter "featureName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Is the cache set?
@@ -116,7 +118,7 @@ class FrameworkFeature extends BaseFrameworkSystem {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FRAMEWORK-FEATURE: featureName=%s - CALLED!', $featureName));
                if (empty($featureName)) {
                        // Throw IAE
-                       throw new InvalidArgumentException('Parameter "featureName" is empty');
+                       throw new InvalidArgumentException('Parameter "featureName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
                }
 
                // Is the cache set?
@@ -163,15 +165,23 @@ class FrameworkFeature extends BaseFrameworkSystem {
         * @param       $featureMethod  Method name of the feature's class
         * @param       $args                   Any arguments that should be handled over
         * @return      $return                 Anything the feature's method has returned
+        * @throws      InvalidArgumentException        If a parameter has an invalid value
+        * @throws      BadMethodCallException  If this method has been invoked but the feature isn't available
         * @throws      FeatureMethodNotCallableException       If the requested method cannot be called
         */
-       public static function callFeature ($featureName, $featureMethod, array $args = NULL) {
-               /*
-                * Please make sure that isFeatureAvailable() has been called and it has
-                * returned true before calling this method.
-                */
+       public static function callFeature (string $featureName, string $featureMethod, array $args = NULL) {
+               // Check parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FRAMEWORK-FEATURE: featureName=%s,featureMethod=%s,args[]=%s - CALLED!', $featureName, $featureMethod, gettype($args)));
-               assert(self::isFeatureAvailable($featureName));
+               if (empty($featureName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "featureName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (empty($featureMethod)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "featureMethod" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!self::isFeatureAvailable($featureName)) {
+                       // Throw BMCE
+                       throw new BadMethodCallException(sprintf('Feature "%s" is not available but method "%s" should be invoked.', $featureName, $featureMethod), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
+               }
 
                // Array for call-back
                $callable = array(