diff --git a/app/Handlers/Actions/ActionHandler.php b/app/Handlers/Actions/ActionHandler.php index a7ff729..b8e0d1a 100644 --- a/app/Handlers/Actions/ActionHandler.php +++ b/app/Handlers/Actions/ActionHandler.php @@ -13,20 +13,6 @@ 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 diff --git a/app/Handlers/Response/ResponseHandler.php b/app/Handlers/Response/ResponseHandler.php index 9f5b35c..36de7af 100644 --- a/app/Handlers/Response/ResponseHandler.php +++ b/app/Handlers/Response/ResponseHandler.php @@ -24,4 +24,18 @@ class ResponseHandler implements ResponseHandlerInterface { $this->source = $source; } + + /** + * + * @param [type] $data + * @return [type] + */ + protected function processActions($data) + { + foreach($this->source->actions() as $action) { + HandlerFactory::getActionHandlerClass($action->action_handler_class); + $action = new ActionClass($this->source, $this->response, $data); + $action->run(); + } + } } \ No newline at end of file diff --git a/composer.json b/composer.json index 27b19ce..973df1d 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "illuminate/http": "^7.0", "illuminate/log": "^7.0", "laravel-zero/framework": "^7.0", - "nunomaduro/laravel-console-menu": "^3.0" + "nunomaduro/laravel-console-menu": "^3.0", + "ralouphie/mimey": "^2.1" }, "require-dev": { "fzaninotto/faker": "^1.4", @@ -31,7 +32,8 @@ }, "autoload": { "psr-4": { - "App\\": "app/" + "App\\": "app/", + "CustomHandlers\\": "resources/CustomHandlers/" } }, "autoload-dev": { diff --git a/composer.lock b/composer.lock index a90e2bb..e9986e6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ac74c34c116ba452cd3b28f38c918e86", + "content-hash": "01f46875cfca1c919f8e66d42dcf772f", "packages": [ { "name": "beberlei/assert", @@ -2594,6 +2594,46 @@ }, "time": "2019-03-08T08:55:37+00:00" }, + { + "name": "ralouphie/mimey", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/mimey.git", + "reference": "8f74e6da73f9df7bd965e4e123f3d8fb9acb89ba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/mimey/zipball/8f74e6da73f9df7bd965e4e123f3d8fb9acb89ba", + "reference": "8f74e6da73f9df7bd965e4e123f3d8fb9acb89ba", + "shasum": "" + }, + "require": { + "php": "^5.4|^7.0" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^1.1", + "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Mimey\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "PHP package for converting file extensions to MIME types and vice versa.", + "time": "2019-03-08T08:49:03+00:00" + }, { "name": "ramsey/uuid", "version": "3.9.3", @@ -6480,5 +6520,5 @@ "platform-overrides": { "php": "7.4.18" }, - "plugin-api-version": "2.0.0" + "plugin-api-version": "1.1.0" } diff --git a/resources/CustomHandlers/Action/FileDownload.php b/resources/CustomHandlers/Action/FileDownload.php index 5089c15..132edb2 100644 --- a/resources/CustomHandlers/Action/FileDownload.php +++ b/resources/CustomHandlers/Action/FileDownload.php @@ -2,6 +2,11 @@ namespace CustomHandlers\Actions; +use Illuminate\Support\Facades\File; +use Illuminate\Support\Str; + +use Mimey\MimeTypes; + /** * * @@ -12,6 +17,19 @@ class FileDownload extends ActionHandler { public function run() { - + if (isset($this->data->enclosure) && isset($this->data->enclosure->attributes()->url)) { + + // get mimes + $mimes = new MimeTypes(); + $extension = $mimes->getExtension($this->data->enclosure->attributes()->type); + + // if extension valid + if ($extension) { + $filename = Str::slug($this->data->title).'.'.$extension; + Storage::download($this->data->enclosure->attributes()->url)->put($filename); + } else { + // @TODO what you do + } + } } } \ No newline at end of file