├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── publish └── config │ └── stubs.php └── src ├── Console ├── ChannelMakeCommand.php ├── ConsoleMakeCommand.php ├── ControllerMakeCommand.php ├── EventMakeCommand.php ├── ExceptionMakeCommand.php ├── FactoryMakeCommand.php ├── JobMakeCommand.php ├── ListenerMakeCommand.php ├── MailMakeCommand.php ├── MiddlewareMakeCommand.php ├── ModelMakeCommand.php ├── Modulable.php ├── NotificationMakeCommand.php ├── ObserverMakeCommand.php ├── PolicyMakeCommand.php ├── ProviderMakeCommand.php ├── RequestMakeCommand.php ├── ResourceMakeCommand.php ├── RuleMakeCommand.php ├── SeederMakeCommand.php ├── StubsPublishCommand.php └── TestMakeCommand.php ├── Database └── MigrationCreator.php └── Providers ├── ArtisanServiceProvider.php ├── ConsoleSupportServiceProvider.php └── MigrationServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | vendor/ 3 | composer.lock -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2019 Andrey Sosnov aka ATehnix 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Customize laravel make command 2 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) 3 | [![Packagist Version](https://img.shields.io/packagist/v/atehnix/laravel-stubs.svg?maxAge=0)](https://packagist.org/packages/atehnix/laravel-stubs) 4 | [![Packagist Stats](https://poser.pugx.org/atehnix/laravel-stubs/downloads)](https://packagist.org/packages/atehnix/laravel-stubs/stats) 5 | 6 | 7 | The package gives you the opportunity to customize Artisan commands like `artisan make:model`, `artisan make:controller` and other, just as you need. 8 | 9 | Any location of the generated classes and with any content. 10 | 11 | 12 | ## Only Laravel 6 or less is supported. 13 | 14 | **The laravel-stubs functionality (partially) is [now added](https://laravel.com/docs/master/artisan#stub-customization) as part of the Laravel framework (v7).** 15 | 16 | **The laravel-stubs package remains available as an implementation of this functionality for previous versions of the framework, but will not be updated for new versions of Laravel.** 17 | 18 | 19 | ## Installation 20 | > *For laravel v5.4 or older see: [older installation](https://github.com/atehnix/laravel-stubs/tree/v2.0.0#installation)* 21 | 22 | You can get library through [composer](https://getcomposer.org/) 23 | 24 | ``` 25 | composer require atehnix/laravel-stubs 26 | ``` 27 | 28 | To publish the config file to `config/stubs.php` run: 29 | 30 | ``` 31 | php artisan vendor:publish --provider="ATehnix\LaravelStubs\Providers\ConsoleSupportServiceProvider" 32 | ``` 33 | 34 | Done! 35 | 36 | 37 | ## Usage 38 | 39 | ### Configure paths for generated classes 40 | To change the paths of saving the generated classes, you need to configure their namespaces in a configuration file `config/stubs.php`. 41 | 42 | ### Modular development. 43 | If you have a large project, you may want to divide it into modules as subdirectories in the "app" directory. 44 | 45 | To make classes inside the module you are developing, you can specify the name of the module in the `STUBS_MODULE` environment variable. 46 | 47 | ### Publish stub files for edit 48 | ``` 49 | php artisan stubs:publish 50 | ``` 51 | 52 | The files will be placed in the directory `resources/stubs` (or other directory if you change it in the configuration file). 53 | 54 | Now you can edit any of the stubs and enjoy your customized commands like `artisan make:model`,` artisan make:controller` and others. 55 | 56 | 57 | ## License 58 | [MIT](LICENSE) 59 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "atehnix/laravel-stubs", 3 | "description": "Customize laravel make command.", 4 | "keywords": [ 5 | "laravel", 6 | "stub", 7 | "make", 8 | "generator" 9 | ], 10 | "type": "library", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Andrey Sosnov", 15 | "email": "atehnix@gmail.com" 16 | } 17 | ], 18 | "require": { 19 | "php": "^7.2", 20 | "laravel/framework": "^6.0" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "ATehnix\\LaravelStubs\\": "src" 25 | } 26 | }, 27 | "extra": { 28 | "laravel": { 29 | "providers": [ 30 | "ATehnix\\LaravelStubs\\Providers\\ConsoleSupportServiceProvider" 31 | ] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /publish/config/stubs.php: -------------------------------------------------------------------------------- 1 | base_path('resources/stubs'), 11 | 12 | /* 13 | |-------------------------------------------------------------------------- 14 | | Default namespaces for the classes 15 | |-------------------------------------------------------------------------- 16 | | Warning! Root application namespace (like "App") should be skipped. 17 | */ 18 | 'namespaces' => [ 19 | 'channel' => '\Broadcasting', 20 | 'command' => '\Console\Commands', 21 | 'controller' => '\Http\Controllers', 22 | 'event' => '\Events', 23 | 'exception' => '\Exceptions', 24 | 'job' => '\Jobs', 25 | 'listener' => '\Listeners', 26 | 'mail' => '\Mail', 27 | 'middleware' => '\Http\Middleware', 28 | 'model' => '', 29 | 'notification' => '\Notifications', 30 | 'observer' => '\Observers', 31 | 'policy' => '\Policies', 32 | 'provider' => '\Providers', 33 | 'request' => '\Http\Requests', 34 | 'resource' => '\Http\Resources', 35 | 'rule' => '\Rules', 36 | ], 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | The name of the module that is being developed 41 | |-------------------------------------------------------------------------- 42 | | When specified, the namespaces will be prefixed with 43 | | the appropriate module name. 44 | | 45 | | For example, if the module is set to 'Blog', then the namespace 46 | | for the controllers might look like: "App\Blog\Http\Controllers" 47 | */ 48 | 'module' => env('STUBS_MODULE', ''), 49 | 50 | ]; 51 | -------------------------------------------------------------------------------- /src/Console/ChannelMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\ChannelMakeCommand as BaseChannelMakeCommand; 14 | 15 | class ChannelMakeCommand extends BaseChannelMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | $stub = config('stubs.path') . '/channel.stub'; 27 | 28 | return file_exists($stub) ? $stub : parent::getStub(); 29 | } 30 | 31 | /** 32 | * Get the default namespace for the class. 33 | * 34 | * @param string $rootNamespace 35 | * @return string 36 | */ 37 | protected function getDefaultNamespace($rootNamespace) 38 | { 39 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.channel'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Console/ConsoleMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\ConsoleMakeCommand as BaseConsoleMakeCommand; 14 | 15 | class ConsoleMakeCommand extends BaseConsoleMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | $stub = config('stubs.path') . '/console.stub'; 27 | 28 | return file_exists($stub) ? $stub : parent::getStub(); 29 | } 30 | 31 | /** 32 | * Get the default namespace for the class. 33 | * 34 | * @param string $rootNamespace 35 | * @return string 36 | */ 37 | protected function getDefaultNamespace($rootNamespace) 38 | { 39 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.command'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Console/ControllerMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Routing\Console\ControllerMakeCommand as BaseControllerMakeCommand; 14 | use Illuminate\Support\Str; 15 | use InvalidArgumentException; 16 | 17 | class ControllerMakeCommand extends BaseControllerMakeCommand 18 | { 19 | use Modulable; 20 | 21 | /** 22 | * The Laravel application instance. 23 | * 24 | * @var \Illuminate\Foundation\Application 25 | */ 26 | protected $laravel; 27 | 28 | /** 29 | * Get the stub file for the generator. 30 | * 31 | * @return string 32 | */ 33 | protected function getStub() 34 | { 35 | $stub = null; 36 | 37 | if ($this->option('parent')) { 38 | $stub = config('stubs.path') . '/controller.nested.stub'; 39 | } elseif ($this->option('model')) { 40 | $stub = config('stubs.path') . '/controller.model.stub'; 41 | } elseif ($this->option('invokable')) { 42 | $stub = config('stubs.path') . '/controller.invokable.stub'; 43 | } elseif ($this->option('resource')) { 44 | $stub = config('stubs.path') . '/controller.stub'; 45 | } 46 | 47 | if ($this->option('api') && is_null($stub)) { 48 | $stub = config('stubs.path') . '/controller.api.stub'; 49 | } elseif ($this->option('api') && !is_null($stub) && !$this->option('invokable')) { 50 | $stub = str_replace('.stub', '.api.stub', $stub); 51 | } 52 | 53 | $stub = $stub ?? config('stubs.path') . '/controller.plain.stub'; 54 | 55 | return file_exists($stub) ? $stub : parent::getStub(); 56 | } 57 | 58 | /** 59 | * Get the default namespace for the class. 60 | * 61 | * @param string $rootNamespace 62 | * @return string 63 | */ 64 | protected function getDefaultNamespace($rootNamespace) 65 | { 66 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.controller'); 67 | } 68 | 69 | /** 70 | * Get the fully-qualified model class name. 71 | * 72 | * @param string $model 73 | * @return string 74 | */ 75 | protected function parseModel($model) 76 | { 77 | if (preg_match('([^A-Za-z0-9_/\\\\])', $model)) { 78 | throw new InvalidArgumentException('Model name contains invalid characters.'); 79 | } 80 | 81 | $model = trim(str_replace('/', '\\', $model), '\\'); 82 | 83 | $namespace = 84 | trim($this->laravel->getNamespace(), '\\') 85 | . $this->getModuleNamespace() 86 | . config('stubs.namespaces.model') . '\\'; 87 | 88 | if (!Str::startsWith($model, $namespace)) { 89 | $model = $namespace . $model; 90 | } 91 | 92 | return $model; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Console/EventMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\EventMakeCommand as BaseEventMakeCommand; 14 | 15 | class EventMakeCommand extends BaseEventMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | $stub = config('stubs.path') . '/event.stub'; 27 | 28 | return file_exists($stub) ? $stub : parent::getStub(); 29 | } 30 | 31 | /** 32 | * Get the default namespace for the class. 33 | * 34 | * @param string $rootNamespace 35 | * @return string 36 | */ 37 | protected function getDefaultNamespace($rootNamespace) 38 | { 39 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.event'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Console/ExceptionMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\ExceptionMakeCommand as BaseExceptionMakeCommand; 14 | 15 | class ExceptionMakeCommand extends BaseExceptionMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | if ($this->option('render') && $this->option('report')) { 27 | $stub = config('stubs.path') . '/exception-render-report.stub'; 28 | } elseif ($this->option('render')) { 29 | $stub = config('stubs.path') . '/exception-render.stub'; 30 | } elseif ($this->option('report')) { 31 | $stub = config('stubs.path') . '/exception-report.stub'; 32 | } else { 33 | $stub = config('stubs.path') . '/exception.stub'; 34 | } 35 | 36 | return file_exists($stub) ? $stub : parent::getStub(); 37 | } 38 | 39 | /** 40 | * Get the default namespace for the class. 41 | * 42 | * @param string $rootNamespace 43 | * @return string 44 | */ 45 | protected function getDefaultNamespace($rootNamespace) 46 | { 47 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.exception'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Console/FactoryMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Database\Console\Factories\FactoryMakeCommand as BaseFactoryMakeCommand; 14 | 15 | class FactoryMakeCommand extends BaseFactoryMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | $stub = config('stubs.path') . '/factory.stub'; 27 | 28 | return file_exists($stub) ? $stub : parent::getStub(); 29 | } 30 | 31 | /** 32 | * Get the default namespace for the class. 33 | * 34 | * @param string $rootNamespace 35 | * @return string 36 | */ 37 | protected function getDefaultNamespace($rootNamespace) 38 | { 39 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.model'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Console/JobMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\JobMakeCommand as BaseJobMakeCommand; 14 | 15 | class JobMakeCommand extends BaseJobMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | if ($this->option('sync')) { 27 | $stub = config('stubs.path') . '/job.stub'; 28 | } else { 29 | $stub = config('stubs.path') . '/job-queued.stub'; 30 | } 31 | 32 | return file_exists($stub) ? $stub : parent::getStub(); 33 | } 34 | 35 | /** 36 | * Get the default namespace for the class. 37 | * 38 | * @param string $rootNamespace 39 | * @return string 40 | */ 41 | protected function getDefaultNamespace($rootNamespace) 42 | { 43 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.job'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Console/ListenerMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\ListenerMakeCommand as BaseListenerMakeCommand; 14 | use Illuminate\Support\Str; 15 | 16 | class ListenerMakeCommand extends BaseListenerMakeCommand 17 | { 18 | use Modulable; 19 | 20 | /** 21 | * The Laravel application instance. 22 | * 23 | * @var \Illuminate\Foundation\Application 24 | */ 25 | protected $laravel; 26 | 27 | /** 28 | * Get the default namespace for the class. 29 | * 30 | * @param string $rootNamespace 31 | * @return string 32 | */ 33 | protected function getDefaultNamespace($rootNamespace) 34 | { 35 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.listener'); 36 | } 37 | 38 | /** 39 | * @param string $name 40 | * @return mixed|string 41 | * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException 42 | */ 43 | protected function buildClass($name) 44 | { 45 | $stub = $this->files->get($this->getStub()); 46 | $stub = $this->replaceNamespace($stub, $name)->replaceClass($stub, $name); 47 | $event = $this->getEvent(); 48 | $stub = str_replace('DummyEvent', class_basename($event), $stub); 49 | $stub = str_replace('DummyFullEvent', $event, $stub); 50 | 51 | return $stub; 52 | } 53 | 54 | /** 55 | * Get the stub file for the generator. 56 | * 57 | * @return string 58 | */ 59 | protected function getStub() 60 | { 61 | if ($this->option('queued') && $this->option('event')) { 62 | $stub = config('stubs.path') . '/listener-queued.stub'; 63 | } elseif ($this->option('queued')) { 64 | $stub = config('stubs.path') . '/listener-queued-duck.stub'; 65 | } elseif ($this->option('event')) { 66 | $stub = config('stubs.path') . '/listener.stub'; 67 | } else { 68 | $stub = config('stubs.path') . '/listener-duck.stub'; 69 | } 70 | 71 | return file_exists($stub) ? $stub : parent::getStub(); 72 | } 73 | 74 | protected function getEvent() 75 | { 76 | $event = $this->option('event'); 77 | 78 | $namespace = 79 | trim($this->laravel->getNamespace(), '\\') 80 | . $this->getModuleNamespace() 81 | . config('stubs.namespaces.event') . '\\'; 82 | 83 | if (!Str::startsWith($event, [ 84 | $namespace, 85 | 'Illuminate', 86 | '\\', 87 | ])) { 88 | $event = $namespace . $event; 89 | } 90 | 91 | return $event; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Console/MailMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\MailMakeCommand as BaseMailMakeCommand; 14 | 15 | class MailMakeCommand extends BaseMailMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | if ($this->option('markdown')) { 27 | $stub = config('stubs.path') . '/markdown-mail.stub'; 28 | } else { 29 | $stub = config('stubs.path') . '/mail.stub'; 30 | } 31 | 32 | return file_exists($stub) ? $stub : parent::getStub(); 33 | } 34 | 35 | /** 36 | * Get the default namespace for the class. 37 | * 38 | * @param string $rootNamespace 39 | * @return string 40 | */ 41 | protected function getDefaultNamespace($rootNamespace) 42 | { 43 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.mail'); 44 | } 45 | 46 | /** 47 | * Write the Markdown template for the mailable. 48 | * 49 | * @return void 50 | */ 51 | protected function writeMarkdownTemplate() 52 | { 53 | $path = resource_path('views/' . str_replace('.', '/', $this->option('markdown'))) . '.blade.php'; 54 | 55 | if (!$this->files->isDirectory(dirname($path))) { 56 | $this->files->makeDirectory(dirname($path), 0755, true); 57 | } 58 | 59 | $stub = config('stubs.path') . '/markdown.stub'; 60 | 61 | if (file_exists($stub)) { 62 | $this->files->put($path, file_get_contents($stub)); 63 | } else { 64 | parent::writeMarkdownTemplate(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Console/MiddlewareMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Routing\Console\MiddlewareMakeCommand as BaseMiddlewareMakeCommand; 14 | 15 | class MiddlewareMakeCommand extends BaseMiddlewareMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | $stub = config('stubs.path') . '/middleware.stub'; 27 | 28 | return file_exists($stub) ? $stub : parent::getStub(); 29 | } 30 | 31 | /** 32 | * Get the default namespace for the class. 33 | * 34 | * @param string $rootNamespace 35 | * @return string 36 | */ 37 | protected function getDefaultNamespace($rootNamespace) 38 | { 39 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.middleware'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Console/ModelMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\ModelMakeCommand as BaseModelMakeCommand; 14 | 15 | class ModelMakeCommand extends BaseModelMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | if ($this->option('pivot')) { 27 | $stub = config('stubs.path') . '/pivot.model.stub'; 28 | } else { 29 | $stub = config('stubs.path') . '/model.stub'; 30 | } 31 | 32 | return file_exists($stub) ? $stub : parent::getStub(); 33 | } 34 | 35 | /** 36 | * Get the default namespace for the class. 37 | * 38 | * @param string $rootNamespace 39 | * @return string 40 | */ 41 | protected function getDefaultNamespace($rootNamespace) 42 | { 43 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.model'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Console/Modulable.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | trait Modulable 14 | { 15 | /** 16 | * The namespace prefix of the module that is being developed 17 | * 18 | * @return string|null 19 | */ 20 | protected function getModuleNamespace() 21 | { 22 | $module = trim(config('stubs.module'), '\\'); 23 | 24 | return $module ? '\\' . $module : null; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Console/NotificationMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\NotificationMakeCommand as BaseNotificationMakeCommand; 14 | 15 | class NotificationMakeCommand extends BaseNotificationMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | if ($this->option('markdown')) { 27 | $stub = config('stubs.path') . '/markdown-notification.stub'; 28 | } else { 29 | $stub = config('stubs.path') . '/notification.stub'; 30 | } 31 | 32 | return file_exists($stub) ? $stub : parent::getStub(); 33 | } 34 | 35 | /** 36 | * Get the default namespace for the class. 37 | * 38 | * @param string $rootNamespace 39 | * @return string 40 | */ 41 | protected function getDefaultNamespace($rootNamespace) 42 | { 43 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.notification'); 44 | } 45 | 46 | /** 47 | * Write the Markdown template for the mailable. 48 | * 49 | * @return void 50 | */ 51 | protected function writeMarkdownTemplate() 52 | { 53 | $path = resource_path('views/' . str_replace('.', '/', $this->option('markdown'))) . '.blade.php'; 54 | 55 | if (!$this->files->isDirectory(dirname($path))) { 56 | $this->files->makeDirectory(dirname($path), 0755, true); 57 | } 58 | 59 | $stub = config('stubs.path') . '/markdown.stub'; 60 | 61 | if (file_exists($stub)) { 62 | $this->files->put($path, file_get_contents($stub)); 63 | } else { 64 | parent::writeMarkdownTemplate(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Console/ObserverMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\ObserverMakeCommand as BaseObserverMakeCommand; 14 | use Illuminate\Support\Str; 15 | 16 | class ObserverMakeCommand extends BaseObserverMakeCommand 17 | { 18 | use Modulable; 19 | 20 | /** 21 | * Get the stub file for the generator. 22 | * 23 | * @return string 24 | */ 25 | protected function getStub() 26 | { 27 | if ($this->option('model')) { 28 | $stub = config('stubs.path') . '/observer.stub'; 29 | } else { 30 | $stub = config('stubs.path') . '/observer.plain.stub'; 31 | } 32 | 33 | return file_exists($stub) ? $stub : parent::getStub(); 34 | } 35 | 36 | /** 37 | * Get the default namespace for the class. 38 | * 39 | * @param string $rootNamespace 40 | * @return string 41 | */ 42 | protected function getDefaultNamespace($rootNamespace) 43 | { 44 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.observer'); 45 | } 46 | 47 | /** 48 | * Replace the model for the given stub. 49 | * 50 | * @param string $stub 51 | * @param string $model 52 | * @return string 53 | */ 54 | protected function replaceModel($stub, $model) 55 | { 56 | $model = str_replace('/', '\\', $model); 57 | 58 | $namespaceModel = 59 | trim($this->laravel->getNamespace(), '\\') 60 | . $this->getModuleNamespace() 61 | . config('stubs.namespaces.model') . '\\' 62 | . $model; 63 | 64 | if (Str::startsWith($model, '\\')) { 65 | $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub); 66 | } else { 67 | $stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub); 68 | } 69 | 70 | $stub = str_replace( 71 | "use {$namespaceModel};\nuse {$namespaceModel};", "use {$namespaceModel};", $stub 72 | ); 73 | 74 | $model = class_basename(trim($model, '\\')); 75 | $stub = str_replace('DocDummyModel', Str::snake($model, ' '), $stub); 76 | $stub = str_replace('DummyModel', $model, $stub); 77 | 78 | return str_replace('dummyModel', Str::camel($model), $stub); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Console/PolicyMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\PolicyMakeCommand as BasePolicyMakeCommand; 14 | use Illuminate\Support\Str; 15 | 16 | class PolicyMakeCommand extends BasePolicyMakeCommand 17 | { 18 | use Modulable; 19 | 20 | /** 21 | * The Laravel application instance. 22 | * 23 | * @var \Illuminate\Foundation\Application 24 | */ 25 | protected $laravel; 26 | 27 | /** 28 | * Get the stub file for the generator. 29 | * 30 | * @return string 31 | */ 32 | protected function getStub() 33 | { 34 | if ($this->option('model')) { 35 | $stub = config('stubs.path') . '/policy.stub'; 36 | } else { 37 | $stub = config('stubs.path') . '/policy.plain.stub'; 38 | } 39 | 40 | return file_exists($stub) ? $stub : parent::getStub(); 41 | } 42 | 43 | /** 44 | * Get the default namespace for the class. 45 | * 46 | * @param string $rootNamespace 47 | * @return string 48 | */ 49 | protected function getDefaultNamespace($rootNamespace) 50 | { 51 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.policy'); 52 | } 53 | 54 | /** 55 | * Replace the model for the given stub. 56 | * 57 | * @param string $stub 58 | * @param string $model 59 | * @return string 60 | */ 61 | protected function replaceModel($stub, $model) 62 | { 63 | $model = str_replace('/', '\\', $model); 64 | 65 | $namespaceModel = 66 | trim($this->laravel->getNamespace(), '\\') 67 | . $this->getModuleNamespace() 68 | . config('stubs.namespaces.model') . '\\' 69 | . $model; 70 | 71 | if (Str::startsWith($model, '\\')) { 72 | $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub); 73 | } else { 74 | $stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub); 75 | } 76 | 77 | $stub = str_replace( 78 | "use {$namespaceModel};\nuse {$namespaceModel};", "use {$namespaceModel};", $stub 79 | ); 80 | 81 | $model = class_basename(trim($model, '\\')); 82 | $dummyUser = class_basename(config('auth.providers.users.model')); 83 | $dummyModel = Str::camel($model) === 'user' ? 'model' : Str::camel($model); 84 | 85 | $stub = str_replace('DummyModel', $model, $stub); 86 | $stub = str_replace('dummyModel', $dummyModel, $stub); 87 | $stub = str_replace('DummyUser', $dummyUser, $stub); 88 | 89 | return str_replace('dummyPluralModel', Str::plural($dummyModel), $stub); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Console/ProviderMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\ProviderMakeCommand as BaseProviderMakeCommand; 14 | 15 | class ProviderMakeCommand extends BaseProviderMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | $stub = config('stubs.path') . '/provider.stub'; 27 | 28 | return file_exists($stub) ? $stub : parent::getStub(); 29 | } 30 | 31 | /** 32 | * Get the default namespace for the class. 33 | * 34 | * @param string $rootNamespace 35 | * @return string 36 | */ 37 | protected function getDefaultNamespace($rootNamespace) 38 | { 39 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.provider'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Console/RequestMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\RequestMakeCommand as BaseRequestMakeCommand; 14 | 15 | class RequestMakeCommand extends BaseRequestMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | $stub = config('stubs.path') . '/request.stub'; 27 | 28 | return file_exists($stub) ? $stub : parent::getStub(); 29 | } 30 | 31 | /** 32 | * Get the default namespace for the class. 33 | * 34 | * @param string $rootNamespace 35 | * @return string 36 | */ 37 | protected function getDefaultNamespace($rootNamespace) 38 | { 39 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.request'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Console/ResourceMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\ResourceMakeCommand as BaseResourceMakeCommand; 14 | 15 | class ResourceMakeCommand extends BaseResourceMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | if ($this->collection()) { 27 | $stub = config('stubs.path') . '/resource-collection.stub'; 28 | } else { 29 | $stub = config('stubs.path') . '/resource.stub'; 30 | } 31 | 32 | return file_exists($stub) ? $stub : parent::getStub(); 33 | } 34 | 35 | /** 36 | * Get the default namespace for the class. 37 | * 38 | * @param string $rootNamespace 39 | * @return string 40 | */ 41 | protected function getDefaultNamespace($rootNamespace) 42 | { 43 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.resource'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Console/RuleMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\RuleMakeCommand as BaseRuleMakeCommand; 14 | 15 | class RuleMakeCommand extends BaseRuleMakeCommand 16 | { 17 | use Modulable; 18 | 19 | /** 20 | * Get the stub file for the generator. 21 | * 22 | * @return string 23 | */ 24 | protected function getStub() 25 | { 26 | $stub = config('stubs.path') . '/rule.stub'; 27 | 28 | return file_exists($stub) ? $stub : parent::getStub(); 29 | } 30 | 31 | /** 32 | * Get the default namespace for the class. 33 | * 34 | * @param string $rootNamespace 35 | * @return string 36 | */ 37 | protected function getDefaultNamespace($rootNamespace) 38 | { 39 | return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.rule'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Console/SeederMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Database\Console\Seeds\SeederMakeCommand as BaseSeederMakeCommand; 14 | 15 | class SeederMakeCommand extends BaseSeederMakeCommand 16 | { 17 | /** 18 | * Get the stub file for the generator. 19 | * 20 | * @return string 21 | */ 22 | protected function getStub() 23 | { 24 | $stub = config('stubs.path') . '/seeder.stub'; 25 | 26 | return file_exists($stub) ? $stub : parent::getStub(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Console/StubsPublishCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Console\Command; 14 | use Illuminate\Filesystem\Filesystem; 15 | 16 | class StubsPublishCommand extends Command 17 | { 18 | /** 19 | * The console command name. 20 | * 21 | * @var string 22 | */ 23 | protected $name = 'stubs:publish'; 24 | 25 | /** 26 | * The console command description. 27 | * 28 | * @var string 29 | */ 30 | protected $description = 'Publish any stub files from framework'; 31 | 32 | /** 33 | * The filesystem instance. 34 | * 35 | * @var \Illuminate\Filesystem\Filesystem 36 | */ 37 | protected $files; 38 | 39 | /** 40 | * Path to the Laravel Framework source directory 41 | * 42 | * @var string 43 | */ 44 | protected $frameworkPath = 'vendor/laravel/framework/src/'; 45 | 46 | /** 47 | * Paths to stub files and a map of their names 48 | * 49 | * @var array 50 | */ 51 | protected $stubs = [ 52 | 'channel.stub' => 'Illuminate/Foundation/Console/stubs/channel.stub', 53 | 'console.stub' => 'Illuminate/Foundation/Console/stubs/console.stub', 54 | 'controller.api.stub' => 'Illuminate/Routing/Console/stubs/controller.api.stub', 55 | 'controller.invokable.stub' => 'Illuminate/Routing/Console/stubs/controller.invokable.stub', 56 | 'controller.model.api.stub' => 'Illuminate/Routing/Console/stubs/controller.model.api.stub', 57 | 'controller.model.stub' => 'Illuminate/Routing/Console/stubs/controller.model.stub', 58 | 'controller.nested.api.stub' => 'Illuminate/Routing/Console/stubs/controller.nested.api.stub', 59 | 'controller.nested.stub' => 'Illuminate/Routing/Console/stubs/controller.nested.stub', 60 | 'controller.plain.stub' => 'Illuminate/Routing/Console/stubs/controller.plain.stub', 61 | 'controller.stub' => 'Illuminate/Routing/Console/stubs/controller.stub', 62 | 'event.stub' => 'Illuminate/Foundation/Console/stubs/event.stub', 63 | 'exception-render-report.stub' => 'Illuminate/Foundation/Console/stubs/exception-render-report.stub', 64 | 'exception-render.stub' => 'Illuminate/Foundation/Console/stubs/exception-render.stub', 65 | 'exception-report.stub' => 'Illuminate/Foundation/Console/stubs/exception-report.stub', 66 | 'exception.stub' => 'Illuminate/Foundation/Console/stubs/exception.stub', 67 | 'factory.stub' => 'Illuminate/Database/Console/Factories/stubs/factory.stub', 68 | 'job.stub' => 'Illuminate/Foundation/Console/stubs/job.stub', 69 | 'job-queued.stub' => 'Illuminate/Foundation/Console/stubs/job-queued.stub', 70 | 'listener-duck.stub' => 'Illuminate/Foundation/Console/stubs/listener-duck.stub', 71 | 'listener-queued-duck.stub' => 'Illuminate/Foundation/Console/stubs/listener-queued-duck.stub', 72 | 'listener-queued.stub' => 'Illuminate/Foundation/Console/stubs/listener-queued.stub', 73 | 'listener.stub' => 'Illuminate/Foundation/Console/stubs/listener.stub', 74 | 'mail.stub' => 'Illuminate/Foundation/Console/stubs/mail.stub', 75 | 'markdown-mail.stub' => 'Illuminate/Foundation/Console/stubs/markdown-mail.stub', 76 | 'markdown-notification.stub' => 'Illuminate/Foundation/Console/stubs/markdown-notification.stub', 77 | 'markdown.stub' => 'Illuminate/Foundation/Console/stubs/markdown.stub', 78 | 'middleware.stub' => 'Illuminate/Routing/Console/stubs/middleware.stub', 79 | 'migration.blank.stub' => 'Illuminate/Database/Migrations/stubs/blank.stub', 80 | 'migration.create.stub' => 'Illuminate/Database/Migrations/stubs/create.stub', 81 | 'migration.update.stub' => 'Illuminate/Database/Migrations/stubs/update.stub', 82 | 'model.stub' => 'Illuminate/Foundation/Console/stubs/model.stub', 83 | 'notification.stub' => 'Illuminate/Foundation/Console/stubs/notification.stub', 84 | 'observer.stub' => 'Illuminate/Foundation/Console/stubs/observer.stub', 85 | 'observer.plain.stub' => 'Illuminate/Foundation/Console/stubs/observer.plain.stub', 86 | 'pivot.model.stub' => 'Illuminate/Foundation/Console/stubs/pivot.model.stub', 87 | 'policy.plain.stub' => 'Illuminate/Foundation/Console/stubs/policy.plain.stub', 88 | 'policy.stub' => 'Illuminate/Foundation/Console/stubs/policy.stub', 89 | 'provider.stub' => 'Illuminate/Foundation/Console/stubs/provider.stub', 90 | 'request.stub' => 'Illuminate/Foundation/Console/stubs/request.stub', 91 | 'resource-collection.stub' => 'Illuminate/Foundation/Console/stubs/resource-collection.stub', 92 | 'resource.stub' => 'Illuminate/Foundation/Console/stubs/resource.stub', 93 | 'rule.stub' => 'Illuminate/Foundation/Console/stubs/rule.stub', 94 | 'seeder.stub' => 'Illuminate/Database/Console/Seeds/stubs/seeder.stub', 95 | 'test.stub' => 'Illuminate/Foundation/Console/stubs/test.stub', 96 | 'unit-test.stub' => 'Illuminate/Foundation/Console/stubs/unit-test.stub', 97 | ]; 98 | 99 | /** 100 | * Create a new command instance. 101 | * 102 | * @param \Illuminate\Filesystem\Filesystem $files 103 | */ 104 | public function __construct(Filesystem $files) 105 | { 106 | parent::__construct(); 107 | 108 | $this->files = $files; 109 | } 110 | 111 | /** 112 | * Execute the console command. 113 | * 114 | * @return void 115 | */ 116 | public function handle() 117 | { 118 | $path = config('stubs.path'); 119 | $this->createDirectory($path); 120 | $publishedCount = 0; 121 | 122 | foreach ($this->stubs as $name => $stub) { 123 | $from = base_path($this->frameworkPath . $stub); 124 | $to = $path . '/' . $name; 125 | $publishedCount += (int)$this->publishFile($from, $to); 126 | } 127 | 128 | if ($publishedCount === 0) { 129 | $this->line('Nothing to publish'); 130 | } 131 | } 132 | 133 | /** 134 | * Create the directory to house the published files if needed. 135 | * 136 | * @param string $directory 137 | * @return void 138 | */ 139 | protected function createDirectory($directory) 140 | { 141 | if (!$this->files->isDirectory($directory)) { 142 | $this->files->makeDirectory($directory, 0755, true); 143 | } 144 | } 145 | 146 | /** 147 | * Publish the file to the given path. 148 | * 149 | * @param string $from 150 | * @param string $to 151 | * @return bool 152 | */ 153 | protected function publishFile($from, $to) 154 | { 155 | if ($this->files->exists($to) || !$this->files->exists($from)) { 156 | return false; 157 | } 158 | 159 | $this->files->copy($from, $to); 160 | $this->info('Stub published: ' . basename($to)); 161 | 162 | return true; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/Console/TestMakeCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Console; 12 | 13 | use Illuminate\Foundation\Console\TestMakeCommand as BaseTestMakeCommand; 14 | 15 | class TestMakeCommand extends BaseTestMakeCommand 16 | { 17 | /** 18 | * Get the stub file for the generator. 19 | * 20 | * @return string 21 | */ 22 | protected function getStub() 23 | { 24 | if ($this->option('unit')) { 25 | $stub = config('stubs.path') . '/unit-test.stub'; 26 | } else { 27 | $stub = config('stubs.path') . '/test.stub'; 28 | } 29 | 30 | return file_exists($stub) ? $stub : parent::getStub(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Database/MigrationCreator.php: -------------------------------------------------------------------------------- 1 | 6 | * @author Daniel Camargo 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace ATehnix\LaravelStubs\Database; 13 | 14 | use Illuminate\Database\Migrations\MigrationCreator as BaseMigrationCreator; 15 | 16 | class MigrationCreator extends BaseMigrationCreator 17 | { 18 | /** 19 | * Get the migration stub file. 20 | * 21 | * @param string $table 22 | * @param bool $create 23 | * @return string 24 | * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException 25 | */ 26 | protected function getStub($table, $create) 27 | { 28 | if (is_null($table)) { 29 | $stub = config('stubs.path') . '/migration.blank.stub'; 30 | } else { 31 | $stub = $create 32 | ? config('stubs.path') . '/migration.create.stub' 33 | : config('stubs.path') . '/migration.update.stub'; 34 | } 35 | 36 | return file_exists($stub) ? $this->files->get($stub) : parent::getStub($table, $create); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Providers/ArtisanServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Providers; 12 | 13 | use ATehnix\LaravelStubs\Console\ChannelMakeCommand; 14 | use ATehnix\LaravelStubs\Console\ConsoleMakeCommand; 15 | use ATehnix\LaravelStubs\Console\ControllerMakeCommand; 16 | use ATehnix\LaravelStubs\Console\EventMakeCommand; 17 | use ATehnix\LaravelStubs\Console\ExceptionMakeCommand; 18 | use ATehnix\LaravelStubs\Console\FactoryMakeCommand; 19 | use ATehnix\LaravelStubs\Console\JobMakeCommand; 20 | use ATehnix\LaravelStubs\Console\ListenerMakeCommand; 21 | use ATehnix\LaravelStubs\Console\MailMakeCommand; 22 | use ATehnix\LaravelStubs\Console\MiddlewareMakeCommand; 23 | use ATehnix\LaravelStubs\Console\ModelMakeCommand; 24 | use ATehnix\LaravelStubs\Console\NotificationMakeCommand; 25 | use ATehnix\LaravelStubs\Console\ObserverMakeCommand; 26 | use ATehnix\LaravelStubs\Console\PolicyMakeCommand; 27 | use ATehnix\LaravelStubs\Console\ProviderMakeCommand; 28 | use ATehnix\LaravelStubs\Console\RequestMakeCommand; 29 | use ATehnix\LaravelStubs\Console\ResourceMakeCommand; 30 | use ATehnix\LaravelStubs\Console\RuleMakeCommand; 31 | use ATehnix\LaravelStubs\Console\SeederMakeCommand; 32 | use ATehnix\LaravelStubs\Console\StubsPublishCommand; 33 | use ATehnix\LaravelStubs\Console\TestMakeCommand; 34 | use Illuminate\Foundation\Providers\ArtisanServiceProvider as BaseServiceProvider; 35 | 36 | class ArtisanServiceProvider extends BaseServiceProvider 37 | { 38 | /** 39 | * Bootstrapping the service provider. 40 | * 41 | * @return void 42 | */ 43 | public function boot() 44 | { 45 | $this->commands(StubsPublishCommand::class); 46 | } 47 | 48 | /** 49 | * Register the command. 50 | * 51 | * @return void 52 | */ 53 | protected function registerChannelMakeCommand() 54 | { 55 | $this->app->singleton('command.channel.make', function ($app) { 56 | return new ChannelMakeCommand($app['files']); 57 | }); 58 | } 59 | 60 | /** 61 | * Register the command. 62 | * 63 | * @return void 64 | */ 65 | protected function registerConsoleMakeCommand() 66 | { 67 | $this->app->singleton('command.console.make', function ($app) { 68 | return new ConsoleMakeCommand($app['files']); 69 | }); 70 | } 71 | 72 | /** 73 | * Register the command. 74 | * 75 | * @return void 76 | */ 77 | protected function registerControllerMakeCommand() 78 | { 79 | $this->app->singleton('command.controller.make', function ($app) { 80 | return new ControllerMakeCommand($app['files']); 81 | }); 82 | } 83 | 84 | /** 85 | * Register the command. 86 | * 87 | * @return void 88 | */ 89 | protected function registerEventMakeCommand() 90 | { 91 | $this->app->singleton('command.event.make', function ($app) { 92 | return new EventMakeCommand($app['files']); 93 | }); 94 | } 95 | 96 | /** 97 | * Register the command. 98 | * 99 | * @return void 100 | */ 101 | protected function registerExceptionMakeCommand() 102 | { 103 | $this->app->singleton('command.exception.make', function ($app) { 104 | return new ExceptionMakeCommand($app['files']); 105 | }); 106 | } 107 | 108 | /** 109 | * Register the command. 110 | * 111 | * @return void 112 | */ 113 | protected function registerFactoryMakeCommand() 114 | { 115 | $this->app->singleton('command.factory.make', function ($app) { 116 | return new FactoryMakeCommand($app['files']); 117 | }); 118 | } 119 | 120 | /** 121 | * Register the command. 122 | * 123 | * @return void 124 | */ 125 | protected function registerJobMakeCommand() 126 | { 127 | $this->app->singleton('command.job.make', function ($app) { 128 | return new JobMakeCommand($app['files']); 129 | }); 130 | } 131 | 132 | /** 133 | * Register the command. 134 | * 135 | * @return void 136 | */ 137 | protected function registerListenerMakeCommand() 138 | { 139 | $this->app->singleton('command.listener.make', function ($app) { 140 | return new ListenerMakeCommand($app['files']); 141 | }); 142 | } 143 | 144 | /** 145 | * Register the command. 146 | * 147 | * @return void 148 | */ 149 | protected function registerMailMakeCommand() 150 | { 151 | $this->app->singleton('command.mail.make', function ($app) { 152 | return new MailMakeCommand($app['files']); 153 | }); 154 | } 155 | 156 | /** 157 | * Register the command. 158 | * 159 | * @return void 160 | */ 161 | protected function registerMiddlewareMakeCommand() 162 | { 163 | $this->app->singleton('command.middleware.make', function ($app) { 164 | return new MiddlewareMakeCommand($app['files']); 165 | }); 166 | } 167 | 168 | /** 169 | * Register the command. 170 | * 171 | * @return void 172 | */ 173 | protected function registerModelMakeCommand() 174 | { 175 | $this->app->singleton('command.model.make', function ($app) { 176 | return new ModelMakeCommand($app['files']); 177 | }); 178 | } 179 | 180 | /** 181 | * Register the command. 182 | * 183 | * @return void 184 | */ 185 | protected function registerNotificationMakeCommand() 186 | { 187 | $this->app->singleton('command.notification.make', function ($app) { 188 | return new NotificationMakeCommand($app['files']); 189 | }); 190 | } 191 | 192 | /** 193 | * Register the command. 194 | * 195 | * @return void 196 | */ 197 | protected function registerObserverMakeCommand() 198 | { 199 | $this->app->singleton('command.observer.make', function ($app) { 200 | return new ObserverMakeCommand($app['files']); 201 | }); 202 | } 203 | 204 | /** 205 | * Register the command. 206 | * 207 | * @return void 208 | */ 209 | protected function registerProviderMakeCommand() 210 | { 211 | $this->app->singleton('command.provider.make', function ($app) { 212 | return new ProviderMakeCommand($app['files']); 213 | }); 214 | } 215 | 216 | /** 217 | * Register the command. 218 | * 219 | * @return void 220 | */ 221 | protected function registerRequestMakeCommand() 222 | { 223 | $this->app->singleton('command.request.make', function ($app) { 224 | return new RequestMakeCommand($app['files']); 225 | }); 226 | } 227 | 228 | /** 229 | * Register the command. 230 | * 231 | * @return void 232 | */ 233 | protected function registerResourceMakeCommand() 234 | { 235 | $this->app->singleton('command.resource.make', function ($app) { 236 | return new ResourceMakeCommand($app['files']); 237 | }); 238 | } 239 | 240 | /** 241 | * Register the command. 242 | * 243 | * @return void 244 | */ 245 | protected function registerRuleMakeCommand() 246 | { 247 | $this->app->singleton('command.rule.make', function ($app) { 248 | return new RuleMakeCommand($app['files']); 249 | }); 250 | } 251 | 252 | /** 253 | * Register the command. 254 | * 255 | * @return void 256 | */ 257 | protected function registerSeederMakeCommand() 258 | { 259 | $this->app->singleton('command.seeder.make', function ($app) { 260 | return new SeederMakeCommand($app['files'], $app['composer']); 261 | }); 262 | } 263 | 264 | /** 265 | * Register the command. 266 | * 267 | * @return void 268 | */ 269 | protected function registerTestMakeCommand() 270 | { 271 | $this->app->singleton('command.test.make', function ($app) { 272 | return new TestMakeCommand($app['files']); 273 | }); 274 | } 275 | 276 | /** 277 | * Register the command. 278 | * 279 | * @return void 280 | */ 281 | protected function registerPolicyMakeCommand() 282 | { 283 | $this->app->singleton('command.policy.make', function ($app) { 284 | return new PolicyMakeCommand($app['files']); 285 | }); 286 | } 287 | } 288 | -------------------------------------------------------------------------------- /src/Providers/ConsoleSupportServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Providers; 12 | 13 | use Illuminate\Foundation\Providers\ComposerServiceProvider; 14 | use Illuminate\Foundation\Providers\ConsoleSupportServiceProvider as BaseServiceProvider; 15 | 16 | class ConsoleSupportServiceProvider extends BaseServiceProvider 17 | { 18 | /** 19 | * The provider class names. 20 | * 21 | * @var array 22 | */ 23 | protected $providers = [ 24 | ArtisanServiceProvider::class, 25 | MigrationServiceProvider::class, 26 | ComposerServiceProvider::class, 27 | ]; 28 | 29 | /** 30 | * Path to the config file 31 | * 32 | * @var string 33 | */ 34 | protected $configPath = __DIR__ . '/../../publish/config/stubs.php'; 35 | 36 | /** 37 | * Register the service provider. 38 | * 39 | * @return void 40 | */ 41 | public function register() 42 | { 43 | $this->mergeConfigFrom($this->configPath, 'stubs'); 44 | 45 | parent::register(); 46 | } 47 | 48 | /** 49 | * Bootstrapping the service provider. 50 | * 51 | * @return void 52 | */ 53 | public function boot() 54 | { 55 | $this->publishes([ 56 | $this->configPath => config_path('stubs.php'), 57 | ], 'config'); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Providers/MigrationServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | namespace ATehnix\LaravelStubs\Providers; 12 | 13 | use ATehnix\LaravelStubs\Database\MigrationCreator; 14 | use Illuminate\Database\MigrationServiceProvider as BaseServiceProvider; 15 | 16 | class MigrationServiceProvider extends BaseServiceProvider 17 | { 18 | /** 19 | * Register the migration creator. 20 | * 21 | * @return void 22 | */ 23 | protected function registerCreator() 24 | { 25 | $this->app->singleton('migration.creator', function ($app) { 26 | return new MigrationCreator($app['files']); 27 | }); 28 | } 29 | } 30 | --------------------------------------------------------------------------------