@@ -126,6 +126,9 @@ |
||
126 | 126 | ); |
127 | 127 | } |
128 | 128 | |
129 | + /** |
|
130 | + * @param resource $handle |
|
131 | + */ |
|
129 | 132 | private function writeFromRessource($handle) |
130 | 133 | { |
131 | 134 |
@@ -129,7 +129,7 @@ |
||
129 | 129 | private function writeFromRessource($handle) |
130 | 130 | { |
131 | 131 | |
132 | - if (! $handle) { |
|
132 | + if ( ! $handle) { |
|
133 | 133 | trigger_error(E_ERROR, 'can not open the destination file'); |
134 | 134 | } |
135 | 135 | $written = 0; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function find(array $query = array(), array $fields = array()) |
93 | 93 | { |
94 | - $cursor = new MongoGridFSCursor($this, $this->db->getConnection(), (string)$this, $query, $fields); |
|
94 | + $cursor = new MongoGridFSCursor($this, $this->db->getConnection(), (string) $this, $query, $fields); |
|
95 | 95 | $cursor->setReadPreference($this->getReadPreference()); |
96 | 96 | |
97 | 97 | return $cursor; |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | $shortName = basename($filename); |
113 | 113 | $filename = fopen($filename, 'r'); |
114 | 114 | } |
115 | - if (! is_resource($filename)) { |
|
115 | + if ( ! is_resource($filename)) { |
|
116 | 116 | throw new \InvalidArgumentException(); |
117 | 117 | } |
118 | 118 | $length = fstat($filename)['size']; |
119 | - $extra['chunkSize'] = isset($extra['chunkSize']) ? $extra['chunkSize']: self::DEFAULT_CHUNK_SIZE; |
|
119 | + $extra['chunkSize'] = isset($extra['chunkSize']) ? $extra['chunkSize'] : self::DEFAULT_CHUNK_SIZE; |
|
120 | 120 | $extra['_id'] = isset($extra['_id']) ?: new MongoId(); |
121 | 121 | $extra['length'] = $length; |
122 | 122 | $extra['md5'] = isset($md5) ? $md5 : $this->calculateMD5($filename, $length); |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | public function findOne(array $query = array(), array $fields = array()) |
217 | 217 | { |
218 | 218 | $file = parent::findOne($query, $fields); |
219 | - if (! $file) { |
|
219 | + if ( ! $file) { |
|
220 | 220 | return; |
221 | 221 | } |
222 | 222 | return new MongoGridFSFile($this, $file); |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | if (is_string($id)) { |
253 | 253 | $id = new MongoId($id); |
254 | 254 | } |
255 | - if (! $id instanceof MongoId) { |
|
255 | + if ( ! $id instanceof MongoId) { |
|
256 | 256 | return false; |
257 | 257 | } |
258 | 258 | $this->chunks->remove(['file_id' => $id], ['justOne' => false]); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | public function storeUpload($name, array $metadata = []) |
270 | 270 | { |
271 | - if (! isset($_FILES[$name]) || $_FILES[$name]['error'] !== UPLOAD_ERR_OK) { |
|
271 | + if ( ! isset($_FILES[$name]) || $_FILES[$name]['error'] !== UPLOAD_ERR_OK) { |
|
272 | 272 | throw new \InvalidArgumentException(); |
273 | 273 | } |
274 | 274 | $metadata += ['filename' => $_FILES[$name]['name']]; |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | if (is_string($id)) { |
287 | 287 | $id = new MongoId($id); |
288 | 288 | } |
289 | - if (! $id instanceof MongoId) { |
|
289 | + if ( ! $id instanceof MongoId) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | return $this->findOne(['_id' => $id]); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @link http://php.net/manual/en/mongogridfs.construct.php |
54 | 54 | * @param MongoDB $db Database |
55 | 55 | * @param string $prefix [optional] <p>Optional collection name prefix.</p> |
56 | - * @param mixed $chunks [optional] |
|
56 | + * @param string $chunks [optional] |
|
57 | 57 | * @return MongoGridFS |
58 | 58 | */ |
59 | 59 | public function __construct(MongoDB $db, $prefix = "fs", $chunks = null) |
@@ -280,6 +280,9 @@ discard block |
||
280 | 280 | $this->createIndex(['filename' => 1, 'uploadDate' => 1]); |
281 | 281 | } |
282 | 282 | |
283 | + /** |
|
284 | + * @param resource $file |
|
285 | + */ |
|
283 | 286 | private function insertChunksFromFile($file, $fileInfo) |
284 | 287 | { |
285 | 288 | $length = $fileInfo['length']; |
@@ -295,6 +298,9 @@ discard block |
||
295 | 298 | } |
296 | 299 | } |
297 | 300 | |
301 | + /** |
|
302 | + * @param resource $file |
|
303 | + */ |
|
298 | 304 | private function calculateMD5($file) |
299 | 305 | { |
300 | 306 | // XXX: this could be really a bad idea with big files... |
@@ -303,6 +309,9 @@ discard block |
||
303 | 309 | return md5($data); |
304 | 310 | } |
305 | 311 | |
312 | + /** |
|
313 | + * @param string $bytes |
|
314 | + */ |
|
306 | 315 | private function insertChunksFromBytes($bytes, $fileInfo) |
307 | 316 | { |
308 | 317 | $length = $fileInfo['length']; |
@@ -316,6 +325,9 @@ discard block |
||
316 | 325 | } |
317 | 326 | } |
318 | 327 | |
328 | + /** |
|
329 | + * @param integer $chunkNumber |
|
330 | + */ |
|
319 | 331 | private function insertChunk($id, $data, $chunkNumber) |
320 | 332 | { |
321 | 333 | $chunk = [ |