Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ Solo::allowCommandsAddedFrom([
]);
```

## Service provider in a custom location.

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.)


## Contributing
Please help.

Expand Down
17 changes: 7 additions & 10 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Laravel\Prompts\Themes\Default\Renderer as PromptsRenderer;
use ReflectionClass;
Expand All @@ -43,11 +44,6 @@ class Manager
'dark' => DarkTheme::class,
];

/**
* @var array<class-string>
*/
protected array $configurationAllowedFrom = [];

/**
* @var array<class-string>
*/
Expand All @@ -56,7 +52,7 @@ class Manager
public function __construct()
{
// The only classes that are guaranteed to be fully in the user's control.
$this->configurationAllowedFrom = $this->commandsAllowedFrom = [
$this->commandsAllowedFrom = [
App::getNamespace() . 'Providers\\AppServiceProvider',
App::getNamespace() . 'Providers\\SoloServiceProvider',
];
Expand Down Expand Up @@ -231,14 +227,15 @@ protected function registrationIsAllowed(): bool

protected function ensureSafeConfigurationLocation($func): void
{
if (in_array($this->caller(), $this->configurationAllowedFrom)) {
$caller = $this->caller();
$namespace = App::getNamespace();

if (Str::startsWith($caller, $namespace)) {
return;
}

$locations = implode(' ', $this->configurationAllowedFrom);

throw new Exception(
"`$func` may only be called from one of the following classes: [$locations]"
"`$func` may only be called from the [$namespace] namespace."
);
}
}