Skip to content

Commit

Permalink
Add 'prefix' and 'url' configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Feb 26, 2019
1 parent e0302c7 commit f0edc17
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ Additional configuration options:
- `swiftSegmentSize` [[ref]](https://github.com/mzur/flysystem-openstack-swift#configuration)

- `swiftSegmentContainer` [[ref]](https://github.com/mzur/flysystem-openstack-swift#configuration)

- `prefix` (default: `null`): Prefix to use for the names of the objects in the container.

- `url` (default: `null`): Override URL to use for public URLs to objects. If this is not set, the public URL will point to the public URL of Swift. This configuration is useful if you use a reverse proxy to pass through requests to public Swift containers.
43 changes: 43 additions & 0 deletions src/SwiftAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Mzur\Filesystem;

use OpenStack\ObjectStore\v1\Models\Container;
use Nimbusoft\Flysystem\OpenStack\SwiftAdapter as BaseAdapter;

class SwiftAdapter extends BaseAdapter
{
/**
* Optional base URL to use for this adapter.
*
* @var string
*/
protected $url;

/**
* Constructor
*
* @param Container $container
* @param string $prefix
*/
public function __construct(Container $container, $prefix = null, $url = null)
{
parent::__construct($container, $prefix);
$this->url = rtrim($url, '/');
}

/**
* Get the URL for the file at the given path.
*
* @param string $path
* @return string
*/
public function getUrl($path)
{
if ($this->url) {
return "{$this->url}/{$path}";
}

return $this->container->getObject($path)->getPublicUri();
}
}
5 changes: 3 additions & 2 deletions src/SwiftServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use League\Flysystem\Filesystem;
use Biigle\CachedOpenStack\OpenStack;
use Illuminate\Support\ServiceProvider;
use Nimbusoft\Flysystem\OpenStack\SwiftAdapter;

class SwiftServiceProvider extends ServiceProvider
{
Expand All @@ -23,7 +22,9 @@ public function boot()
->objectStoreV1()
->getContainer($config['container']);

$adapter = new SwiftAdapter($container);
$prefix = array_get($config, 'prefix', null);
$url = array_get($config, 'url', null);
$adapter = new SwiftAdapter($container, $prefix, $url);

return new Filesystem($adapter, $this->getFlyConfig($config));
});
Expand Down

0 comments on commit f0edc17

Please sign in to comment.