From 16d024bb57befd6427f9cf5a982418aa92f525ae Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Fri, 30 Oct 2015 10:04:40 +0000 Subject: [PATCH 1/4] Adding support for Lumen (http://lumen.laravel.com/), which doesn't support publishing config, so in the boot method the $this->publishes are only run for Laravel. Updated the README with what else was needed to be done differently. --- README.md | 17 ++++++++++- .../AuthorityControllerServiceProvider.php | 30 +++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 480a3e8..0f0bb8b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ AuthorityController [![Build Status](https://travis-ci.org/efficiently/authority-controller.png?branch=master)](http://travis-ci.org/efficiently/authority-controller) =================== -AuthorityController is an PHP authorization library for [Laravel 5.0 & 5.1](http://laravel.com) which restricts what resources a given user is allowed to access. +AuthorityController is an PHP authorization library for [Laravel 5.0 & 5.1](http://laravel.com) and [Lumen (http://lumen.laravel.com/)] which restricts what resources a given user is allowed to access. All permissions are defined in a single location: @@ -11,6 +11,21 @@ and not duplicated across controllers, routes, views, and database queries. For [**Laravel 4.1 or 4.2**](http://laravel.com/docs/4.2) supports see [AuthorityController 1.2 branch](https://github.com/efficiently/authority-controller/tree/1.2) +#### Lumen Support +For Lumen support, follow the instructions below for the most part, but as Lumen doesn't support config publishing you'll not be able to run php artisan vendor:publish for example, and some of the config is done a little different. + +You will need to manually copy the migrations in to your migrations folder from vendor/efficiently/authority-controller/src/migrations/ to your migrations folder and the config from vendor/efficiently/authority-controller/src/config/config.php to config/authority-controller.php. + +Register the aliases (in bootstrap/app.php), notice you'll need to add the Lang alias too. + +class_alias('Efficiently\AuthorityController\Facades\Params', 'Params'); +class_alias('Efficiently\AuthorityController\Facades\Authority', 'Authority'); +class_alias('Illuminate\Support\Facades\Lang', 'Lang'); + +Lumen will not automatically load the config file so this will need adding to bootstrap/app.php too + +$app->configure('authority-controller'); + #### Demo application You can see in action this package with this Laravel 5.1 [**demo application**](https://github.com/efficiently/laravel_authority-controller_app#readme). diff --git a/src/Efficiently/AuthorityController/AuthorityControllerServiceProvider.php b/src/Efficiently/AuthorityController/AuthorityControllerServiceProvider.php index 2532d32..8ad27cd 100644 --- a/src/Efficiently/AuthorityController/AuthorityControllerServiceProvider.php +++ b/src/Efficiently/AuthorityController/AuthorityControllerServiceProvider.php @@ -22,23 +22,27 @@ class AuthorityControllerServiceProvider extends ServiceProvider */ public function boot() { - // Publish config - $this->publishes([ - __DIR__ . '/../../config/config.php' => config_path('authority-controller.php') - ], 'config'); + //Lumen doesn't support publishing config + if (!str_contains($this->app->version(), 'Lumen')) { + // Publish config + $this->publishes([ + __DIR__ . '/../../config/config.php' => config_path('authority-controller.php') + ], 'config'); + + // Publish migrations + $this->publishes([ + __DIR__ . '/../../migrations/' => base_path('database/migrations') + ], 'migrations'); + + // Publish translations + $this->publishes([ + __DIR__ . '/../../translations' => base_path('resources/lang') + ], 'translations'); + } - // Publish migrations - $this->publishes([ - __DIR__ . '/../../migrations/' => base_path('database/migrations') - ], 'migrations'); // Load translations $this->loadTranslationsFrom(__DIR__ . '/../../lang', 'authority-controller'); - - // Publish translations - $this->publishes([ - __DIR__ . '/../../translations' => base_path('resources/lang') - ], 'translations'); } /** From 069a7f9169e328dbcb47424d7f7f9f938a6d178f Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Fri, 30 Oct 2015 10:06:28 +0000 Subject: [PATCH 2/4] Adding support for Lumen (http://lumen.laravel.com/), which doesn't support publishing config, so in the boot method the $this->publishes are only run for Laravel. Updated the README with what else was needed to be done differently. --- README.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0f0bb8b..09ed463 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,22 @@ For [**Laravel 4.1 or 4.2**](http://laravel.com/docs/4.2) supports see [Authorit #### Lumen Support For Lumen support, follow the instructions below for the most part, but as Lumen doesn't support config publishing you'll not be able to run php artisan vendor:publish for example, and some of the config is done a little different. -You will need to manually copy the migrations in to your migrations folder from vendor/efficiently/authority-controller/src/migrations/ to your migrations folder and the config from vendor/efficiently/authority-controller/src/config/config.php to config/authority-controller.php. - +You will need to manually copy the migrations in to your migrations folder from + ```php + vendor/efficiently/authority-controller/src/migrations/ to your migrations folder and the config from vendor/efficiently/authority-controller/src/config/config.php to config/authority-controller.php. + ``` Register the aliases (in bootstrap/app.php), notice you'll need to add the Lang alias too. -class_alias('Efficiently\AuthorityController\Facades\Params', 'Params'); -class_alias('Efficiently\AuthorityController\Facades\Authority', 'Authority'); -class_alias('Illuminate\Support\Facades\Lang', 'Lang'); - + ```php + class_alias('Efficiently\AuthorityController\Facades\Params', 'Params'); + class_alias('Efficiently\AuthorityController\Facades\Authority', 'Authority'); + class_alias('Illuminate\Support\Facades\Lang', 'Lang'); + ``` Lumen will not automatically load the config file so this will need adding to bootstrap/app.php too -$app->configure('authority-controller'); - + ```php + $app->configure('authority-controller'); + ``` #### Demo application You can see in action this package with this Laravel 5.1 [**demo application**](https://github.com/efficiently/laravel_authority-controller_app#readme). From 29937368e9254c659dbd402f223c1a94e1843d36 Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Fri, 30 Oct 2015 10:39:27 +0000 Subject: [PATCH 3/4] Fixing README formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09ed463..3c3d7b2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ AuthorityController [![Build Status](https://travis-ci.org/efficiently/authority-controller.png?branch=master)](http://travis-ci.org/efficiently/authority-controller) =================== -AuthorityController is an PHP authorization library for [Laravel 5.0 & 5.1](http://laravel.com) and [Lumen (http://lumen.laravel.com/)] which restricts what resources a given user is allowed to access. +AuthorityController is an PHP authorization library for [Laravel 5.0 & 5.1](http://laravel.com) and [Lumen] (http://lumen.laravel.com/) which restricts what resources a given user is allowed to access. All permissions are defined in a single location: From f45f26a157fb297a9da9d32f245f0d52554c32cf Mon Sep 17 00:00:00 2001 From: Jamie Jones Date: Fri, 30 Oct 2015 10:43:03 +0000 Subject: [PATCH 4/4] Removing extra line space --- .../AuthorityController/AuthorityControllerServiceProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Efficiently/AuthorityController/AuthorityControllerServiceProvider.php b/src/Efficiently/AuthorityController/AuthorityControllerServiceProvider.php index 8ad27cd..c54ddb2 100644 --- a/src/Efficiently/AuthorityController/AuthorityControllerServiceProvider.php +++ b/src/Efficiently/AuthorityController/AuthorityControllerServiceProvider.php @@ -40,7 +40,6 @@ public function boot() ], 'translations'); } - // Load translations $this->loadTranslationsFrom(__DIR__ . '/../../lang', 'authority-controller'); }