Coder Social home page Coder Social logo

laravel-sabre's Introduction

Sabre adapter for Laravel

Laravel-Sabre is an adapter to use Sabre.io DAV Server on Laravel.

Latest Version Downloads Circle CI Coverage Status

Installation

You may use Composer to install this package into your Laravel project:

composer require monicahq/laravel-sabre

You don't need to add this package to your service providers.

Support

This package supports Laravel 5.6 and newer, and has been tested with php 7.1 and newer versions.

Configuration

You can publish the LaravelSabre configuration in a file named config/laravelsabre.php. Simply run this artisan command:

php artisan laravelsabre:publish

If desired, you may disable LaravelSabre entirely using the enabled configuration option:

'enabled' => env('LARAVELSABRE_ENABLED', true),

Change the path configuration to set the url path where the Sabre server will answer to.

Usage

Use LaravelSabre\LaravelSabre class to add node collection and plugins to the Sabre server.

In the example above, DAVServiceProvider is a service provider that has been added to the list of providers in config/app.php file.

Nodes

LaravelSabre::nodes() is used to add nodes collection to the Sabre server.

It may be an array, or a callback function, like in this example here:

Example:

use LaravelSabre\LaravelSabre;
use Sabre\DAVACL\PrincipalCollection;
use Sabre\DAVACL\PrincipalBackend\PDO as PrincipalBackend;

class DAVServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        LaravelSabre::nodes(function () {
            return $this->nodes();
        });
    }

    /**
     * List of nodes for DAV Collection.
     */
    private function nodes() : array
    {
        $principalBackend = new PrincipalBackend();

        return [
            new PrincipalCollection($principalBackend),
        ];
    }
}

Plugins

You can use either:

  • LaravelSbre::plugins() to define a new array of plugins to add to the Sabre server. It may be a callback function.
  • or LaravelSbre::plugin() to add 1 plugin to the list of plugins.

Example:

use LaravelSabre\LaravelSabre;
use LaravelSabre\Http\Auth\AuthBackend;
use Sabre\DAV\Auth\Plugin as AuthPlugin;
use Sabre\CardDAV\Plugin as CardDAVPlugin;

class DAVServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        LaravelSabre::plugins(function () {
            return $this->plugins();
        });
    }

    /**
     * List of Sabre plugins.
     */
    private function plugins()
    {
        // Authentication backend
        $authBackend = new AuthBackend();
        yield new AuthPlugin($authBackend);

        // CardDAV plugin
        yield new CardDAVPlugin();
    }
}

Auth

Use the LaravelSabre::auth() method with the Authorize::class middleware gate, to allow access to some people, based on some criteria.

Example:

LaravelSabre::auth(function () {
    return auth()->user()->email == '[email protected]';
})

License

Author: Alexis Saettler

This project is part of MonicaHQ.

Copyright (c) 2019.

Licensed under the MIT License. View license.

laravel-sabre's People

Contributors

asbiin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.