From 47afa95e0773ed3861d8630132a223d51f0340f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Fri, 21 May 2021 12:24:27 +0200 Subject: [PATCH] adding --- app/Commands/CrawlerRunCommand.php | 29 ++++---- app/Handlers/Action/ActionHandler.php | 26 ------- app/Handlers/Actions/ActionHandler.php | 39 ++++++++++ .../{Action => Actions}/ActionInterface.php | 5 +- app/Handlers/Handler.php | 42 ----------- app/Handlers/HandlerFactory.php | 72 +++++++++++++++++++ app/Handlers/Response/ResponseHandler.php | 9 +-- .../Response/ResponseHandlerInterface.php | 2 +- .../CustomHandlers/Action/FileDownload.php | 17 +++++ resources/CustomHandlers/Action/FileMove.php | 13 ---- resources/CustomHandlers/Response/Rss.php | 13 ++-- 11 files changed, 161 insertions(+), 106 deletions(-) delete mode 100644 app/Handlers/Action/ActionHandler.php create mode 100644 app/Handlers/Actions/ActionHandler.php rename app/Handlers/{Action => Actions}/ActionInterface.php (54%) delete mode 100644 app/Handlers/Handler.php create mode 100644 app/Handlers/HandlerFactory.php create mode 100644 resources/CustomHandlers/Action/FileDownload.php delete mode 100644 resources/CustomHandlers/Action/FileMove.php diff --git a/app/Commands/CrawlerRunCommand.php b/app/Commands/CrawlerRunCommand.php index 61e8f98..eaa7f7a 100644 --- a/app/Commands/CrawlerRunCommand.php +++ b/app/Commands/CrawlerRunCommand.php @@ -5,7 +5,9 @@ namespace App\Commands; use Illuminate\Console\Scheduling\Schedule; use LaravelZero\Framework\Commands\Command; use Illuminate\Support\Facades\Http; -use SimpleXMLElement; + +use App\Handlers\HandlerFactory; + class CrawlerRunCommand extends Command { @@ -35,24 +37,23 @@ class CrawlerRunCommand extends Command 'https://steadyhq.com/rss/insertmoin?auth=d37bffc9-9a84-4eed-95f6-3b6cb77c2406' ]; - $handlerClass = $source->response_handler_class; + foreach ($sources as $source) { - $handler = new $handlerClass($source); - $response = $handler->getResponse(); + // getting handler class and create object + $handlerClass = HandlerFactory::getResponseHandlerClass($source->response_handler_class); + $handler = new $handlerClass($source); - // if it is a 200 - if ($response->ok()) { - $handler->run(); + $response = $handler->getResponse(); - // if there is an error on the source - } else if ($response->serverError()) { + // if it is a 200 + if ($response->ok()) { + $handler->run(); - } - } - - private function get($url, $handler) - { + // if there is an error on the source + } else if ($response->serverError()) { + } + } } /** diff --git a/app/Handlers/Action/ActionHandler.php b/app/Handlers/Action/ActionHandler.php deleted file mode 100644 index a3a6226..0000000 --- a/app/Handlers/Action/ActionHandler.php +++ /dev/null @@ -1,26 +0,0 @@ -data = $data; - } -} \ No newline at end of file diff --git a/app/Handlers/Actions/ActionHandler.php b/app/Handlers/Actions/ActionHandler.php new file mode 100644 index 0000000..a7ff729 --- /dev/null +++ b/app/Handlers/Actions/ActionHandler.php @@ -0,0 +1,39 @@ +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; + } +} \ No newline at end of file diff --git a/app/Handlers/Action/ActionInterface.php b/app/Handlers/Actions/ActionInterface.php similarity index 54% rename from app/Handlers/Action/ActionInterface.php rename to app/Handlers/Actions/ActionInterface.php index eefcc9e..cc5be18 100644 --- a/app/Handlers/Action/ActionInterface.php +++ b/app/Handlers/Actions/ActionInterface.php @@ -1,12 +1,15 @@ response->body()); - foreach($xml->channel->item as $item) { - foreach($this->actions as $action) { - $actionClass = $action->action_handler_class; - $action = new ActionClass($item); - $action->run(); + // only process if xml is valid + if ($xml) { + foreach($xml->channel->item as $item) { + $this->processActions($item); } } }