Skip to content

Commit

Permalink
Lumen support.
Browse files Browse the repository at this point in the history
  • Loading branch information
freyo committed Aug 11, 2017
1 parent 8cb180b commit a21f4cf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
34 changes: 34 additions & 0 deletions README.md
Expand Up @@ -118,6 +118,40 @@ bool $flysystem->setVisibility('file.md', 'public'); //or 'private'
],
],
```

## Use in Lumen

1. Add the following code to your `bootstrap/app.php`:

```php
$app->singleton('filesystem', function ($app) {
return $app->loadComponent(
'filesystems',
Illuminate\Filesystem\FilesystemServiceProvider::class,
'filesystem'
);
});
```

2. And this:

```php
$app->register(Freyo\Flysystem\QcloudCOSv4\ServiceProvider::class);
```

3. Configure `.env`:

```php
COSV4_PROTOCOL=http
COSV4_DOMAIN=
COSV4_APP_ID=
COSV4_SECRET_ID=
COSV4_SECRET_KEY=
COSV4_TIMEOUT=60
COSV4_BUCKET=
COSV4_REGION=gz
COSV4_DEBUG=true
```

### Usage

Expand Down
30 changes: 20 additions & 10 deletions src/ServiceProvider.php
Expand Up @@ -5,8 +5,10 @@
use Freyo\Flysystem\QcloudCOSv4\Plugins\GetUrl;
use Freyo\Flysystem\QcloudCOSv4\Plugins\PutRemoteFile;
use Freyo\Flysystem\QcloudCOSv4\Plugins\PutRemoteFileAs;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
use Laravel\Lumen\Application as LumenApplication;
use League\Flysystem\Filesystem;

/**
Expand All @@ -21,18 +23,26 @@ class ServiceProvider extends LaravelServiceProvider
*/
public function boot()
{
$this->publishes([
__DIR__.'/filesystems.php' => config_path('filesystems.php'),
]);
$source = realpath(__DIR__ . '/filesystems.php');

Storage::extend('cosv4', function ($app, $config) {
return new Filesystem(new Adapter($config));
});
if ($this->app instanceof LaravelApplication) {
if ($this->app->runningInConsole()) {
$this->publishes([
$source => config_path('filesystems.php'),
]);
}
} elseif ($this->app instanceof LumenApplication) {
$this->app->configure('filesystems');
}

Storage::disk('cosv4')
->addPlugin(new PutRemoteFile())
->addPlugin(new PutRemoteFileAs())
->addPlugin(new GetUrl());
$this->app->make('filesystem')
->extend('cosv4', function ($app, $config) {
return new Filesystem(new Adapter($config));
})
->disk('cosv4')
->addPlugin(new PutRemoteFile())
->addPlugin(new PutRemoteFileAs())
->addPlugin(new GetUrl());
}

/**
Expand Down

0 comments on commit a21f4cf

Please sign in to comment.