Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Commit 44aee37

Browse files
author
atehnix
committed
init
0 parents  commit 44aee37

21 files changed

+1065
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Andrey Sosnov aka ATehnix <atehnix@gmail.com>
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.

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Override Laravel stubs
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)](https://packagist.org/packages/atehnix/laravel-stubs)
4+
5+
The package gives you the opportunity to customize Artisan commands like `artisan make:model`, `artisan make:controller` and other, just as you need.
6+
7+
Any location of the generated classes and with any content.
8+
9+
## Installation
10+
11+
You can get library through [composer](https://getcomposer.org/)
12+
13+
```
14+
composer require atehnix/laravel-stubs
15+
```
16+
17+
Next up, the service provider
18+
`Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,`
19+
20+
should be replaced by
21+
`ATehnix\LaravelStubs\Providers\ConsoleSupportServiceProvider::class,`
22+
23+
```php
24+
// config/app.php
25+
26+
'providers' => [
27+
...
28+
// Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
29+
ATehnix\LaravelStubs\Providers\ConsoleSupportServiceProvider::class,
30+
...
31+
];
32+
```
33+
34+
To publish the config file to app/config/stubs.php run:
35+
36+
```
37+
php artisan vendor:publish --provider=ATehnix\LaravelStubs\Providers\ConsoleSupportServiceProvider
38+
```
39+
40+
Done!
41+
42+
43+
## Usage
44+
45+
### Publish stub files for edit
46+
```
47+
php artisan stubs:publish
48+
```
49+
50+
The files will be placed in the directory `resources/stubs` (or other directory if you change it in the configuration file).
51+
52+
Now you can edit any of the stubs and enjoy your customized commands like `artisan make:model`,` artisan make:controller` and others.
53+
54+
55+
## License
56+
[MIT](LICENSE)

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "atehnix/laravel-stubs",
3+
"description": "Override default stubs",
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": ">=5.6.4",
20+
"laravel/framework": "5.3.*"
21+
}
22+
}

publish/config/stubs.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Path to the stub files for the generator
8+
|--------------------------------------------------------------------------
9+
*/
10+
'path' => base_path('resources/stubs'),
11+
12+
/*
13+
|--------------------------------------------------------------------------
14+
| Default namespaces for the classes
15+
|--------------------------------------------------------------------------
16+
| Root application namespaсe (like "App") should be skipped.
17+
*/
18+
'namespaces' => [
19+
'console' => '\Console\Commands',
20+
'controller' => '\Http\Controllers',
21+
'event' => '\Events',
22+
'job' => '\Jobs',
23+
'listener' => '\Listeners',
24+
'mail' => '\Mail',
25+
'middleware' => '\Http\Middleware',
26+
'model' => '\Models',
27+
'notification' => '\Notifications',
28+
'policy' => '\Policies',
29+
'provider' => '\Providers',
30+
'request' => '\Http\Requests',
31+
],
32+
33+
];

src/Console/ConsoleMakeCommand.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\ConsoleMakeCommand as BaseConsoleMakeCommand;
13+
14+
class ConsoleMakeCommand extends BaseConsoleMakeCommand
15+
{
16+
/**
17+
* Get the stub file for the generator.
18+
*
19+
* @return string
20+
*/
21+
protected function getStub()
22+
{
23+
$stub = config('stubs.path').'/console.stub';
24+
25+
return file_exists($stub) ? $stub : parent::getStub();
26+
}
27+
28+
/**
29+
* Get the default namespace for the class.
30+
*
31+
* @param string $rootNamespace
32+
* @return string
33+
*/
34+
protected function getDefaultNamespace($rootNamespace)
35+
{
36+
return $rootNamespace.config('stubs.namespaces.console');
37+
}
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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\Routing\Console\ControllerMakeCommand as BaseControllerMakeCommand;
13+
14+
class ControllerMakeCommand extends BaseControllerMakeCommand
15+
{
16+
/**
17+
* Get the stub file for the generator.
18+
*
19+
* @return string
20+
*/
21+
protected function getStub()
22+
{
23+
if ($this->option('resource')) {
24+
$stub = config('stubs.path').'/controller.stub';
25+
} else {
26+
$stub = config('stubs.path').'/controller.plain.stub';
27+
}
28+
29+
return file_exists($stub) ? $stub : parent::getStub();
30+
}
31+
32+
/**
33+
* Get the default namespace for the class.
34+
*
35+
* @param string $rootNamespace
36+
* @return string
37+
*/
38+
protected function getDefaultNamespace($rootNamespace)
39+
{
40+
return $rootNamespace.config('stubs.namespaces.controller');
41+
}
42+
}

src/Console/EventMakeCommand.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\EventMakeCommand as BaseEventMakeCommand;
13+
14+
class EventMakeCommand extends BaseEventMakeCommand
15+
{
16+
/**
17+
* Get the stub file for the generator.
18+
*
19+
* @return string
20+
*/
21+
protected function getStub()
22+
{
23+
$stub = config('stubs.path').'/event.stub';
24+
25+
return file_exists($stub) ? $stub : parent::getStub();
26+
}
27+
28+
/**
29+
* Get the default namespace for the class.
30+
*
31+
* @param string $rootNamespace
32+
* @return string
33+
*/
34+
protected function getDefaultNamespace($rootNamespace)
35+
{
36+
return $rootNamespace.config('stubs.namespaces.event');
37+
}
38+
}

src/Console/JobMakeCommand.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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\JobMakeCommand as BaseJobMakeCommand;
13+
14+
class JobMakeCommand extends BaseJobMakeCommand
15+
{
16+
/**
17+
* Get the stub file for the generator.
18+
*
19+
* @return string
20+
*/
21+
protected function getStub()
22+
{
23+
if ($this->option('sync')) {
24+
$stub = config('stubs.path').'/job.stub';
25+
} else {
26+
$stub = config('stubs.path').'/job-queued.stub';
27+
}
28+
29+
return file_exists($stub) ? $stub : parent::getStub();
30+
}
31+
32+
/**
33+
* Get the default namespace for the class.
34+
*
35+
* @param string $rootNamespace
36+
* @return string
37+
*/
38+
protected function getDefaultNamespace($rootNamespace)
39+
{
40+
return $rootNamespace.config('stubs.namespaces.job');
41+
}
42+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)