Client::deleteObjectAcl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Sulao\BaiduBos;
4
5
/**
6
 * Class Client
7
 *
8
 * @package Sulao\BaiduBos
9
 */
10
class Client extends Request
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $config;
16
17
    /**
18
     * Get config
19
     *
20
     * @return array
21
     */
22 1
    public function getConfig()
23
    {
24 1
        return $this->config;
25
    }
26
27
    /**
28
     * Get an object
29
     *
30
     * @param string $path
31
     * @param array  $options
32
     *
33
     * @return string|mixed
34
     * @throws Exception
35
     */
36 1
    public function getObject($path, array $options = [])
37
    {
38 1
        return $this->request('GET', $path, $options);
39
    }
40
41
    /**
42
     * Get the meta of an object
43
     *
44
     * @param string $path
45
     * @param array  $options
46
     *
47
     * @return array|mixed
48
     * @throws Exception
49
     */
50 1
    public function getObjectMeta($path, array $options = [])
51
    {
52 1
        $options += ['return' => 'headers'];
53
54 1
        return $this->request('HEAD', $path, $options);
55
    }
56
57
    /**
58
     * Add an object
59
     *
60
     * @param string $path
61
     * @param string $content
62
     * @param array  $options
63
     *
64
     * @return array|mixed
65
     * @throws Exception
66
     */
67 1
    public function putObject($path, $content, array $options = [])
68
    {
69 1
        $options['body'] = $content;
70 1
        $options += ['return' => 'headers'];
71
72 1
        return $this->request('PUT', $path, $options);
73
    }
74
75
    /**
76
     * Copy an object
77
     *
78
     * @param string $source
79
     * @param string $dest
80
     * @param array  $options
81
     *
82
     * @return array|mixed
83
     * @throws Exception
84
     */
85 1
    public function copyObject($source, $dest, array $options = [])
86
    {
87 1
        $sourcePath = '/' . $this->config['bucket'] . '/' . ltrim($source, '/');
88 1
        $options['headers']['x-bce-copy-source'] = $sourcePath;
89 1
        $options += ['return' => 'body-json'];
90
91 1
        return $this->request('PUT', $dest, $options);
92
    }
93
94
    /**
95
     * Fetch a remote source as an object
96
     *
97
     * @param string $path
98
     * @param string $source
99
     * @param array  $options
100
     *
101
     * @return array|mixed
102
     * @throws Exception
103
     */
104 1
    public function fetchObject($path, $source, array $options = [])
105
    {
106 1
        $options['query']['fetch'] = null;
107 1
        $options['headers']['x-bce-fetch-source'] = $source;
108 1
        $options += ['return' => 'body-json'];
109
110 1
        return $this->request('POST', $path, $options);
111
    }
112
113
    /**
114
     * Append content to an object
115
     *
116
     * @param string $path
117
     * @param string $content
118
     * @param array  $options
119
     *
120
     * @return array|mixed
121
     * @throws Exception
122
     */
123 1
    public function appendObject($path, $content, array $options = [])
124
    {
125 1
        $options['query']['append'] = null;
126
127 1
        $options['body'] = $content;
128 1
        $options += ['return' => 'headers'];
129
130 1
        return $this->request('POST', $path, $options);
131
    }
132
133
    /**
134
     * Delete an object
135
     *
136
     * @param string $path
137
     * @param array  $options
138
     *
139
     * @return array|mixed
140
     * @throws Exception
141
     */
142 1
    public function deleteObject($path, array $options = [])
143
    {
144 1
        $options += ['return' => 'headers'];
145
146 1
        return $this->request('DELETE', $path, $options);
147
    }
148
149
150
    /**
151
     * Delete objects
152
     *
153
     * @param array $paths
154
     * @param array  $options
155
     *
156
     * @return array|mixed
157
     * @throws Exception
158
     */
159 1
    public function deleteObjects(array $paths, array $options = [])
160
    {
161 1
        $paths = array_map(function ($path) {
162 1
            return ['key' => ltrim($path, '/')];
163 1
        }, $paths);
164
165 1
        $options['query']['delete'] = null;
166 1
        $options['body'] = json_encode(['objects' => $paths]);
167 1
        $options += ['return' => 'headers'];
168
169 1
        return $this->request('POST', '/', $options);
170
    }
171
172
    /**
173
     * Get object ACL
174
     *
175
     * @param string $path
176
     * @param array  $options
177
     *
178
     * @return array|mixed
179
     * @throws Exception
180
     */
181 1
    public function getObjectAcl($path, array $options = [])
182
    {
183 1
        $options['query'] = ['acl' => ''];
184 1
        $options += ['return' => 'body-json'];
185
186 1
        return $this->request('GET', $path, $options);
187
    }
188
189
    /**
190
     * Update object ACL
191
     *
192
     * @param string $path
193
     * @param string $acl     private or public-read
194
     * @param array  $options
195
     *
196
     * @return array|mixed
197
     * @throws Exception
198
     */
199 1
    public function putObjectAcl($path, $acl, array $options = [])
200
    {
201 1
        if (!in_array($acl, ['private', 'public-read'])) {
202 1
            throw new Exception(
203 1
                'Unsupported acl: ' . $acl . ', either private or public-read'
204 1
            );
205
        }
206
207 1
        $options['headers']['x-bce-acl'] = $acl;
208 1
        $options['query']['acl'] = '';
209 1
        $options += ['return' => 'headers'];
210
211 1
        return $this->request('PUT', $path, $options);
212
    }
213
214
    /**
215
     * Delete object ACL
216
     *
217
     * @param string $path
218
     * @param array  $options
219
     *
220
     * @return array|mixed
221
     * @throws Exception
222
     */
223 1
    public function deleteObjectAcl($path, array $options = [])
224
    {
225 1
        $options['query']['acl'] = '';
226 1
        $options += ['return' => 'headers'];
227
228 1
        return $this->request('DELETE', $path, $options);
229
    }
230
231
    /**
232
     * Get current bucket ACL
233
     *
234
     * @param array $options
235
     *
236
     * @return array|mixed
237
     * @throws Exception
238
     */
239 1
    public function getBucketAcl(array $options = [])
240
    {
241 1
        $options['query']['acl'] = '';
242 1
        $options += ['return' => 'body-json'];
243
244 1
        return $this->request('GET', '/', $options);
245
    }
246
247
    /**
248
     * List objects
249
     *
250
     * @param array $options
251
     *
252
     * @return array|mixed|string
253
     * @throws Exception
254
     */
255 1
    public function listObjects(array $options = [])
256
    {
257 1
        $options += ['return' => 'body-json'];
258
259 1
        return $this->request('GET', '/', $options);
260
    }
261
}
262