Skip to content

Commit b75315b

Browse files
committed
2 parents a0fdaea + 4e0c49b commit b75315b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ Solo::allowCommandsAddedFrom([
189189
]);
190190
```
191191

192+
## Service provider in a custom location.
193+
194+
By default, your `SoloServiceProvider` is created in the `App\Providers` namespace, which is pre-registered as a "safe" location to add commands from. If your `SoloServiceProvider` is in a custom location, it will still be deemed "safe" as long as it resides in your application's namespace (usually `App`, but custom root namespaces are supported.)
195+
196+
192197
## Contributing
193198
Please help.
194199

src/Manager.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Illuminate\Support\Facades\App;
1919
use Illuminate\Support\Facades\Config;
2020
use Illuminate\Support\Facades\Facade;
21+
use Illuminate\Support\Str;
2122
use InvalidArgumentException;
2223
use Laravel\Prompts\Themes\Default\Renderer as PromptsRenderer;
2324
use ReflectionClass;
@@ -43,11 +44,6 @@ class Manager
4344
'dark' => DarkTheme::class,
4445
];
4546

46-
/**
47-
* @var array<class-string>
48-
*/
49-
protected array $configurationAllowedFrom = [];
50-
5147
/**
5248
* @var array<class-string>
5349
*/
@@ -56,7 +52,7 @@ class Manager
5652
public function __construct()
5753
{
5854
// The only classes that are guaranteed to be fully in the user's control.
59-
$this->configurationAllowedFrom = $this->commandsAllowedFrom = [
55+
$this->commandsAllowedFrom = [
6056
App::getNamespace() . 'Providers\\AppServiceProvider',
6157
App::getNamespace() . 'Providers\\SoloServiceProvider',
6258
];
@@ -231,14 +227,15 @@ protected function registrationIsAllowed(): bool
231227

232228
protected function ensureSafeConfigurationLocation($func): void
233229
{
234-
if (in_array($this->caller(), $this->configurationAllowedFrom)) {
230+
$caller = $this->caller();
231+
$namespace = App::getNamespace();
232+
233+
if (Str::startsWith($caller, $namespace)) {
235234
return;
236235
}
237236

238-
$locations = implode(' ', $this->configurationAllowedFrom);
239-
240237
throw new Exception(
241-
"`$func` may only be called from one of the following classes: [$locations]"
238+
"`$func` may only be called from the [$namespace] namespace."
242239
);
243240
}
244241
}

0 commit comments

Comments
 (0)