|
13 | 13 | namespace Guanguans\LaravelExceptionNotify; |
14 | 14 |
|
15 | 15 | use Guanguans\LaravelExceptionNotify\Commands\TestCommand; |
| 16 | +use Guanguans\LaravelExceptionNotify\Facades\ExceptionNotify; |
16 | 17 | use Guanguans\LaravelExceptionNotify\Macros\CollectionMacro; |
17 | 18 | use Guanguans\LaravelExceptionNotify\Macros\RequestMacro; |
18 | 19 | use Guanguans\LaravelExceptionNotify\Macros\StringableMacro; |
@@ -135,9 +136,7 @@ protected function registerCollectorManager(): self |
135 | 136 | protected function registerTestCommand(): self |
136 | 137 | { |
137 | 138 | $this->app->singleton(TestCommand::class); |
138 | | - |
139 | 139 | $this->alias(TestCommand::class); |
140 | | - $this->app->alias(TestCommand::class, 'command.exception-notify.test'); |
141 | 140 |
|
142 | 141 | return $this; |
143 | 142 | } |
@@ -171,23 +170,24 @@ protected function registerCommands(): self |
171 | 170 | /** |
172 | 171 | * @param class-string $class |
173 | 172 | */ |
174 | | - protected function alias(string $class, ?string $prefix = null): void |
| 173 | + protected function alias(string $class): self |
175 | 174 | { |
176 | | - $this->app->alias($class, $this->toAlias($class, $prefix)); |
| 175 | + $this->app->alias($class, $this->toAlias($class)); |
| 176 | + |
| 177 | + return $this; |
177 | 178 | } |
178 | 179 |
|
179 | 180 | /** |
180 | 181 | * @param class-string $class |
181 | 182 | */ |
182 | | - protected function toAlias(string $class, ?string $prefix = null): string |
| 183 | + protected function toAlias(string $class): string |
183 | 184 | { |
184 | | - $prefix ??= 'exception.notify.'; |
185 | | - |
186 | | - $alias = Str::snake(class_basename($class), '.'); |
187 | | - if (Str::startsWith($alias, Str::replaceLast('.', '', $prefix))) { |
188 | | - return $alias; |
189 | | - } |
190 | | - |
191 | | - return $prefix.$alias; |
| 185 | + return str($class) |
| 186 | + ->replaceFirst(__NAMESPACE__, '') |
| 187 | + ->start('\\'.class_basename(ExceptionNotify::class)) |
| 188 | + ->ltrim('\\') |
| 189 | + ->explode('\\') |
| 190 | + ->map(static fn (string $name): string => Str::snake($name, '-')) |
| 191 | + ->implode('.'); |
192 | 192 | } |
193 | 193 | } |
0 commit comments