1 | <?php |
||
11 | class ImageUploadSubscriber implements ContainerAwareInterface, EventSubscriber |
||
12 | { |
||
13 | /** |
||
14 | * @var ContainerInterface; |
||
15 | */ |
||
16 | private $container; |
||
17 | |||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | public function setContainer(ContainerInterface $container = null) |
||
25 | |||
26 | /** |
||
27 | * @param $subject |
||
28 | */ |
||
29 | private function upload($subject) |
||
30 | { |
||
31 | if ($subject instanceof ImageInterface && $subject->hasFile()) { |
||
32 | $this->container->get('dos.image_uploader')->upload($subject); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function prePersist(LifecycleEventArgs $event) |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function preUpdate(LifecycleEventArgs $event) |
||
48 | { |
||
49 | $this->upload($event->getObject()); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function getSubscribedEvents() |
||
62 | } |
||
63 |