|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Devmachine\Bundle\OntheioBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
|
|
|
|
|
6
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
|
|
|
|
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
|
|
12
|
|
|
class ImageController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @Route("/{key}/rotate/{angle}") |
|
16
|
|
|
* |
|
17
|
|
|
* @param string $key |
|
18
|
|
|
* @param int $angle |
|
19
|
|
|
* |
|
20
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
21
|
|
|
*/ |
|
22
|
|
|
public function rotateAction($key, $angle) |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->getClient()->rotate($key, $angle); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @Route("/{key}/delete/{thumb}") |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $key |
|
31
|
|
|
* @param string $thumb |
|
32
|
|
|
* |
|
33
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
34
|
|
|
*/ |
|
35
|
|
|
public function deleteAction($key, $thumb = null) |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->getClient()->delete($key, $thumb); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @Route("/thumbnail") |
|
42
|
|
|
* @Method("POST") |
|
43
|
|
|
* |
|
44
|
|
|
* @param Request $request |
|
45
|
|
|
* |
|
46
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
47
|
|
|
*/ |
|
48
|
|
|
public function thumbnailAction(Request $request) |
|
49
|
|
|
{ |
|
50
|
|
|
$url = $request->request->get('url'); |
|
51
|
|
|
|
|
52
|
|
|
if (!filter_var($url, FILTER_VALIDATE_URL)) { |
|
53
|
|
|
return Response::create('', Response::HTTP_BAD_REQUEST); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$result = [ |
|
57
|
|
|
'key' => null, |
|
58
|
|
|
'width' => null, |
|
59
|
|
|
'height' => null, |
|
60
|
|
|
'original_url' => $url, |
|
61
|
|
|
'error' => null, |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
try { |
|
65
|
|
|
$image = $this->getClient()->uploadByUrl($url); |
|
66
|
|
|
|
|
67
|
|
|
$result['key'] = $image->getKey(); |
|
68
|
|
|
$result['width'] = $image->getWidth(); |
|
69
|
|
|
$result['height'] = $image->getHeight(); |
|
70
|
|
|
} catch (\Exception $e) { |
|
71
|
|
|
$result['error'] = $e->getMessage(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** @var \Twig_Template $template */ |
|
75
|
|
|
$template = $this->get('twig')->loadTemplate('DevmachineOntheioBundle:Form:form_layout.html.twig'); |
|
76
|
|
|
|
|
77
|
|
|
$html = $template->renderBlock('devmachine_ontheio_image_thumbnail', [ |
|
78
|
|
|
'thumb_width' => $request->query->get('width'), |
|
79
|
|
|
'thumb_height' => $request->query->get('height'), |
|
80
|
|
|
'translation_domain' => $request->query->get('trans_domain'), |
|
81
|
|
|
'image' => $result, |
|
82
|
|
|
]); |
|
83
|
|
|
|
|
84
|
|
|
return JsonResponse::create(['html' => $html, 'image' => $result]); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return \Devmachine\Bundle\OntheioBundle\Client\Image\ImageClient |
|
89
|
|
|
*/ |
|
90
|
|
|
private function getClient() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->get('devmachine_ontheio.client.image'); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths