This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
atehnix
committed
Oct 19, 2016
0 parents
commit 44aee37
Showing
21 changed files
with
1,065 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Andrey Sosnov aka ATehnix <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Override Laravel stubs | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) | ||
[![Packagist Version](https://img.shields.io/packagist/v/atehnix/laravel-stubs.svg)](https://packagist.org/packages/atehnix/laravel-stubs) | ||
|
||
The package gives you the opportunity to customize Artisan commands like `artisan make:model`, `artisan make:controller` and other, just as you need. | ||
|
||
Any location of the generated classes and with any content. | ||
|
||
## Installation | ||
|
||
You can get library through [composer](https://getcomposer.org/) | ||
|
||
``` | ||
composer require atehnix/laravel-stubs | ||
``` | ||
|
||
Next up, the service provider | ||
`Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,` | ||
|
||
should be replaced by | ||
`ATehnix\LaravelStubs\Providers\ConsoleSupportServiceProvider::class,` | ||
|
||
```php | ||
// config/app.php | ||
|
||
'providers' => [ | ||
... | ||
// Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, | ||
ATehnix\LaravelStubs\Providers\ConsoleSupportServiceProvider::class, | ||
... | ||
]; | ||
``` | ||
|
||
To publish the config file to app/config/stubs.php run: | ||
|
||
``` | ||
php artisan vendor:publish --provider=ATehnix\LaravelStubs\Providers\ConsoleSupportServiceProvider | ||
``` | ||
|
||
Done! | ||
|
||
|
||
## Usage | ||
|
||
### Publish stub files for edit | ||
``` | ||
php artisan stubs:publish | ||
``` | ||
|
||
The files will be placed in the directory `resources/stubs` (or other directory if you change it in the configuration file). | ||
|
||
Now you can edit any of the stubs and enjoy your customized commands like `artisan make:model`,` artisan make:controller` and others. | ||
|
||
|
||
## License | ||
[MIT](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "atehnix/laravel-stubs", | ||
"description": "Override default stubs", | ||
"keywords": [ | ||
"laravel", | ||
"stub", | ||
"make", | ||
"generator" | ||
], | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Andrey Sosnov", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.6.4", | ||
"laravel/framework": "5.3.*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Path to the stub files for the generator | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
'path' => base_path('resources/stubs'), | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default namespaces for the classes | ||
|-------------------------------------------------------------------------- | ||
| Root application namespaсe (like "App") should be skipped. | ||
*/ | ||
'namespaces' => [ | ||
'console' => '\Console\Commands', | ||
'controller' => '\Http\Controllers', | ||
'event' => '\Events', | ||
'job' => '\Jobs', | ||
'listener' => '\Listeners', | ||
'mail' => '\Mail', | ||
'middleware' => '\Http\Middleware', | ||
'model' => '\Models', | ||
'notification' => '\Notifications', | ||
'policy' => '\Policies', | ||
'provider' => '\Providers', | ||
'request' => '\Http\Requests', | ||
], | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* This file is part of laravel-stubs package. | ||
* | ||
* @author ATehnix <atehnix@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace ATehnix\LaravelStubs\Console; | ||
|
||
use Illuminate\Foundation\Console\ConsoleMakeCommand as BaseConsoleMakeCommand; | ||
|
||
class ConsoleMakeCommand extends BaseConsoleMakeCommand | ||
{ | ||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
$stub = config('stubs.path').'/console.stub'; | ||
|
||
return file_exists($stub) ? $stub : parent::getStub(); | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.config('stubs.namespaces.console'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* This file is part of laravel-stubs package. | ||
* | ||
* @author ATehnix <atehnix@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace ATehnix\LaravelStubs\Console; | ||
|
||
use Illuminate\Routing\Console\ControllerMakeCommand as BaseControllerMakeCommand; | ||
|
||
class ControllerMakeCommand extends BaseControllerMakeCommand | ||
{ | ||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
if ($this->option('resource')) { | ||
$stub = config('stubs.path').'/controller.stub'; | ||
} else { | ||
$stub = config('stubs.path').'/controller.plain.stub'; | ||
} | ||
|
||
return file_exists($stub) ? $stub : parent::getStub(); | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.config('stubs.namespaces.controller'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* This file is part of laravel-stubs package. | ||
* | ||
* @author ATehnix <atehnix@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace ATehnix\LaravelStubs\Console; | ||
|
||
use Illuminate\Foundation\Console\EventMakeCommand as BaseEventMakeCommand; | ||
|
||
class EventMakeCommand extends BaseEventMakeCommand | ||
{ | ||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
$stub = config('stubs.path').'/event.stub'; | ||
|
||
return file_exists($stub) ? $stub : parent::getStub(); | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.config('stubs.namespaces.event'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* This file is part of laravel-stubs package. | ||
* | ||
* @author ATehnix <atehnix@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace ATehnix\LaravelStubs\Console; | ||
|
||
use Illuminate\Foundation\Console\JobMakeCommand as BaseJobMakeCommand; | ||
|
||
class JobMakeCommand extends BaseJobMakeCommand | ||
{ | ||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
if ($this->option('sync')) { | ||
$stub = config('stubs.path').'/job.stub'; | ||
} else { | ||
$stub = config('stubs.path').'/job-queued.stub'; | ||
} | ||
|
||
return file_exists($stub) ? $stub : parent::getStub(); | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.config('stubs.namespaces.job'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* This file is part of laravel-stubs package. | ||
* | ||
* @author ATehnix <atehnix@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace ATehnix\LaravelStubs\Console; | ||
|
||
use Illuminate\Foundation\Console\ListenerMakeCommand as BaseListenerMakeCommand; | ||
use Illuminate\Support\Str; | ||
|
||
class ListenerMakeCommand extends BaseListenerMakeCommand | ||
{ | ||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
if ($this->option('queued')) { | ||
$stub = config('stubs.path').'/listener-queued.stub'; | ||
} else { | ||
$stub = config('stubs.path').'/listener.stub'; | ||
} | ||
|
||
return file_exists($stub) ? $stub : parent::getStub(); | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.config('stubs.namespaces.listener'); | ||
} | ||
|
||
protected function buildClass($name) | ||
{ | ||
$stub = $this->files->get($this->getStub()); | ||
$stub = $this->replaceNamespace($stub, $name)->replaceClass($stub, $name); | ||
$event = $this->getEvent(); | ||
$stub = str_replace('DummyEvent', class_basename($event), $stub); | ||
$stub = str_replace('DummyFullEvent', $event, $stub); | ||
|
||
return $stub; | ||
} | ||
|
||
protected function getEvent() | ||
{ | ||
$event = $this->option('event'); | ||
|
||
if (! Str::startsWith($event, $this->laravel->getNamespace()) && ! Str::startsWith($event, 'Illuminate')) { | ||
$eventNamespace = ltrim(config('stubs.namespaces.event'), '\\').'\\'; | ||
$event = $this->laravel->getNamespace().$eventNamespace.$event; | ||
} | ||
|
||
return $event; | ||
} | ||
} |
Oops, something went wrong.