|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MJRider\FlysystemFactory\Adapter; |
| 4 | + |
| 5 | +use OpenStack\OpenStack as OpenStackClient; |
| 6 | +use Nimbusoft\Flysystem\OpenStack\SwiftAdapter; |
| 7 | +use MJRider\FlysystemFactory\Endpoint; |
| 8 | +use GuzzleHttp\MessageFormatter; |
| 9 | + |
| 10 | +/** |
| 11 | + * Static factory class for creating an rackspace Adapter |
| 12 | + */ |
| 13 | +class Openstack implements AdapterFactoryInterface |
| 14 | +{ |
| 15 | + use Endpoint; |
| 16 | + |
| 17 | + /** |
| 18 | + * @inheritDoc |
| 19 | + */ |
| 20 | + public static function create($url) |
| 21 | + { |
| 22 | + $auth = null; |
| 23 | + $region = null; |
| 24 | + |
| 25 | + if (isset($url->query->authendpoint)) { |
| 26 | + $auth = urldecode($url->query->authendpoint); |
| 27 | + unset($url->query->authendpoint); |
| 28 | + } |
| 29 | + |
| 30 | + if (isset($url->query->region)) { |
| 31 | + $region = urldecode($url->query->region); |
| 32 | + unset($url->query->region); |
| 33 | + } |
| 34 | + |
| 35 | + $auth = self::endpointToURL($auth); |
| 36 | + |
| 37 | + $args = [ |
| 38 | + 'authUrl' => $auth, |
| 39 | + 'user' => [ |
| 40 | + 'name' => urldecode($url->user), |
| 41 | + 'password' => urldecode($url->pass), |
| 42 | + "domain" => [ "id" => "default" ], |
| 43 | + ], |
| 44 | + 'scope' => ['project' => ['id' => $url->host ]] |
| 45 | + ]; |
| 46 | + |
| 47 | + if (!is_null($region)) { |
| 48 | + $args['region'] = $region; |
| 49 | + } |
| 50 | + |
| 51 | + $options = (array) $url->query; |
| 52 | + |
| 53 | + $path = \arc\path::collapse($url->path); |
| 54 | + $container = trim(\arc\path::head($path), '/'); |
| 55 | + $prefix = ltrim(\arc\path::tail($path), '/'); |
| 56 | + |
| 57 | + $client = new OpenStackClient($args); |
| 58 | + $container = $client->objectStoreV1()->getContainer($container); |
| 59 | + |
| 60 | + $adapter = new SwiftAdapter($container, $prefix); |
| 61 | + |
| 62 | + return $adapter; |
| 63 | + } |
| 64 | +} |
0 commit comments