Created
May 26, 2019 11:47
-
-
Save DaaGER/364e4c40a047c2f91262590cf5c7a5ca to your computer and use it in GitHub Desktop.
Catching artisan commands/Перехват команд артисан
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
//config/app.php | |
//change provider | |
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class | |
=> | |
App\Providers\ConsoleSupportServiceProvider::class, |
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
//app/Providers/ArtisanServiceProvider.php | |
<?php | |
namespace App\Providers; | |
use App\Providers\Command\ControllerMakeCommand; | |
class ArtisanServiceProvider extends \Illuminate\Foundation\Providers\ArtisanServiceProvider | |
{ | |
protected function registerControllerMakeCommand() | |
{ | |
$this->app->singleton('command.controller.make', function ($app) { | |
return new ControllerMakeCommand($app['files']); | |
}); | |
} | |
} |
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
//app/Providers/ConsoleSupportServiceProvider.php | |
<?php | |
namespace App\Providers; | |
use Illuminate\Database\MigrationServiceProvider; | |
use Illuminate\Foundation\Providers\ComposerServiceProvider; | |
use Illuminate\Support\AggregateServiceProvider; | |
class ConsoleSupportServiceProvider extends AggregateServiceProvider | |
{ | |
/** | |
* The provider class names. | |
* | |
* @var array | |
*/ | |
protected $providers = [ | |
ArtisanServiceProvider::class, | |
MigrationServiceProvider::class, | |
ComposerServiceProvider::class, | |
]; | |
} |
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
//app/Providers/Command/ControllerMakeCommand.php | |
<?php | |
namespace App\Providers\Command; | |
class ControllerMakeCommand extends \Illuminate\Routing\Console\ControllerMakeCommand | |
{ | |
public function handle() | |
{ | |
$word="Controller"; | |
$name=substr($this->getNameInput(),-strlen($word)); | |
if($name!==$word){ | |
$this->error("Название контроллера {$this->getNameInput()} должно заканчиваться на $word"); | |
return false; | |
} | |
return parent::handle(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment