1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* RackspaceFactory.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license http://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec http://www.ipublikuj.eu |
8
|
|
|
* @package iPublikuj:Flysystem! |
9
|
|
|
* @subpackage Adapters |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 23.04.16 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace IPub\Flysystem\Factories\Adapters; |
16
|
|
|
|
17
|
|
|
use Nette; |
18
|
|
|
use Nette\Utils; |
19
|
|
|
|
20
|
|
|
use League\Flysystem; |
21
|
|
|
use League\Flysystem\Rackspace; |
22
|
|
|
|
23
|
|
|
use OpenCloud; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Rackspace adapter filesystem factory |
27
|
|
|
* |
28
|
|
|
* @package iPublikuj:Flysystem! |
29
|
|
|
* @subpackage Adapters |
30
|
|
|
* |
31
|
|
|
* @author Adam Kadlec <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
class RackspaceFactory |
34
|
|
|
{ |
35
|
|
|
const US_ENDPOINT = 'US'; |
36
|
|
|
const UK_ENDPOINT = 'UK'; |
37
|
|
|
|
38
|
|
|
const REGION_DFW = 'DFW'; |
39
|
|
|
const REGION_IAD = 'IAD'; |
40
|
|
|
const REGION_ORD = 'ORD'; |
41
|
|
|
const REGION_LON = 'LON'; |
42
|
|
|
const REGION_SYD = 'SYD'; |
43
|
|
|
|
44
|
|
|
const URL_PUBLIC = 'public'; |
45
|
|
|
const URL_INTERNAL = 'internal'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param Utils\ArrayHash $parameters |
49
|
|
|
* |
50
|
|
|
* @return Rackspace\RackspaceAdapter |
51
|
|
|
*/ |
52
|
|
|
public static function create(Utils\ArrayHash $parameters) |
53
|
|
|
{ |
54
|
|
|
$client = new OpenCloud\OpenStack(self::getEndpoints()[$parameters->endpoint], [ |
55
|
|
|
'username' => $parameters->username, |
56
|
|
|
'password' => $parameters->password, |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
$region = $parameters->region ? self::getRegions()[$parameters->region] : NULL; |
60
|
|
|
$urlType = $parameters->urlType ? self::getUrls()[$parameters->urlType] : NULL; |
61
|
|
|
|
62
|
|
|
$store = $client->objectStoreService($parameters->serviceName, $region, $urlType); |
63
|
|
|
|
64
|
|
|
$container = $store->getContainer($parameters->container); |
65
|
|
|
|
66
|
|
|
return new Rackspace\RackspaceAdapter($container, $parameters->prefix); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
private static function getEndpoints() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
self::US_ENDPOINT => OpenCloud\Rackspace::US_IDENTITY_ENDPOINT, |
76
|
|
|
self::UK_ENDPOINT => OpenCloud\Rackspace::UK_IDENTITY_ENDPOINT, |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
|
|
private static function getRegions() |
84
|
|
|
{ |
85
|
|
|
return [ |
86
|
|
|
self::REGION_DFW => 'DFW', |
87
|
|
|
self::REGION_IAD => 'IAD', |
88
|
|
|
self::REGION_ORD => 'ORD', |
89
|
|
|
self::REGION_LON => 'LON', |
90
|
|
|
self::REGION_SYD => 'SYD', |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
private static function getUrls() |
98
|
|
|
{ |
99
|
|
|
return [ |
100
|
|
|
self::URL_PUBLIC => 'publicURL', |
101
|
|
|
self::URL_INTERNAL => 'internalURL', |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|