|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of laravel-stubs package. |
| 4 | + * |
| 5 | + * @author ATehnix <atehnix@gmail.com> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | +namespace ATehnix\LaravelStubs\Console; |
| 11 | + |
| 12 | +use Illuminate\Foundation\Console\ListenerMakeCommand as BaseListenerMakeCommand; |
| 13 | +use Illuminate\Support\Str; |
| 14 | + |
| 15 | +class ListenerMakeCommand extends BaseListenerMakeCommand |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Get the stub file for the generator. |
| 19 | + * |
| 20 | + * @return string |
| 21 | + */ |
| 22 | + protected function getStub() |
| 23 | + { |
| 24 | + if ($this->option('queued')) { |
| 25 | + $stub = config('stubs.path').'/listener-queued.stub'; |
| 26 | + } else { |
| 27 | + $stub = config('stubs.path').'/listener.stub'; |
| 28 | + } |
| 29 | + |
| 30 | + return file_exists($stub) ? $stub : parent::getStub(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Get the default namespace for the class. |
| 35 | + * |
| 36 | + * @param string $rootNamespace |
| 37 | + * @return string |
| 38 | + */ |
| 39 | + protected function getDefaultNamespace($rootNamespace) |
| 40 | + { |
| 41 | + return $rootNamespace.config('stubs.namespaces.listener'); |
| 42 | + } |
| 43 | + |
| 44 | + protected function buildClass($name) |
| 45 | + { |
| 46 | + $stub = $this->files->get($this->getStub()); |
| 47 | + $stub = $this->replaceNamespace($stub, $name)->replaceClass($stub, $name); |
| 48 | + $event = $this->getEvent(); |
| 49 | + $stub = str_replace('DummyEvent', class_basename($event), $stub); |
| 50 | + $stub = str_replace('DummyFullEvent', $event, $stub); |
| 51 | + |
| 52 | + return $stub; |
| 53 | + } |
| 54 | + |
| 55 | + protected function getEvent() |
| 56 | + { |
| 57 | + $event = $this->option('event'); |
| 58 | + |
| 59 | + if (! Str::startsWith($event, $this->laravel->getNamespace()) && ! Str::startsWith($event, 'Illuminate')) { |
| 60 | + $eventNamespace = ltrim(config('stubs.namespaces.event'), '\\').'\\'; |
| 61 | + $event = $this->laravel->getNamespace().$eventNamespace.$event; |
| 62 | + } |
| 63 | + |
| 64 | + return $event; |
| 65 | + } |
| 66 | +} |
0 commit comments