PHP code example of gwsn / flysystem-sharepoint-adapter

1. Go to this page and download the library: Download gwsn/flysystem-sharepoint-adapter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gwsn / flysystem-sharepoint-adapter example snippets




namespace App\Providers;

use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
use GWSN\FlysystemSharepoint\FlysystemSharepointAdapter;
use GWSN\FlysystemSharepoint\SharepointConnector;

class FlySystemSharepointProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register() { }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('sharepoint', function ($app, $config) {

            $adapter = new FlysystemSharepointAdapter(new SharepointConnector(
                    $config['tenantId'],
                    $config['clientId'],
                    $config['clientSecret'],
                    $config['sharepointSite'],
                ),
                $config['prefix'],
            );

            return new FilesystemAdapter(
                new Filesystem($adapter, $config),
                $adapter,
                $config
            );
        });
    }
}
 
 'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
         [...]
         App\Providers\FlySystemSharepointProvider::class,
 ]
 
 /*
    |--------------------------------------------------------------------------
    | Filesystem Disks
    |--------------------------------------------------------------------------
    |
    | Here you may configure as many filesystem "disks" as you wish, and you
    | may even configure multiple disks of the same driver. Defaults have
    | been set up for each driver as an example of the NT_CLIENT_ID', 'secret'),
            'clientSecret' => env('SHAREPOINT_CLIENT_SECRET_VALUE', 'secret'),
            'sharepointSite' => env('SHAREPOINT_SITE', 'laravelTest'),
            'prefix' => env('SHAREPOINT_PREFIX', 'test'),
        ]

    ],



namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Storage;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function index() {

        try {
            Storage::disk('sharepoint')->put('test.txt', 'testContent');
            return Storage::disk('sharepoint')->get('test.txt');
            
        } catch (\Exception $exception) {
            dd($exception);
        }
        return 'error';
    }
}