@@ -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 | } |