|
|
- <?php
-
- namespace App\Handlers;
-
- use Exception;
-
- /**
- * Factory to getting Handler-Classes
- *
- *
- */
-
- class HandlerFactory
- {
- /**
- * getting handler class if exists
- *
- * @param String $className
- * @return Mixed
- *
- */
- private static function getHandlerClass(String $prefix, String $className)
- {
- $result = NULL;
-
- // create class
- $class = 'App\\Handlers\\'.$prefix.'\\'.$className);
-
- // if not found check for custom handlers
- if (class_exists($class)) {
- $result = new $class();
- } else {
-
- // create class
- $class = 'CustomHandlers\\'.$prefix.'\\'.$className;
-
- if (class_exists($class)) {
- $result = new $class();
- }
- }
-
- // if there is not class throw Exception
- if ($result === NULL) {
- thrown new Exception($prefix.'\\'.$className.' not Found!');
- }
-
- return $result;
- }
- /**
- *
- *
- * @param String $className
- * @return Mixed
- *
- */
- public static function getResponseHandlerClass(String $className)
- {
- return self::getHandlerClass('Response', String $className)
- }
-
- /**
- *
- *
- * @param String $className
- * @return Mixed
- *
- */
- public static function getActionHandlerClass(String $className)
- {
- return self::getHandlerClass('Actions', String $className)
- }
- }
|