1 | <?php |
||
12 | class MediaProvider extends BaseProvider |
||
13 | { |
||
14 | protected $mediaManager; |
||
15 | |||
16 | public function __construct(MediaManager $mediaManager) |
||
20 | |||
21 | /** @deprecated */ |
||
22 | public function randomMedia($width = null, $height = null, $type = 'color') |
||
26 | |||
27 | public function randomImage($width = null, $height = null, $type = 'color') |
||
42 | |||
43 | public function randomFile($fileType) |
||
59 | |||
60 | protected function fetchDimensions($width = null, $height = null) |
||
75 | |||
76 | protected function generateUrl($dimensions, $type = 'color') |
||
91 | |||
92 | protected function downloadMedia($url, $ext) |
||
93 | { |
||
94 | $filepath = sys_get_temp_dir() . '/' . uniqid() . '.' . $ext; |
||
95 | $ch = curl_init($url); |
||
96 | $fp = fopen($filepath, 'wb'); |
||
97 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
98 | curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); |
||
99 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
100 | curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
||
101 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
||
102 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); |
||
103 | $raw = curl_exec($ch); |
||
104 | if($raw) { |
||
105 | fwrite($fp, $raw); |
||
106 | } |
||
107 | curl_close($ch); |
||
108 | fclose($fp); |
||
109 | |||
110 | return new File($filepath, 'random'); |
||
|
|||
111 | } |
||
112 | |||
113 | protected function fetchFromCache($key) |
||
114 | { |
||
115 | $fs = new Filesystem(); |
||
116 | $cacheDir = $_SERVER['HOME'] . '/.symfony/media'; |
||
117 | if (!$fs->exists($cacheDir)) { |
||
118 | $fs->mkdir($cacheDir, 0777); |
||
119 | } else { |
||
120 | $cacheDir .= '/' . $key; |
||
121 | if (!$fs->exists($cacheDir)) { |
||
122 | $fs->mkdir($cacheDir, 0777); |
||
123 | } else { |
||
124 | $finder = new Finder(); |
||
125 | $files = $finder->in($cacheDir . '/')->files(); |
||
126 | if (strrpos($key, "file-") !== false || $files->count() === 3) { |
||
127 | try { |
||
128 | $iterator = $finder->getIterator(); |
||
129 | $iterator->rewind(); |
||
130 | for ($i = 0; $i < rand(0, 2); $i++) { |
||
131 | $iterator->next(); |
||
132 | } |
||
133 | $file = new File($iterator->current()); |
||
134 | $fs->copy($file->getRealPath(), sys_get_temp_dir() . '/' . $file->getFilename()); |
||
135 | |||
136 | return new File(sys_get_temp_dir() . '/' . $file->getFilename()); |
||
137 | } catch(FileNotFoundException $e) {} |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | |||
143 | protected function storeInCache($key, File $file) |
||
152 | } |
||
153 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: