monicahq / laravel-sabre
Sabre DAV server adapter for Laravel.
Fund package maintenance!
asbiin
Installs: 392 613
Dependents: 1
Suggesters: 0
Security: 0
Stars: 51
Watchers: 4
Forks: 9
Open Issues: 4
Requires
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0
- sabre/dav: ^4.0
- thecodingmachine/safe: ^2.0
Requires (Dev)
- larastan/larastan: ^1.0 || ^2.0
- mockery/mockery: ^1.4
- ocramius/package-versions: ^1.9 || ^2.0
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- phpunit/phpunit: ^9.0 || ^10.0 || ^11.0
- roave/security-advisories: dev-master
- thecodingmachine/phpstan-safe-rule: ^1.0
- vimeo/psalm: ^4.0 || ^5.6
README
Laravel-Sabre is an adapter to use Sabre.io DAV Server on Laravel.
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
If you want, you can publish the package config file to config/laravelsabre.php
:
php artisan vendor:publish --provider="LaravelSabre\LaravelSabreServiceProvider"
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 == 'admin@admin.com'; })
License
Author: Alexis Saettler
This project is part of MonicaHQ.
Copyright © 2019–2022.
Licensed under the MIT License. View license.