CriteriaCommand.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Prettus\Repository\Generators\CriteriaGenerator;
  5. use Prettus\Repository\Generators\FileAlreadyExistsException;
  6. use Symfony\Component\Console\Input\InputArgument;
  7. use Symfony\Component\Console\Input\InputOption;
  8. /**
  9. * Class CriteriaCommand
  10. * @package Prettus\Repository\Generators\Commands
  11. * @author Anderson Andrade <contato@andersonandra.de>
  12. */
  13. class CriteriaCommand extends Command
  14. {
  15. /**
  16. * The name of command.
  17. *
  18. * @var string
  19. */
  20. protected $name = 'make:criteria';
  21. /**
  22. * The description of command.
  23. *
  24. * @var string
  25. */
  26. protected $description = 'Create a new criteria.';
  27. /**
  28. * The type of class being generated.
  29. *
  30. * @var string
  31. */
  32. protected $type = 'Criteria';
  33. /**
  34. * Execute the command.
  35. *
  36. * @return void
  37. * @see fire()
  38. */
  39. public function handle()
  40. {
  41. $this->laravel->call([$this, 'fire'], func_get_args());
  42. }
  43. /**
  44. * Execute the command.
  45. *
  46. * @return void
  47. */
  48. public function fire()
  49. {
  50. try {
  51. (new CriteriaGenerator([
  52. 'name' => $this->argument('name'),
  53. 'force' => $this->option('force'),
  54. ]))->run();
  55. $this->info("Criteria created successfully.");
  56. } catch (FileAlreadyExistsException $ex) {
  57. $this->error($this->type . ' already exists!');
  58. return false;
  59. }
  60. }
  61. /**
  62. * The array of command arguments.
  63. *
  64. * @return array
  65. */
  66. public function getArguments()
  67. {
  68. return [
  69. [
  70. 'name',
  71. InputArgument::REQUIRED,
  72. 'The name of class being generated.',
  73. null
  74. ],
  75. ];
  76. }
  77. /**
  78. * The array of command options.
  79. *
  80. * @return array
  81. */
  82. public function getOptions()
  83. {
  84. return [
  85. [
  86. 'force',
  87. 'f',
  88. InputOption::VALUE_NONE,
  89. 'Force the creation if file already exists.',
  90. null
  91. ],
  92. ];
  93. }
  94. }