1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace B2\Files; |
4
|
|
|
|
5
|
|
|
use B2\B2Client; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Files |
9
|
|
|
* @package Mlh\B2\Files |
10
|
|
|
*/ |
11
|
|
|
class Files |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var B2Client |
16
|
|
|
*/ |
17
|
|
|
protected $B2Client; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Files constructor. |
21
|
|
|
* @param B2Client $B2Client |
22
|
|
|
*/ |
23
|
2 |
|
public function __construct(B2Client $B2Client) |
24
|
|
|
{ |
25
|
2 |
|
$this->B2Client = $B2Client; |
26
|
2 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param $bucketId |
30
|
|
|
* @param $startFileName |
31
|
|
|
* @return mixed |
32
|
|
|
* @throws \Exception |
33
|
|
|
*/ |
34
|
|
|
public function listFileNames($bucketId, $startFileName = null, $maxFileCount = 100) |
35
|
|
|
{ |
36
|
|
|
return $this->B2Client->call('b2_list_file_names', 'POST', [ |
37
|
|
|
'startFileName' => $startFileName, |
38
|
|
|
'bucketId' => $bucketId, |
39
|
|
|
'maxFileCount' => $maxFileCount |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Lists all files in a bucket and starting filename. For very large buckets this may fail, use listFileNames() directly |
45
|
|
|
* |
46
|
|
|
* @param $bucketId |
47
|
|
|
* @param $startFileName |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
|
public function listAllFileNames($bucketId, $startFileName) |
51
|
|
|
{ |
52
|
|
|
|
53
|
|
|
$allresults = []; |
54
|
|
|
$result = $this->listFileNames($bucketId, $startFileName); |
55
|
|
|
$allresults = array_merge($allresults, $result['responseBody']['files']); |
56
|
|
|
|
57
|
|
|
if ($result['responseBody']['nextFileName'] !== null) { |
58
|
|
|
$allresults = array_merge($allresults, |
59
|
|
|
$this->listAllFileNames($bucketId, $result['responseBody']['nextFileName'])); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $allresults; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $fileID |
67
|
|
|
* @return mixed |
68
|
|
|
* @throws \Exception |
69
|
|
|
*/ |
70
|
|
|
public function getFileInfo($fileId) |
71
|
|
|
{ |
72
|
|
|
return $this->B2Client->call('b2_get_file_info', 'POST', ['fileId' => $fileId]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param $bucketId |
77
|
|
|
* @return mixed |
78
|
|
|
* @throws \Exception |
79
|
|
|
*/ |
80
|
|
|
public function getUploadUrl($bucketId) |
81
|
|
|
{ |
82
|
|
|
return $this->B2Client->call('b2_get_upload_url', 'POST', ['bucketId' => $bucketId]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $bucketId |
87
|
|
|
* @param string $filePath The path to the local file |
88
|
|
|
* @param string $fileName The name/path on B2 |
89
|
|
|
* @param string $contentType |
90
|
|
|
* @param null $uploadUrl |
|
|
|
|
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function uploadFile($bucketId, $filePath, $fileName, $contentType, $uploadUrlResponse = []) |
94
|
|
|
{ |
95
|
|
|
|
96
|
|
|
if (!$uploadUrlResponse) { |
|
|
|
|
97
|
|
|
$uploadUrlResponse = $this->getUploadUrl($bucketId); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$handle = fopen($filePath, 'r'); |
101
|
|
|
$fileData = fread($handle, filesize($filePath)); |
102
|
|
|
$fileDataSha1 = sha1_file($filePath); |
103
|
|
|
|
104
|
|
|
return $this->B2Client->uploadData($fileData, $fileDataSha1, $fileName, $contentType, |
105
|
|
|
$uploadUrlResponse['uploadUrl'], |
106
|
|
|
$uploadUrlResponse['authorizationToken']); |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param $bucketId |
112
|
|
|
* @param $fileName |
113
|
|
|
* @return mixed |
114
|
|
|
* @throws \Exception |
115
|
|
|
*/ |
116
|
|
|
public function downloadFileByName($bucketName, $fileName) |
117
|
|
|
{ |
118
|
|
|
return $this->B2Client->downloadFileByName($bucketName . '/' . $fileName); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
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.