From ee8d3cf29a31eb1cf3ed4ded7117f28c4645e66e Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 17 May 2017 15:42:31 +0200 Subject: [PATCH] first commit --- .gitignore | 15 +++++ LICENSE | 21 +++++++ README.md | 47 ++++++++++++++ composer.json | 28 +++++++++ src/Controllers/RoutesController.php | 94 ++++++++++++++++++++++++++++ src/Menu.json | 9 +++ src/Models/Route.php | 10 +++ src/Policies/RoutePolicy.php | 36 +++++++++++ src/Routes/web.php | 13 ++++ src/RoutesServiceProvider.php | 77 +++++++++++++++++++++++ src/Translations/ca/general.php | 15 +++++ src/Translations/de/general.php | 15 +++++ src/Translations/en/general.php | 15 +++++ src/Translations/es/general.php | 15 +++++ src/Translations/fr/general.php | 15 +++++ src/Translations/it/general.php | 15 +++++ src/Views/routes.blade.php | 57 +++++++++++++++++ 17 files changed, 497 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100755 composer.json create mode 100644 src/Controllers/RoutesController.php create mode 100755 src/Menu.json create mode 100644 src/Models/Route.php create mode 100755 src/Policies/RoutePolicy.php create mode 100755 src/Routes/web.php create mode 100644 src/RoutesServiceProvider.php create mode 100755 src/Translations/ca/general.php create mode 100755 src/Translations/de/general.php create mode 100755 src/Translations/en/general.php create mode 100755 src/Translations/es/general.php create mode 100755 src/Translations/fr/general.php create mode 100755 src/Translations/it/general.php create mode 100644 src/Views/routes.blade.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cd717b --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +vendor/ +node_modules/ + +# Laravel 4 specific +bootstrap/compiled.php +app/storage/ + +# Laravel 5 & Lumen specific +bootstrap/cache/ +.env.*.php +.env.php +.env + +# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer +.rocketeer/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0c57ad6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Laralum + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bbf8eef --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +

+ +

Routes

+ +

+StyleCI +Laralum +Downloads +License +License +

+ +## Description + + + +## Documentation + +

+ +

+ +## License + +``` +MIT License + +Copyright (c) 2017 Laralum + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..8f2a0d4 --- /dev/null +++ b/composer.json @@ -0,0 +1,28 @@ +{ + "name": "laralum/routes", + "description": "Routes module for laralum", + "require": { + "laralum/laralum": "1.*" + }, + "license": "MIT", + "authors": [ + { + "name": "Erik Campobadal", + "email": "soc@erik.cat" + }, + { + "name": "Aitor Riba", + "email": "contact@aitorriba.com" + }, + { + "name": "Krishan König", + "email": "krishan.koenig@googlemail.com" + } + ], + "autoload": { + "psr-4": { + "Laralum\\Routes\\": "./src" + } + }, + "minimum-stability": "dev" +} diff --git a/src/Controllers/RoutesController.php b/src/Controllers/RoutesController.php new file mode 100644 index 0000000..e360b7d --- /dev/null +++ b/src/Controllers/RoutesController.php @@ -0,0 +1,94 @@ +router = $router; + $this->routes = $router->getRoutes(); + } + + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function routes() + { + collect($this->routes)->map(function ($route) { + dd($route->getName()); + })->all(); + + return view('laralum_routes::routes', ['routes' => $routes]); + } + + /** + * Compile the routes into a displayable format. + * + * @return array + */ + public function getAll() + { + $routes = collect($this->routes)->map(function ($route) { + return $this->getRouteInformation($route); + })->all(); + + return array_filter($routes); + } + + /** + * Get the route information for a given route. + * + * @param \Illuminate\Routing\Route $route + * @return array + */ + public function getRouteInformation(BaseRoute $route) + { + return [ + 'host' => $route->domain(), + 'method' => implode('|', $route->methods()), + 'uri' => $route->uri(), + 'name' => $route->getName(), + 'action' => $route->getActionName(), + 'middleware' => $this->getRouteMiddleware($route), + ]; + } + + /** + * Get before filters. + * + * @param \Illuminate\Routing\Route $route + * @return string + */ + public function getRouteMiddleware($route) + { + return collect($route->gatherMiddleware())->map(function ($middleware) { + return $middleware instanceof Closure ? 'Closure' : $middleware; + })->implode(','); + } +} diff --git a/src/Menu.json b/src/Menu.json new file mode 100755 index 0000000..8560c32 --- /dev/null +++ b/src/Menu.json @@ -0,0 +1,9 @@ +{ + "items": [ + { + "permission" : "laralum::routes.access", + "trans": "laralum_routes::general.routes", + "route": "laralum::routes.index" + } + ] +} diff --git a/src/Models/Route.php b/src/Models/Route.php new file mode 100644 index 0000000..351083b --- /dev/null +++ b/src/Models/Route.php @@ -0,0 +1,10 @@ +id)->superAdmin()) { + return true; + } + } + + /** + * Determine if the current user can access statistics moule. + * + * @param mixed $user + * + * @return bool + */ + public function access($user) + { + return User::findOrFail($user->id)->hasPermission('laralum::routes.access'); + } +} diff --git a/src/Routes/web.php b/src/Routes/web.php new file mode 100755 index 0000000..f8d48b7 --- /dev/null +++ b/src/Routes/web.php @@ -0,0 +1,13 @@ + [ + 'web', 'laralum.base', 'laralum.auth', + // 'can:access,Laralum\Routes\Models\Route', + ], + 'prefix' => config('laralum.settings.base_url'), + 'namespace' => 'Laralum\Routes\Controllers', + 'as' => 'laralum::routes.', + ], function () { + Route::get('routes', 'RoutesController@routes')->name('index'); + }); diff --git a/src/RoutesServiceProvider.php b/src/RoutesServiceProvider.php new file mode 100644 index 0000000..063d25c --- /dev/null +++ b/src/RoutesServiceProvider.php @@ -0,0 +1,77 @@ + RoutePolicy::class, + ]; + + /** + * The mandatory permissions for the module. + * + * @var array + */ + protected $permissions = [ + [ + 'name' => 'Routes Access', + 'slug' => 'laralum::routes.access', + 'desc' => 'Grants access to laralum/Routes module', + ], + ]; + + /** + * Bootstrap the application services. + * + * @return void + */ + public function boot() + { + $this->registerPolicies(); + + $this->loadViewsFrom(__DIR__.'/Views', 'laralum_routes'); + $this->loadTranslationsFrom(__DIR__.'/Translations', 'laralum_routes'); + + if (!$this->app->routesAreCached()) { + require __DIR__.'/Routes/web.php'; + } + + // Make sure the permissions are OK + PermissionsChecker::check($this->permissions); + } + + /** + * I cheated this comes from the AuthServiceProvider extended by the App\Providers\AuthServiceProvider. + * + * Register the application's policies. + * + * @return void + */ + public function registerPolicies() + { + foreach ($this->policies as $key => $value) { + Gate::policy($key, $value); + } + } + + /** + * Register the application services. + * + * @return void + */ + public function register() + { + } +} diff --git a/src/Translations/ca/general.php b/src/Translations/ca/general.php new file mode 100755 index 0000000..e0eb461 --- /dev/null +++ b/src/Translations/ca/general.php @@ -0,0 +1,15 @@ + 'Inici', + 'name' => 'Nom', + 'routes' => 'Rutes', + 'routes_desc' => 'Veure rutes d\'aplicacions', +]; diff --git a/src/Translations/de/general.php b/src/Translations/de/general.php new file mode 100755 index 0000000..231fbe2 --- /dev/null +++ b/src/Translations/de/general.php @@ -0,0 +1,15 @@ + 'Home', + 'name' => 'Name', + 'routes' => 'Routen', + 'routes_desc' => 'Anzeigen der App Routen', +]; diff --git a/src/Translations/en/general.php b/src/Translations/en/general.php new file mode 100755 index 0000000..6b79333 --- /dev/null +++ b/src/Translations/en/general.php @@ -0,0 +1,15 @@ + 'Home', + 'name' => 'Name', + 'routes' => 'Routes', + 'routes_desc' => 'View application routes', +]; diff --git a/src/Translations/es/general.php b/src/Translations/es/general.php new file mode 100755 index 0000000..7b6ce3f --- /dev/null +++ b/src/Translations/es/general.php @@ -0,0 +1,15 @@ + 'Inicio', + 'name' => 'Nombre', + 'routes' => 'Rutas', + 'routes_desc' => 'Ver rutas de aplicación', +]; diff --git a/src/Translations/fr/general.php b/src/Translations/fr/general.php new file mode 100755 index 0000000..68fa6b4 --- /dev/null +++ b/src/Translations/fr/general.php @@ -0,0 +1,15 @@ + 'Accueil', + 'name' => 'Nom', + 'routes' => 'Itinéraires', + 'routes_desc' => 'Afficher les itinéraires d\'application', +]; diff --git a/src/Translations/it/general.php b/src/Translations/it/general.php new file mode 100755 index 0000000..cbf1419 --- /dev/null +++ b/src/Translations/it/general.php @@ -0,0 +1,15 @@ + 'Casa', + 'name' => 'Nome', + 'routes' => 'itinerari', + 'routes_desc' => 'Visualizza i percorsi di applicazione', +]; diff --git a/src/Views/routes.blade.php b/src/Views/routes.blade.php new file mode 100644 index 0000000..0d91fe6 --- /dev/null +++ b/src/Views/routes.blade.php @@ -0,0 +1,57 @@ +@extends('laralum::layouts.master') +@section('icon', 'ion-soup-can') +@section('title', __('laralum_routes::general.routes')) +@section('subtitle', __('laralum_routes::general.routes_desc')) +@section('breadcrumb') + +@endsection +@section('content') +
+
+
+
+
+
+ @lang('laralum_routes::general.routes') +
+
+
+ + + + + + + + + @forelse($routes as $route) + + + + + @empty + + + + + @endforelse + +
@lang('laralum_CRUD::general.name')second row{{-- @lang('laralum_CRUD::general.actions') --}}
{{ $route }} + {{-- --}} + Some Route +
--
+
+
+
+
+
+
+
+@endsection