Skip to content

Commit d4d9e06

Browse files
committed
Merge branch 'release/1.0.3'
2 parents d6231c2 + 817da82 commit d4d9e06

File tree

1 file changed

+154
-2
lines changed

1 file changed

+154
-2
lines changed

README.md

Lines changed: 154 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ You need to request a new clientId and clientSecret for a new application on Azu
4444

4545

4646
``` php
47-
use GWSN\Sharepoint\FlysystemSharepointAdapter;
48-
use GWSN\Sharepoint\SharepointConnector;
47+
use GWSN\FlysystemSharepoint\FlysystemSharepointAdapter;
48+
use GWSN\FlysystemSharepoint\SharepointConnector;
4949
use League\Flysystem\Filesystem;
5050

5151
$tenantId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
@@ -72,6 +72,158 @@ $ composer run-script test
7272

7373
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
7474

75+
76+
## Laravel
77+
78+
To use the flysystem in Laravel there are additional steps required:
79+
80+
First we need to create a `FlySystemSharepointProvider` and register this in the `config/app.php`
81+
82+
Then we need to create the config into the `config/filesystem.php`
83+
84+
### Create the FlySystemSharepointProvider
85+
86+
we need to create a provider to register the custom FlySystem Adapter
87+
88+
create a new file in the `app/Providers` directory called `FlySystemSharepointProvider.php` with the following content:
89+
```PHP
90+
<?php
91+
92+
namespace App\Providers;
93+
94+
use Illuminate\Filesystem\FilesystemAdapter;
95+
use Illuminate\Support\Facades\Storage;
96+
use Illuminate\Support\ServiceProvider;
97+
use League\Flysystem\Filesystem;
98+
use GWSN\FlysystemSharepoint\FlysystemSharepointAdapter;
99+
use GWSN\FlysystemSharepoint\SharepointConnector;
100+
101+
class FlySystemSharepointProvider extends ServiceProvider
102+
{
103+
/**
104+
* Register any application services.
105+
*
106+
* @return void
107+
*/
108+
public function register() { }
109+
110+
/**
111+
* Bootstrap any application services.
112+
*
113+
* @return void
114+
*/
115+
public function boot()
116+
{
117+
Storage::extend('sharepoint', function ($app, $config) {
118+
119+
$adapter = new FlysystemSharepointAdapter(new SharepointConnector(
120+
$config['tenantId'],
121+
$config['clientId'],
122+
$config['clientSecret'],
123+
$config['sharepointSite'],
124+
),
125+
$config['prefix'],
126+
);
127+
128+
return new FilesystemAdapter(
129+
new Filesystem($adapter, $config),
130+
$adapter,
131+
$config
132+
);
133+
});
134+
}
135+
}
136+
```
137+
138+
### Register the provider in the App config
139+
Add the bottom of the list with providers we need to add the previous created Provider:
140+
141+
```php
142+
'providers' => [
143+
144+
/*
145+
* Laravel Framework Service Providers...
146+
*/
147+
[...]
148+
App\Providers\FlySystemSharepointProvider::class,
149+
]
150+
```
151+
152+
### Update the Filesystem config
153+
154+
Add filesystem Disks section we will add a new custom disk: sharepoint.
155+
156+
We use env variables as config but you could also enter them directly as string
157+
158+
```php
159+
/*
160+
|--------------------------------------------------------------------------
161+
| Filesystem Disks
162+
|--------------------------------------------------------------------------
163+
|
164+
| Here you may configure as many filesystem "disks" as you wish, and you
165+
| may even configure multiple disks of the same driver. Defaults have
166+
| been set up for each driver as an example of the required values.
167+
|
168+
| Supported Drivers: "local", "ftp", "sftp", "s3"
169+
|
170+
*/
171+
172+
'disks' => [
173+
174+
'local' => [
175+
'driver' => 'local',
176+
'root' => storage_path('app'),
177+
'throw' => false,
178+
],
179+
180+
'sharepoint' => [
181+
'driver' => 'sharepoint',
182+
'tenantId' => env('SHAREPOINT_TENANT_ID', 'secret'),
183+
'clientId' => env('SHAREPOINT_CLIENT_ID', 'secret'),
184+
'clientSecret' => env('SHAREPOINT_CLIENT_SECRET_VALUE', 'secret'),
185+
'sharepointSite' => env('SHAREPOINT_SITE', 'laravelTest'),
186+
'prefix' => env('SHAREPOINT_PREFIX', 'test'),
187+
]
188+
189+
],
190+
```
191+
192+
### Usage in laravel
193+
it is bad practice to use logic into a controller but for example purpose we show it in the controller:
194+
195+
`App\Http\Controllers\Controller.php`
196+
```php
197+
<?php
198+
199+
namespace App\Http\Controllers;
200+
201+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
202+
use Illuminate\Foundation\Bus\DispatchesJobs;
203+
use Illuminate\Foundation\Validation\ValidatesRequests;
204+
use Illuminate\Routing\Controller as BaseController;
205+
use Illuminate\Support\Facades\Storage;
206+
207+
class Controller extends BaseController
208+
{
209+
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
210+
211+
public function index() {
212+
213+
try {
214+
Storage::disk('sharepoint')->put('test.txt', 'testContent');
215+
return Storage::disk('sharepoint')->get('test.txt');
216+
217+
} catch (\Exception $exception) {
218+
dd($exception);
219+
}
220+
return 'error';
221+
}
222+
}
223+
```
224+
225+
226+
75227
## License
76228

77229
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

0 commit comments

Comments
 (0)