From a4882b840a6a150f640ec67212560e8ade9fd250 Mon Sep 17 00:00:00 2001 From: Tobias van Beek Date: Mon, 9 Oct 2017 22:36:04 +0200 Subject: [PATCH] Add the option to disable the action in the laroute call to prevent exposing the PHP class and method names See: https://github.com/aaronlord/laroute/issues/58 --- config/laroute.php | 8 +++++++- src/LarouteServiceProvider.php | 2 +- src/Routes/Collection.php | 23 +++++++++++++---------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/config/laroute.php b/config/laroute.php index 6866c49..a69f59a 100644 --- a/config/laroute.php +++ b/config/laroute.php @@ -42,13 +42,19 @@ */ 'action_namespace' => '', + /* + * If we use the actions, this will expose the PHP classes and methods + * See: https://github.com/aaronlord/laroute/issues/58 + */ + 'use_actions' => true, + /* * The path to the template `laroute.js` file. This is the file that contains * the ported helper Laravel url/route functions and the route data to go * with them. */ 'template' => 'vendor/lord/laroute/src/templates/laroute.js', - + /* * Appends a prefix to URLs. By default the prefix is an empty string. * diff --git a/src/LarouteServiceProvider.php b/src/LarouteServiceProvider.php index 3062dd0..aad778a 100644 --- a/src/LarouteServiceProvider.php +++ b/src/LarouteServiceProvider.php @@ -83,7 +83,7 @@ protected function registerCommand() 'command.laroute.generate', function ($app) { $config = $app['config']; - $routes = new Routes($app['router']->getRoutes(), $config->get('laroute.filter', 'all'), $config->get('laroute.action_namespace', '')); + $routes = new Routes($app['router']->getRoutes(), $config->get('laroute.filter', 'all'), $config->get('laroute.action_namespace', ''), $config->get('laroute.use_actions', true)); $generator = $app->make('Lord\Laroute\Generators\GeneratorInterface'); return new LarouteGeneratorCommand($config, $routes, $generator); diff --git a/src/Routes/Collection.php b/src/Routes/Collection.php index f6388c6..65187e3 100644 --- a/src/Routes/Collection.php +++ b/src/Routes/Collection.php @@ -8,9 +8,9 @@ class Collection extends \Illuminate\Support\Collection { - public function __construct(RouteCollection $routes, $filter, $namespace) + public function __construct(RouteCollection $routes, $filter, $namespace, $useActions = true) { - $this->items = $this->parseRoutes($routes, $filter, $namespace); + $this->items = $this->parseRoutes($routes, $filter, $namespace, $useActions); } /** @@ -23,14 +23,14 @@ public function __construct(RouteCollection $routes, $filter, $namespace) * @return array * @throws ZeroRoutesException */ - protected function parseRoutes(RouteCollection $routes, $filter, $namespace) + protected function parseRoutes(RouteCollection $routes, $filter, $namespace, $useActions) { $this->guardAgainstZeroRoutes($routes); $results = []; foreach ($routes as $route) { - $results[] = $this->getRouteInformation($route, $filter, $namespace); + $results[] = $this->getRouteInformation($route, $filter, $namespace, $useActions); } return array_values(array_filter($results)); @@ -59,20 +59,23 @@ protected function guardAgainstZeroRoutes(RouteCollection $routes) * * @return array */ - protected function getRouteInformation(Route $route, $filter, $namespace) + protected function getRouteInformation(Route $route, $filter, $namespace, $useActions) { $host = $route->domain(); $methods = $route->methods(); $uri = $route->uri(); $name = $route->getName(); - $action = $route->getActionName(); + $action = ''; $laroute = array_get($route->getAction(), 'laroute', null); - if(!empty($namespace)) { - $a = $route->getAction(); + if ($useActions) { + $action = $route->getActionName(); + if(!empty($namespace)) { + $a = $route->getAction(); - if(isset($a['controller'])) { - $action = str_replace($namespace.'\\', '', $action); + if(isset($a['controller'])) { + $action = str_replace($namespace.'\\', '', $action); + } } }