Skip to content

Commit

Permalink
Upgrade to Laravel 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gabsource committed Oct 14, 2017
1 parent 71b0185 commit 2326957
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/.idea/
/vendor/
composer.lock
_ide_helper.php
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/[email protected]

Then add the service provider to your configuration :

```php
'providers' => [
Expand All @@ -21,7 +30,6 @@ Add the service provider to your configuration :
],
```


## Configuration

You can customize this package behavior by publishing the configuration file :
Expand Down
28 changes: 24 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,36 @@
"email": "[email protected]"
}
],
"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"
]
}
}
}
19 changes: 16 additions & 3 deletions src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions src/AttachmentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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([
Expand Down Expand Up @@ -48,10 +45,4 @@ public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../config/attachments.php', 'attachments');
}


private function routes($router)
{

}
}
4 changes: 2 additions & 2 deletions src/Console/Commands/CleanupAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions src/HasAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/DropzoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
12 changes: 7 additions & 5 deletions src/Http/Controllers/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand Down

0 comments on commit 2326957

Please sign in to comment.