Skip to content

Commit d1c360a

Browse files
committed
Merge pull request #63 from jildertmiedema/event-support
Event support
2 parents 72e98c7 + 1e66ce7 commit d1c360a

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,42 @@ PR is welcome!
4040

4141
![FileManager screenshot 2](http://unisharp.com/img/filemanager2.png)
4242

43+
## Events
44+
45+
To use events you can add a listener to listen to the events
46+
47+
Snippet for `EventServiceProvider`
48+
```php
49+
protected $listen = [
50+
ImageWasUploaded::class => [
51+
UploadListener::class,
52+
],
53+
];
54+
```
55+
56+
The `UploadListener` will look like:
57+
```php
58+
class UploadListener
59+
{
60+
public function handle($event)
61+
{
62+
$method = 'on'.class_basename($event);
63+
if (method_exists($this, $method)) {
64+
call_user_func([$this, $method], $event);
65+
}
66+
}
67+
68+
public function onImageWasUploaded(ImageWasUploaded $event)
69+
{
70+
$path = $event->path();
71+
//your code, for example resizing and cropping
72+
}
73+
}
74+
```
75+
76+
List of events:
77+
* Unisharp\Laravelfilemanager\Events\ImageWasUploaded
78+
4379
## Credits
4480
* All contibutors from GitHub. (issues / PR)
4581
* Special thanks to

src/Events/ImageWasUploaded.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Unisharp\Laravelfilemanager\Events;
4+
5+
class ImageWasUploaded
6+
{
7+
private $path;
8+
9+
public function __construct($path)
10+
{
11+
$this->path = $path;
12+
}
13+
14+
/**
15+
* @return string
16+
*/
17+
public function path()
18+
{
19+
return $this->path;
20+
}
21+
22+
}

src/controllers/UploadController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Unisharp\Laravelfilemanager\controllers;
22

3+
use Illuminate\Support\Facades\Event;
34
use Unisharp\Laravelfilemanager\controllers\Controller;
45
use Illuminate\Support\Facades\Config;
56
use Illuminate\Support\Facades\File;
@@ -8,6 +9,7 @@
89
use Lang;
910
use Intervention\Image\Facades\Image;
1011
use Symfony\Component\HttpFoundation\File\UploadedFile;
12+
use Unisharp\Laravelfilemanager\Events\ImageWasUploaded;
1113

1214
/**
1315
* Class UploadController
@@ -51,6 +53,8 @@ public function upload()
5153
$this->makeThumb($dest_path, $new_filename);
5254
}
5355

56+
Event::fire(new ImageWasUploaded(realpath($dest_path.'/'.$new_filename)));
57+
5458
// upload via ckeditor 'Upload' tab
5559
if (!Input::has('show_list')) {
5660
return $this->useFile($new_filename);

0 commit comments

Comments
 (0)