|
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
|
|
|
* The Decoder for creating files |
|
16
|
|
|
* |
|
17
|
|
|
* @author Igor Romanov <[email protected]> |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class Decoder |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Create a file from the path |
|
24
|
|
|
* |
|
25
|
|
|
* @param Storage $storage; |
|
|
|
|
|
|
26
|
|
|
* @param string $path Path to the file |
|
27
|
|
|
* @param int $ownerId The id of the owner |
|
28
|
|
|
* @param int $ownerType The type of the owner |
|
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
|
|
|
* @throws InvalidValueException |
|
33
|
|
|
*/ |
|
34
|
32 |
|
public function createFromPath( |
|
35
|
|
|
$storage, |
|
36
|
|
|
$path, |
|
37
|
|
|
$ownerId = -1, |
|
38
|
|
|
$ownerType = -1, |
|
39
|
|
|
$temporary = false, |
|
40
|
|
|
$protected = false |
|
41
|
|
|
) { |
|
42
|
32 |
|
$file = File::create($path, $ownerId, $ownerType, $temporary, $protected); |
|
43
|
32 |
|
if ($file) { |
|
44
|
31 |
|
$file->setStorage($storage); |
|
45
|
31 |
|
return $file->getStorage()->save($path); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
throw new InvalidValueException('Unable to create from `' . $path . '`'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Create a file from the remote path |
|
53
|
|
|
* |
|
54
|
|
|
* @param Storage $storage; |
|
|
|
|
|
|
55
|
|
|
* @param string $path Path to the file or URL |
|
56
|
|
|
* @param int $ownerId The id of the owner |
|
57
|
|
|
* @param int $ownerType The type of the owner |
|
58
|
|
|
* @param bool $temporary The file is temporary |
|
59
|
|
|
* @param bool $protected The file is protected, not available from the web |
|
60
|
|
|
* @return \rkit\filemanager\models\File|bool |
|
61
|
|
|
* @throws InvalidValueException |
|
62
|
|
|
*/ |
|
63
|
5 |
|
public function createFromRemotePath( |
|
64
|
|
|
$storage, |
|
65
|
|
|
$path, |
|
66
|
|
|
$ownerId = -1, |
|
67
|
|
|
$ownerType = -1, |
|
68
|
|
|
$temporary = false, |
|
69
|
|
|
$protected = false |
|
70
|
|
|
) { |
|
71
|
5 |
|
$filePath = tempnam(sys_get_temp_dir(), 'FMR'); |
|
72
|
5 |
|
if ($fileContent = @file_get_contents($path)) { |
|
73
|
4 |
|
file_put_contents($filePath, $fileContent); |
|
74
|
4 |
|
$file = File::create($filePath, $ownerId, $ownerType, $temporary, $protected); |
|
75
|
4 |
|
if ($file) { |
|
76
|
4 |
|
$file->setStorage($storage); |
|
77
|
4 |
|
return $file->getStorage()->save($filePath, false); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} // @codeCoverageIgnore |
|
80
|
|
|
|
|
81
|
1 |
|
throw new InvalidValueException('Unable to create from `' . $path . '`'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
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
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.