This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/
Client.php
executable file
·126 lines (110 loc) · 3.76 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/
namespace Pydio\Access\Core\Stream;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
/**
* Client to interact with SabreDAV Client
*
*
* @link http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html User guide
* @link http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.S3.S3Client.html API docs
*/
class Client extends GuzzleClient implements ClientInterface
{
const LATEST_API_VERSION = '2016-01-01';
public static $STAT_TEMPLATE = [
0 => 0, 'dev' => 0,
1 => 0, 'ino' => 0,
2 => 0, 'mode' => 0,
3 => 0, 'nlink' => 0,
4 => 0, 'uid' => 0,
5 => 0, 'gid' => 0,
6 => -1, 'rdev' => -1,
7 => 0, 'size' => 0,
8 => 0, 'atime' => 0,
9 => 0, 'mtime' => 0,
10 => 0, 'ctime' => 0,
11 => -1, 'blksize' => -1,
12 => -1, 'blocks' => -1,
];
/**
* @param ClientInterface $client HTTP client to use.
* @param DescriptionInterface $description Guzzle service description
* @param array $config Configuration options
*/
public function __construct__(
ClientInterface $client,
DescriptionInterface $description,
array $config = []
) {
parent::__construct($client, $config);
$this->processConfig($config);
}
/**
* Register this client on the StreamWrapper
*/
public function registerStreamWrapper() {
StreamWrapper::register($this);
}
/**
* Redefine a file stat
*
* @param array $arr
*
* @return array Associative array containing the stats
*/
public function formatUrlStat($arr) {
return $STAT_TEMPLATE;
}
/**
* Get a Directory Iterator based on the given array
*
* @param array $arr
*
* @return DirIterator
*/
public function getIterator($arr) {
return new Iterator\DirIterator($arr);
}
/**
* Get the params from the passed path
*
* @param string $path Path passed to the stream wrapper
*
* @return array Hash of custom params
*/
public function getParams($path, $prefix = "")
{
$parts = parse_url($path);
$parts[$prefix . 'path'] = $parts['path'];
$parts[$prefix . 'basepath'] = $this->urlParams['path'];
$parts[$prefix . 'fullpath'] = dirname($this->urlParams['path'] . $parts[$prefix . 'path']);
$parts[$prefix . 'itemname'] = basename($parts[$prefix . 'path']);
if (!isset($parts[$prefix . 'path']) || $parts[$prefix . 'path'] == '/') {
$parts[$prefix . 'fullpath'] = $parts[$prefix . 'basepath'];
$parts[$prefix . 'path'] = '/';
}
$parts[$prefix . 'path'] = dirname($parts[$prefix . 'path']);
$parts[$prefix . 'auth'] = [$username, $password];
$parts['base_url'] = $this->urlParams['scheme'] . '://' . $this->urlParams['host'];
return $parts;
}
}