MakeServiceCommand.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. class MakeServiceCommand extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'make:service {name : fileName}';
  12. /**
  13. * The console command description.
  14. *
  15. * @var string
  16. */
  17. protected $description = 'Create Service file';
  18. /**
  19. * Create a new command instance.
  20. *
  21. * @return void
  22. */
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. }
  27. /**
  28. * Execute the console command.
  29. *
  30. * @return void
  31. */
  32. public function handle()
  33. {
  34. if (!file_exists(base_path('app\\Services'))){
  35. mkdir('app\\Services',666,false);
  36. }
  37. $fileName=$this->argument('name');
  38. if (!file_exists(base_path('app\\Services\\'.$fileName.'.php'))){
  39. file_put_contents(base_path('app\\Services\\'.$fileName.'.php'),
  40. '<?php '.PHP_EOL.PHP_EOL.'namespace App\Services; '.PHP_EOL.PHP_EOL.'Class '.$fileName.PHP_EOL.'{ '.PHP_EOL.PHP_EOL.PHP_EOL.'}');
  41. }
  42. else echo $this->error("ERROR: file exists;");
  43. }
  44. }