1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @link https://github.com/rkit/filemanager-yii2 |
5
|
|
|
* @copyright Copyright (c) 2015 Igor Romanov |
6
|
|
|
* @license [MIT](http://opensource.org/licenses/MIT) |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace rkit\filemanager; |
10
|
|
|
|
11
|
|
|
use yii\base\InvalidValueException; |
12
|
|
|
use rkit\filemanager\models\File; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* File Manager |
16
|
|
|
* |
17
|
|
|
* @author Igor Romanov <[email protected]> |
18
|
|
|
* @since 1.0 |
19
|
|
|
*/ |
20
|
|
|
class Decoder |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Create file from uploader (UploadedFile) |
24
|
|
|
* |
25
|
|
|
* @param Storage $storage; |
|
|
|
|
26
|
|
|
* @param string $path Path to the file |
27
|
|
|
* @param int $ownerId |
28
|
|
|
* @param int $ownerType |
29
|
|
|
* @param bool $temporary The file is temporary |
30
|
|
|
* @param bool $protected The file is protected, not available from the web |
31
|
|
|
* @return \rkit\filemanager\models\File|bool |
32
|
|
|
*/ |
33
|
31 |
|
public function createFromUploader( |
34
|
|
|
$storage, |
35
|
|
|
$path, |
36
|
|
|
$ownerId = -1, |
37
|
|
|
$ownerType = -1, |
38
|
|
|
$temporary = false, |
39
|
|
|
$protected = false |
40
|
|
|
) { |
41
|
31 |
|
$file = File::create($path, $ownerId, $ownerType, $temporary, $protected); |
42
|
31 |
|
if ($file) { |
43
|
30 |
|
$file->setStorage($storage); |
44
|
30 |
|
return $file->getStorage()->save($path); |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
throw new InvalidValueException('Unable to create from `' . $path . '`'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Create file from path |
52
|
|
|
* |
53
|
|
|
* @param Storage $storage; |
|
|
|
|
54
|
|
|
* @param string $path Path to the file or URL |
55
|
|
|
* @param int $ownerId |
56
|
|
|
* @param int $ownerType |
57
|
|
|
* @param bool $temporary The file is temporary |
58
|
|
|
* @param bool $protected The file is protected, not available from the web |
59
|
|
|
* @return \rkit\filemanager\models\File|bool |
60
|
|
|
*/ |
61
|
5 |
|
public function createFromPath( |
62
|
|
|
$storage, |
63
|
|
|
$path, |
64
|
|
|
$ownerId = -1, |
65
|
|
|
$ownerType = -1, |
66
|
|
|
$temporary = false, |
67
|
|
|
$protected = false |
68
|
|
|
) { |
69
|
5 |
|
$filePath = tempnam(sys_get_temp_dir(), 'FMR'); |
70
|
5 |
|
if ($fileContent = @file_get_contents($path)) { |
71
|
4 |
|
file_put_contents($filePath, $fileContent); |
72
|
4 |
|
$file = File::create($filePath, $ownerId, $ownerType, $temporary, $protected); |
73
|
4 |
|
if ($file) { |
74
|
4 |
|
$file->setStorage($storage); |
75
|
4 |
|
return $file->getStorage()->save($filePath, false); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} // @codeCoverageIgnore |
78
|
|
|
|
79
|
1 |
|
throw new InvalidValueException('Unable to create from `' . $path . '`'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.