1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the IrishDan\ResponsiveImageBundle package. |
4
|
|
|
* |
5
|
|
|
* (c) Daniel Byrne <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE file that was distributed with this source |
8
|
|
|
* code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace IrishDan\ResponsiveImageBundle\EventSubscriber; |
12
|
|
|
|
13
|
|
|
use IrishDan\ResponsiveImageBundle\Event\UploaderEvent; |
14
|
|
|
use IrishDan\ResponsiveImageBundle\Event\UploaderEvents; |
15
|
|
|
use League\Flysystem\FilesystemInterface; |
16
|
|
|
|
17
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class UploaderSubscriber |
21
|
|
|
* |
22
|
|
|
* @package IrishDan\ResponsiveImageBundle\EventSubscriber |
23
|
|
|
*/ |
24
|
|
|
class UploaderSubscriber implements EventSubscriberInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var FilesystemInterface |
28
|
|
|
*/ |
29
|
|
|
private $fileSystem; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* UploaderSubscriber constructor. |
33
|
|
|
* |
34
|
|
|
* @param FilesystemInterface $fileSystem |
35
|
|
|
*/ |
36
|
|
|
public function __construct(FilesystemInterface $fileSystem) |
37
|
|
|
{ |
38
|
|
|
$this->fileSystem = $fileSystem; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public static function getSubscribedEvents() |
45
|
|
|
{ |
46
|
|
|
return [ |
47
|
|
|
UploaderEvents::UPLOADER_PRE_UPLOAD => 'onPreUpload', |
48
|
|
|
UploaderEvents::UPLOADER_UPLOADED => 'onUploaded', |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param UploaderEvent $event |
54
|
|
|
*/ |
55
|
|
|
public function onPreUpload(UploaderEvent $event) |
56
|
|
|
{ |
57
|
|
|
// This is how we can swap filesystems. |
58
|
|
|
$uploader = $event->getUploader(); |
59
|
|
|
|
60
|
|
|
if (empty($uploader->getFileSystem())) { |
61
|
|
|
$uploader->setFileSystem($this->fileSystem); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param UploaderEvent $event |
67
|
|
|
*/ |
68
|
|
|
public function onUploaded(UploaderEvent $event) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
// @TODO: Implement |
71
|
|
|
} |
72
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.