From 2326957ce384e0f310fc62c18056b37435a95cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Gaulin?= Date: Sat, 14 Oct 2017 17:50:54 +0400 Subject: [PATCH] Upgrade to Laravel 5.5 --- .gitignore | 3 +++ README.md | 16 +++++++++--- composer.json | 28 ++++++++++++++++++--- src/Attachment.php | 19 +++++++++++--- src/AttachmentsServiceProvider.php | 11 +------- src/Console/Commands/CleanupAttachments.php | 4 +-- src/HasAttachment.php | 1 + src/Http/Controllers/DropzoneController.php | 2 +- src/Http/Controllers/ShareController.php | 12 +++++---- 9 files changed, 67 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 57872d0..471340b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ +/.idea/ /vendor/ +composer.lock +_ide_helper.php \ No newline at end of file diff --git a/README.md b/README.md index 80682f1..9997e56 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,24 @@ -# Laravel 5.4+ file attachment helpers +# Laravel 5.5 file attachment helpers This package allows to quickly links files to models. +> Can also be installed on Laravel 5.4, [see below](#older-laravel-54-install) + ## Installation -You can install this package via composer : +You can install this package via composer. Laravel 5.5 auto discovers the service provider. composer require bnbwebexpertise/laravel-attachments + + +### Older Laravel 5.4 install -Add the service provider to your configuration : +For 5.4 support install version 0.0.16 : + + composer require bnbwebexpertise/laravel-attachments@0.0.16 + +Then add the service provider to your configuration : ```php 'providers' => [ @@ -21,7 +30,6 @@ Add the service provider to your configuration : ], ``` - ## Configuration You can customize this package behavior by publishing the configuration file : diff --git a/composer.json b/composer.json index c197722..efc6018 100644 --- a/composer.json +++ b/composer.json @@ -9,16 +9,36 @@ "email": "support@bnb.re" } ], - "minimum-stability": "stable", "require": { - "php": ">=5.6.4", - "laravel/framework": ">=5.4.0", + "php": ">=7.0", + "illuminate/database": "5.5.x", + "illuminate/routing": "5.5.x", + "illuminate/support": "5.5.x", + "illuminate/console": "5.5.x", + "illuminate/encryption": "5.5.x", "bnbwebexpertise/php-uuid": ">=0.0.2", - "doctrine/dbal": "^2.5" + "doctrine/dbal": "~2.5", + "nesbot/carbon": "~1.20" + }, + "require-dev": { + "laravel/framework": "5.5.x" }, + "minimum-stability": "stable", + "prefer-stable": true, "autoload": { "psr-4": { "Bnb\\Laravel\\Attachments\\": "src/" } + }, + "extra": { + "branch-alias": { + "dev-master": "1.x-dev", + "dev-L5.4": "0.x-dev" + }, + "laravel": { + "providers": [ + "Bnb\\Laravel\\Attachments\\AttachmentsServiceProvider" + ] + } } } diff --git a/src/Attachment.php b/src/Attachment.php index a3c112c..b241fd5 100644 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -54,8 +54,9 @@ class Attachment extends Model * * @param string $uuid * @param Model $model a model that uses HasAttachment + * @param array $options filter options based on configuration key `attachments.attributes` * - * @return self|null + * @return Attachment|null */ public static function attach($uuid, $model, $options = []) { @@ -328,7 +329,7 @@ protected function putFile($sourcePath, $filePath = null) ! FileHelper::makeDirectory($destinationPath, 0777, true, true) && ! FileHelper::isDirectory($destinationPath) ) { - trigger_error(error_get_last(), E_USER_WARNING); + trigger_error(error_get_last()['message'], E_USER_WARNING); } return FileHelper::copy($sourcePath, $destinationPath . basename($filePath)); @@ -434,7 +435,9 @@ protected function isLocalStorage() /** * Returns true if a directory contains no files. * - * @return boolean + * @param string|null $dir the directory path + * + * @return bool */ protected function isDirectoryEmpty($dir) { @@ -448,6 +451,11 @@ protected function isDirectoryEmpty($dir) /** * Copy the local file to Storage + * + * @param string $localPath + * @param string $storagePath + * + * @return bool */ protected function copyToStorage($localPath, $storagePath) { @@ -459,6 +467,8 @@ protected function copyToStorage($localPath, $storagePath) * Checks if directory is empty then deletes it, * three levels up to match the partition directory. * + * @param string|null $dir the directory path + * * @return void */ protected function deleteEmptyDirectory($dir = null) @@ -493,6 +503,9 @@ protected function deleteEmptyDirectory($dir = null) * also good for performance. For local storage, *every* argument * is prefixed with the local root path. * + * @param string $string the command string + * @param string $filepath the path on storage + * * @return mixed */ protected function storageCommand($string, $filepath) diff --git a/src/AttachmentsServiceProvider.php b/src/AttachmentsServiceProvider.php index ab1b35c..36068d5 100644 --- a/src/AttachmentsServiceProvider.php +++ b/src/AttachmentsServiceProvider.php @@ -3,7 +3,6 @@ namespace Bnb\Laravel\Attachments; use Bnb\Laravel\Attachments\Console\Commands\CleanupAttachments; -use Illuminate\Routing\Router; use Illuminate\Support\ServiceProvider; class AttachmentsServiceProvider extends ServiceProvider @@ -12,11 +11,9 @@ class AttachmentsServiceProvider extends ServiceProvider /** * Bootstrap the application services. * - * @param Router $router - * * @return void */ - public function boot(Router $router) + public function boot() { $this->publishes([ @@ -48,10 +45,4 @@ public function register() { $this->mergeConfigFrom(__DIR__ . '/../config/attachments.php', 'attachments'); } - - - private function routes($router) - { - - } } diff --git a/src/Console/Commands/CleanupAttachments.php b/src/Console/Commands/CleanupAttachments.php index f7f8b9c..ef5c25c 100644 --- a/src/Console/Commands/CleanupAttachments.php +++ b/src/Console/Commands/CleanupAttachments.php @@ -23,10 +23,10 @@ class CleanupAttachments extends Command public function __construct() { - $this->description = Lang::get('attachments::messages.console.cleanup_description'); - parent::__construct(); + $this->setDescription(Lang::get('attachments::messages.console.cleanup_description')); + $this->getDefinition()->addOption(new InputOption('since', '-s', InputOption::VALUE_OPTIONAL, Lang::get('attachments::messages.console.cleanup_option_since'), 1440)); } diff --git a/src/HasAttachment.php b/src/HasAttachment.php index eea3b6e..56ff4b7 100644 --- a/src/HasAttachment.php +++ b/src/HasAttachment.php @@ -50,6 +50,7 @@ public function attachmentsGroup($group) * @param array $options Set attachment options : title, description, key, disk * * @return Attachment|null + * @throws \Exception */ public function attach($fileOrPath, $options = []) { diff --git a/src/Http/Controllers/DropzoneController.php b/src/Http/Controllers/DropzoneController.php index a7563cf..23ccdd3 100644 --- a/src/Http/Controllers/DropzoneController.php +++ b/src/Http/Controllers/DropzoneController.php @@ -76,7 +76,7 @@ public function delete($id, Request $request) } catch (Exception $e) { Log::error('Failed to delete attachment : ' . $e->getMessage(), ['id' => $id, 'trace' => $e->getTraceAsString()]); - response(Lang::get('attachments::messages.errors.delete_failed'), 500); + return response(Lang::get('attachments::messages.errors.delete_failed'), 500); } } } \ No newline at end of file diff --git a/src/Http/Controllers/ShareController.php b/src/Http/Controllers/ShareController.php index 5fd16e4..b9a4a1e 100644 --- a/src/Http/Controllers/ShareController.php +++ b/src/Http/Controllers/ShareController.php @@ -17,14 +17,16 @@ public function download($token, Request $request) { try { $data = json_decode(Crypt::decryptString($token)); - $id = $data->id; - $expire = $data->expire; - - } catch(DecryptException $e) { + } catch (DecryptException $e) { abort(404, Lang::get('attachments::messages.errors.file_not_found')); + + return; } - if(Carbon::createFromTimestamp($expire)->isPast()) { + $id = $data->id; + $expire = $data->expire; + + if (Carbon::createFromTimestamp($expire)->isPast()) { abort(403, Lang::get('attachments::messages.errors.expired')); }