1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\MediaBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\MediaBundle\Entity\Folder; |
6
|
|
|
use Kunstmaan\MediaBundle\Entity\Media; |
7
|
|
|
use Kunstmaan\MediaBundle\Helper\MediaManager; |
8
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Controller class which Aviary can use to upload the edited image and add it to the database |
15
|
|
|
* |
16
|
|
|
* @deprecated The AviaryController is deprecated in KunstmaanMediaBundle 5.7 and will be removed in KunstmaanMediaBundle 6.0. The aviary service is discontinued. |
17
|
|
|
*/ |
18
|
|
|
class AviaryController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param Request $request |
22
|
|
|
* @param int $folderId The id of the Folder |
23
|
|
|
* @param int $mediaId The id of the image |
24
|
|
|
* |
25
|
|
|
* @Route("/aviary/{folderId}/{mediaId}", requirements={"folderId" = "\d+", "mediaId" = "\d+"}, name="KunstmaanMediaBundle_aviary") |
26
|
|
|
* |
27
|
|
|
* @return RedirectResponse |
28
|
|
|
*/ |
29
|
|
|
public function indexAction(Request $request, $folderId, $mediaId) |
30
|
|
|
{ |
31
|
|
|
$em = $this->getDoctrine()->getManager(); |
32
|
|
|
|
33
|
|
|
/* @var Folder $folder */ |
34
|
|
|
$folder = $em->getRepository(Folder::class)->getFolder($folderId); |
|
|
|
|
35
|
|
|
/* @var Media $media */ |
36
|
|
|
$media = $em->getRepository(Media::class)->getMedia($mediaId); |
|
|
|
|
37
|
|
|
/* @var MediaManager $mediaManager */ |
38
|
|
|
$mediaManager = $this->get('kunstmaan_media.media_manager'); |
39
|
|
|
|
40
|
|
|
$media = clone $media; |
41
|
|
|
$handler = $mediaManager->getHandler($media); |
42
|
|
|
$fileHelper = $handler->getFormHelper($media); |
43
|
|
|
$fileHelper->getMediaFromUrl($request->get('url')); |
44
|
|
|
$media = $fileHelper->getMedia(); |
45
|
|
|
|
46
|
|
|
$media->setUuid(null); |
47
|
|
|
$handler->prepareMedia($media); |
48
|
|
|
|
49
|
|
|
$em->persist($media); |
50
|
|
|
$em->flush(); |
51
|
|
|
|
52
|
|
|
$media->setCreatedAt($media->getUpdatedAt()); |
53
|
|
|
$em->persist($media); |
54
|
|
|
$em->flush(); |
55
|
|
|
|
56
|
|
|
return new RedirectResponse( |
57
|
|
|
$this->generateUrl( |
58
|
|
|
'KunstmaanMediaBundle_folder_show', |
59
|
|
|
array('folderId' => $folder->getId()) |
60
|
|
|
) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: