@@ -50,8 +50,9 @@ |
||
50 | 50 | return $this->transformSingleEntity($data); |
51 | 51 | } |
52 | 52 | |
53 | - if (is_array($data)) |
|
54 | - return $data; |
|
53 | + if (is_array($data)) { |
|
54 | + return $data; |
|
55 | + } |
|
55 | 56 | |
56 | 57 | $return = []; |
57 | 58 | $data = explode('#&#', $data); |
@@ -21,6 +21,10 @@ |
||
21 | 21 | private $class; |
22 | 22 | private $multiple; |
23 | 23 | |
24 | + /** |
|
25 | + * @param string $class |
|
26 | + * @param string $property |
|
27 | + */ |
|
24 | 28 | public function __construct(EntityManager $em, $class, $property, $queryBuilder, $multiple) |
25 | 29 | { |
26 | 30 | if (!(null === $queryBuilder || $queryBuilder instanceof QueryBuilder || $queryBuilder instanceof \Closure)) { |
@@ -33,7 +33,7 @@ |
||
33 | 33 | public function prepend(ContainerBuilder $container) |
34 | 34 | { |
35 | 35 | $parser = new Parser(); |
36 | - $config = $parser->parse(file_get_contents(__DIR__ . '/../Resources/config/config.yml')); |
|
36 | + $config = $parser->parse(file_get_contents(__DIR__.'/../Resources/config/config.yml')); |
|
37 | 37 | |
38 | 38 | foreach ($config as $key => $configuration) { |
39 | 39 | $container->prependExtensionConfig($key, $configuration); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | public function configure() |
16 | 16 | { |
17 | 17 | $this->setName('alpixel:media:cleanup') |
18 | - ->setDescription('Cleaning unused media'); |
|
18 | + ->setDescription('Cleaning unused media'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function execute(InputInterface $input, OutputInterface $output) |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | $container = $this->getContainer(); |
24 | 24 | |
25 | 25 | $container->get('doctrine.orm.entity_manager') |
26 | - ->getRepository('AlpixelMediaBundle:Media') |
|
27 | - ->findExpiredMedias(); |
|
26 | + ->getRepository('AlpixelMediaBundle:Media') |
|
27 | + ->findExpiredMedias(); |
|
28 | 28 | |
29 | 29 | $medias = $container->get('alpixel_media.manager')->cleanup(); |
30 | 30 | $output->writeln(sprintf('%s medias deleted', $medias)); |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | /** |
151 | 151 | * Sets the value of uri. |
152 | 152 | * |
153 | - * @param string $name $uri the uri |
|
154 | 153 | * |
154 | + * @param string $uri |
|
155 | 155 | * @return self |
156 | 156 | */ |
157 | 157 | public function setUri($uri) |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * Sets the value of secretKey. |
176 | 176 | * |
177 | - * @param string $name $secretKey the secret key |
|
178 | 177 | * |
178 | + * @param string $secretKey |
|
179 | 179 | * @return self |
180 | 180 | */ |
181 | 181 | public function setSecretKey($secretKey) |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | /** |
199 | 199 | * Sets the value of mime. |
200 | 200 | * |
201 | - * @param string $name $mime the mime |
|
202 | 201 | * |
202 | + * @param string|null $mime |
|
203 | 203 | * @return self |
204 | 204 | */ |
205 | 205 | public function setMime($mime) |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | /** |
223 | 223 | * Sets the value of lifetime. |
224 | 224 | * |
225 | - * @param string $label $lifetime the lifetime |
|
226 | 225 | * |
226 | + * @param null|\DateTime $lifetime |
|
227 | 227 | * @return self |
228 | 228 | */ |
229 | 229 | public function setLifetime($lifetime) |
@@ -88,6 +88,9 @@ discard block |
||
88 | 88 | return $url; |
89 | 89 | } |
90 | 90 | |
91 | + /** |
|
92 | + * @param string $url |
|
93 | + */ |
|
91 | 94 | protected function downloadMedia($url, $ext) |
92 | 95 | { |
93 | 96 | $filepath = sys_get_temp_dir() . '/' . uniqid() . '.' . $ext; |
@@ -102,6 +105,9 @@ discard block |
||
102 | 105 | return new File($filepath, 'random'); |
103 | 106 | } |
104 | 107 | |
108 | + /** |
|
109 | + * @param string $key |
|
110 | + */ |
|
105 | 111 | protected function fetchFromCache($key) |
106 | 112 | { |
107 | 113 | $fs = new Filesystem(); |
@@ -130,6 +136,9 @@ discard block |
||
130 | 136 | } |
131 | 137 | } |
132 | 138 | |
139 | + /** |
|
140 | + * @param string $key |
|
141 | + */ |
|
133 | 142 | protected function storeInCache($key, File $file) |
134 | 143 | { |
135 | 144 | $fs = new Filesystem(); |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | { |
29 | 29 | do { |
30 | 30 | $dimensions = $this->fetchDimensions($width, $height); |
31 | - $file = $this->fetchFromCache($dimensions['w'] . '-' . $dimensions['h']); |
|
31 | + $file = $this->fetchFromCache($dimensions['w'].'-'.$dimensions['h']); |
|
32 | 32 | if ($file === null) { |
33 | 33 | $file = $this->downloadMedia($this->generateUrl($dimensions, $type), 'jpg'); |
34 | - $this->storeInCache($dimensions['w'] . '-' . $dimensions['h'], $file); |
|
34 | + $this->storeInCache($dimensions['w'].'-'.$dimensions['h'], $file); |
|
35 | 35 | } |
36 | 36 | } while (!preg_match('@^image/@', $file->getMimeType())); |
37 | 37 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | public function randomFile($fileType) |
44 | 44 | { |
45 | - $file = $this->fetchFromCache("file-" . $fileType); |
|
45 | + $file = $this->fetchFromCache("file-".$fileType); |
|
46 | 46 | if ($file === null) { |
47 | 47 | switch ($fileType) { |
48 | 48 | case "pdf": |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | break; |
52 | 52 | } |
53 | 53 | } |
54 | - $this->storeInCache("file-" . $fileType, $file); |
|
54 | + $this->storeInCache("file-".$fileType, $file); |
|
55 | 55 | $media = $this->mediaManager->upload($file); |
56 | 56 | |
57 | 57 | return $media; |
@@ -81,27 +81,27 @@ discard block |
||
81 | 81 | $url .= 'g/'; |
82 | 82 | } |
83 | 83 | |
84 | - $url .= $dimensions['w'] . '/' . $dimensions['h']; |
|
84 | + $url .= $dimensions['w'].'/'.$dimensions['h']; |
|
85 | 85 | |
86 | 86 | $category = ['abstract', 'city', 'nature', 'moutains']; |
87 | - $url .= '/' . $category[array_rand($category, 1)] . '/'; |
|
87 | + $url .= '/'.$category[array_rand($category, 1)].'/'; |
|
88 | 88 | |
89 | 89 | return $url; |
90 | 90 | } |
91 | 91 | |
92 | 92 | protected function downloadMedia($url, $ext) |
93 | 93 | { |
94 | - $filepath = sys_get_temp_dir() . '/' . uniqid() . '.' . $ext; |
|
94 | + $filepath = sys_get_temp_dir().'/'.uniqid().'.'.$ext; |
|
95 | 95 | $ch = curl_init($url); |
96 | 96 | $fp = fopen($filepath, 'wb'); |
97 | 97 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
98 | - curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); |
|
98 | + curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); |
|
99 | 99 | curl_setopt($ch, CURLOPT_HEADER, 0); |
100 | 100 | curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
101 | 101 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
102 | 102 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); |
103 | 103 | $raw = curl_exec($ch); |
104 | - if($raw) { |
|
104 | + if ($raw) { |
|
105 | 105 | fwrite($fp, $raw); |
106 | 106 | } |
107 | 107 | curl_close($ch); |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | protected function fetchFromCache($key) |
114 | 114 | { |
115 | 115 | $fs = new Filesystem(); |
116 | - $cacheDir = $_SERVER['HOME'] . '/.symfony/media'; |
|
116 | + $cacheDir = $_SERVER['HOME'].'/.symfony/media'; |
|
117 | 117 | if (!$fs->exists($cacheDir)) { |
118 | 118 | $fs->mkdir($cacheDir, 0777); |
119 | 119 | } else { |
120 | - $cacheDir .= '/' . $key; |
|
120 | + $cacheDir .= '/'.$key; |
|
121 | 121 | if (!$fs->exists($cacheDir)) { |
122 | 122 | $fs->mkdir($cacheDir, 0777); |
123 | 123 | } else { |
124 | 124 | $finder = new Finder(); |
125 | - $files = $finder->in($cacheDir . '/')->files(); |
|
125 | + $files = $finder->in($cacheDir.'/')->files(); |
|
126 | 126 | if (strrpos($key, "file-") !== false || $files->count() === 3) { |
127 | 127 | try { |
128 | 128 | $iterator = $finder->getIterator(); |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | $iterator->next(); |
132 | 132 | } |
133 | 133 | $file = new File($iterator->current()); |
134 | - $fs->copy($file->getRealPath(), sys_get_temp_dir() . '/' . $file->getFilename()); |
|
134 | + $fs->copy($file->getRealPath(), sys_get_temp_dir().'/'.$file->getFilename()); |
|
135 | 135 | |
136 | - return new File(sys_get_temp_dir() . '/' . $file->getFilename()); |
|
137 | - } catch(FileNotFoundException $e) {} |
|
136 | + return new File(sys_get_temp_dir().'/'.$file->getFilename()); |
|
137 | + } catch (FileNotFoundException $e) {} |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | protected function storeInCache($key, File $file) |
144 | 144 | { |
145 | 145 | $fs = new Filesystem(); |
146 | - $cacheDir = $_SERVER['HOME'] . '/.symfony/media/' . $key; |
|
146 | + $cacheDir = $_SERVER['HOME'].'/.symfony/media/'.$key; |
|
147 | 147 | if (!$fs->exists($cacheDir)) { |
148 | 148 | $fs->mkdir($cacheDir, 0777); |
149 | 149 | } |
150 | - $fs->copy($file->getRealPath(), $cacheDir . '/' . $file->getFilename()); |
|
150 | + $fs->copy($file->getRealPath(), $cacheDir.'/'.$file->getFilename()); |
|
151 | 151 | } |
152 | 152 | } |