@ -1,26 +0,0 @@ | |||
<?php | |||
namespace App\ResponseHandler; | |||
use App\Handlers\Handler; | |||
/** | |||
* | |||
* | |||
* | |||
*/ | |||
class ActionHandler extends Handler implements ActionHandlerInterface | |||
{ | |||
protected $data; | |||
/** | |||
* | |||
* @param mixed $data | |||
* | |||
*/ | |||
public function __construct($data) | |||
{ | |||
$this->data = $data; | |||
} | |||
} |
@ -0,0 +1,39 @@ | |||
<?php | |||
namespace App\Handlers\Actions; | |||
/** | |||
* | |||
* | |||
* | |||
*/ | |||
class ActionHandler implements ActionHandlerInterface | |||
{ | |||
// data to process in a action | |||
protected $data; | |||
/** | |||
* | |||
* @param [type] $data | |||
* @return [type] | |||
*/ | |||
protected function processActions($source, $response, $data) | |||
{ | |||
foreach($this->source->actions() as $action) { | |||
HandlerFactory::getActionHandlerClass($action->response_handler_class); | |||
$action = new ActionClass($this->source, $data); | |||
$action->run(); | |||
} | |||
} | |||
/** | |||
* | |||
* @param mixed $data | |||
* | |||
*/ | |||
public function __construct($data) | |||
{ | |||
$this->data = $data; | |||
} | |||
} |
@ -1,12 +1,15 @@ | |||
<?php | |||
namespace App\Handlers\Action; | |||
namespace App\Handlers\Actions; | |||
/** | |||
* | |||
* | |||
* | |||
*/ | |||
interface ActionInterface | |||
{ | |||
// method to process data | |||
public function run(); | |||
} |
@ -1,42 +0,0 @@ | |||
<?php | |||
namespace App\Handlers; | |||
/** | |||
* | |||
* | |||
* | |||
*/ | |||
abstract class Handler | |||
{ | |||
/** | |||
* | |||
* | |||
* @param String $className | |||
* @return Mixed | |||
* | |||
*/ | |||
protected function getHandlerClass(String $className) | |||
{ | |||
$result = NULL; | |||
// create class | |||
$class = 'App\\Handlers\\'.$className); | |||
// if not found check for custom handlers | |||
if (class_exists($class)) { | |||
$result = new $class(); | |||
} else { | |||
// create class | |||
$class = 'CustomHandlers\\'.$className; | |||
if (class_exists($class)) { | |||
$result = new $class(); | |||
} | |||
} | |||
return $result; | |||
} | |||
} |
@ -0,0 +1,72 @@ | |||
<?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) | |||
} | |||
} |
@ -0,0 +1,17 @@ | |||
<?php | |||
namespace CustomHandlers\Actions; | |||
/** | |||
* | |||
* | |||
* | |||
*/ | |||
class FileDownload extends ActionHandler | |||
{ | |||
public function run() | |||
{ | |||
} | |||
} |
@ -1,13 +0,0 @@ | |||
<?php | |||
namespace CustomHandlers\Actions; | |||
/** | |||
* | |||
* | |||
* | |||
*/ | |||
class FileMove extends ActionHandler { | |||
} |