itstructure /
laravel-rbac
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Itstructure\LaRbac\Commands; |
||
| 4 | |||
| 5 | use Illuminate\Console\Command; |
||
| 6 | use Symfony\Component\Process\Process; |
||
| 7 | use Itstructure\LaRbac\RbacServiceProvider; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Class PublishCommand |
||
| 11 | * |
||
| 12 | * @package Itstructure\LaRbac\Commands |
||
| 13 | * |
||
| 14 | * @author Andrey Girnik <[email protected]> |
||
| 15 | */ |
||
| 16 | class PublishCommand extends Command |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * The name and signature of the console command. |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $signature = 'rbac:publish '. |
||
| 23 | '{--force : Overwrite existing files by default.}'. |
||
| 24 | '{--only= : Publish only specific part. Available parts: config, views, lang, migrations, seeders.}'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The console command description. |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $description = 'Publish the RBAC package parts.'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Execute the console command. |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | public function handle() |
||
| 37 | { |
||
| 38 | $this->info('Starting publication process of RBAC package parts...'); |
||
| 39 | |||
| 40 | $callArguments = ['--provider' => RbacServiceProvider::class]; |
||
| 41 | |||
| 42 | $dumpAutoload = false; |
||
| 43 | |||
| 44 | if ($this->option('only')) { |
||
| 45 | switch ($this->option('only')) { |
||
| 46 | case 'config': |
||
| 47 | $this->info('Publish just a part: config.'); |
||
| 48 | $callArguments['--tag'] = 'config'; |
||
| 49 | break; |
||
| 50 | |||
| 51 | case 'views': |
||
| 52 | $this->info('Publish just a part: views.'); |
||
| 53 | $callArguments['--tag'] = 'views'; |
||
| 54 | break; |
||
| 55 | |||
| 56 | case 'lang': |
||
| 57 | $this->info('Publish just a part: lang.'); |
||
| 58 | $callArguments['--tag'] = 'lang'; |
||
| 59 | break; |
||
| 60 | |||
| 61 | case 'migrations': |
||
| 62 | $this->info('Publish just a part: migrations.'); |
||
| 63 | $callArguments['--tag'] = 'migrations'; |
||
| 64 | $dumpAutoload = true; |
||
| 65 | break; |
||
| 66 | |||
| 67 | case 'seeders': |
||
| 68 | $this->info('Publish just a part: seeders.'); |
||
| 69 | $callArguments['--tag'] = 'seeders'; |
||
| 70 | $dumpAutoload = true; |
||
| 71 | break; |
||
| 72 | |||
| 73 | default: |
||
| 74 | $this->error('Invalid "only" argument value!'); |
||
| 75 | return; |
||
| 76 | break; |
||
|
0 ignored issues
–
show
|
|||
| 77 | } |
||
| 78 | |||
| 79 | } else { |
||
| 80 | $this->info('Publish all parts: config, views, lang, migrations, seeders.'); |
||
| 81 | $dumpAutoload = true; |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($this->option('force')) { |
||
| 85 | $this->warn('Force publishing.'); |
||
| 86 | $callArguments['--force'] = true; |
||
| 87 | } |
||
| 88 | |||
| 89 | $this->call('vendor:publish', $callArguments); |
||
| 90 | |||
| 91 | if ($dumpAutoload) { |
||
| 92 | $this->info('Dumping the autoloaded files and reloading all new files.'); |
||
| 93 | $composer = $this->findComposer(); |
||
| 94 | $process = Process::fromShellCommandline($composer.' dump-autoload -o'); |
||
| 95 | $process->setTimeout(null); |
||
| 96 | $process->setWorkingDirectory(base_path())->run(); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Get the composer command for the environment. |
||
| 102 | * @return string |
||
| 103 | */ |
||
| 104 | private function findComposer() |
||
| 105 | { |
||
| 106 | if (file_exists(getcwd().'/composer.phar')) { |
||
| 107 | return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
||
| 108 | } |
||
| 109 | |||
| 110 | return 'composer'; |
||
| 111 | } |
||
| 112 | } |
||
| 113 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.