From 23c7f9a0d57b8a71d284d9022dd68d291a433991 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Tue, 7 Jul 2020 22:48:23 -0400 Subject: [PATCH] Bugfixes --- src/Support/ModularServiceProvider.php | 29 +++++++++++--------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/Support/ModularServiceProvider.php b/src/Support/ModularServiceProvider.php index f390cf4..e78602b 100644 --- a/src/Support/ModularServiceProvider.php +++ b/src/Support/ModularServiceProvider.php @@ -167,6 +167,10 @@ protected function bootViews(): void }); } + /** + * This functionality is likely to go away at some point so don't rely + * on it too much. The package has been abandoned. + */ protected function bootBreadcrumbs(): void { $class_name = 'DaveJamesMiller\\Breadcrumbs\\BreadcrumbsManager'; @@ -208,7 +212,7 @@ protected function registerPolicies(Gate $gate): void { $this->autoDiscoveryHelper() ->modelFileFinder() - ->map(function(SplFileInfo $file) { + ->each(function(SplFileInfo $file) use ($gate) { if (!$module = $this->registry()->moduleForPath($file->getPath())) { throw new RuntimeException("Unable to determine module for '{$file->getPath()}'"); } @@ -220,7 +224,7 @@ protected function registerPolicies(Gate $gate): void $namespaced_model = Str::after($fully_qualified_model, 'Models\\'); $namespaced_policy = rtrim($module->namespaces->first(), '\\').'\\Policies\\'.$namespaced_model.'Policy'; if (class_exists($namespaced_policy)) { - return [$fully_qualified_model, $namespaced_policy]; + $gate->policy($fully_qualified_model, $namespaced_policy); } // If that doesn't match, try the simple mapping as well @@ -230,15 +234,9 @@ protected function registerPolicies(Gate $gate): void $simple_policy = rtrim($module->namespaces->first(), '\\').'\\Policies\\'.$simple_model.'Policy'; if (class_exists($simple_policy)) { - return [$fully_qualified_model, $simple_policy]; + $gate->policy($fully_qualified_model, $simple_policy); } } - - return null; - }) - ->filter() - ->eachSpread(function($class, $policy) use ($gate) { - $gate->policy($class, $policy); }); } @@ -246,18 +244,15 @@ protected function registerCommands(Artisan $artisan): void { $this->autoDiscoveryHelper() ->commandFileFinder() - ->map(function(SplFileInfo $file) { + ->each(function(SplFileInfo $file) use ($artisan) { if (!$module = $this->registry()->moduleForPath($file->getPath())) { throw new RuntimeException("Unable to determine module for '{$file->getPath()}'"); } - return $this->pathToFullyQualifiedClassName($file->getPathname(), $module); - }) - ->filter(function($class_name) { - return $this->isInstantiableCommand($class_name); - }) - ->each(function($command) use ($artisan) { - $artisan->resolve($command); + $class_name = $this->pathToFullyQualifiedClassName($file->getPathname(), $module); + if ($this->isInstantiableCommand($class_name)) { + $artisan->resolve($class_name); + } }); }