EntityCommand.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Collection;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputOption;
  7. /**
  8. * Class EntityCommand
  9. * @package Prettus\Repository\Generators\Commands
  10. * @author Anderson Andrade <contato@andersonandra.de>
  11. */
  12. class EntityCommand extends Command
  13. {
  14. /**
  15. * The name of command.
  16. *
  17. * @var string
  18. */
  19. protected $name = 'make:entity';
  20. /**
  21. * The description of command.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'Create a new entity.';
  26. /**
  27. * @var Collection
  28. */
  29. protected $generators = null;
  30. /**
  31. * Execute the command.
  32. *
  33. * @return void
  34. * @see fire()
  35. */
  36. public function handle()
  37. {
  38. $this->laravel->call([$this, 'fire'], func_get_args());
  39. }
  40. /**
  41. * Execute the command.
  42. *
  43. * @return void
  44. */
  45. public function fire()
  46. {
  47. if ($this->confirm('Would you like to create a Presenter? [y|N]')) {
  48. $this->call('make:presenter', [
  49. 'name' => $this->argument('name'),
  50. '--force' => $this->option('force'),
  51. ]);
  52. }
  53. $validator = $this->option('validator');
  54. if (is_null($validator) && $this->confirm('Would you like to create a Validator? [y|N]')) {
  55. $validator = 'yes';
  56. }
  57. if ($validator == 'yes') {
  58. $this->call('make:validator', [
  59. 'name' => $this->argument('name'),
  60. '--rules' => $this->option('rules'),
  61. '--force' => $this->option('force'),
  62. ]);
  63. }
  64. if ($this->confirm('Would you like to create a Controller? [y|N]')) {
  65. $resource_args = [
  66. 'name' => $this->argument('name')
  67. ];
  68. // Generate a controller resource
  69. $controller_command = ((float)app()->version() >= 5.5 ? 'make:rest-controller' : 'make:resource');
  70. $this->call($controller_command, $resource_args);
  71. }
  72. $this->call('make:repository', [
  73. 'name' => $this->argument('name'),
  74. '--fillable' => $this->option('fillable'),
  75. '--rules' => $this->option('rules'),
  76. '--validator' => $validator,
  77. '--force' => $this->option('force')
  78. ]);
  79. $this->call('make:bindings', [
  80. 'name' => $this->argument('name'),
  81. '--force' => $this->option('force')
  82. ]);
  83. $this->call('make:criteria', [
  84. 'name' => $this->argument('name'),
  85. '--force' => $this->option('force')
  86. ]);
  87. }
  88. /**
  89. * The array of command arguments.
  90. *
  91. * @return array
  92. */
  93. public function getArguments()
  94. {
  95. return [
  96. [
  97. 'name',
  98. InputArgument::REQUIRED,
  99. 'The name of class being generated.',
  100. null
  101. ],
  102. ];
  103. }
  104. /**
  105. * The array of command options.
  106. *
  107. * @return array
  108. */
  109. public function getOptions()
  110. {
  111. return [
  112. [
  113. 'fillable',
  114. null,
  115. InputOption::VALUE_OPTIONAL,
  116. 'The fillable attributes.',
  117. null
  118. ],
  119. [
  120. 'rules',
  121. null,
  122. InputOption::VALUE_OPTIONAL,
  123. 'The rules of validation attributes.',
  124. null
  125. ],
  126. [
  127. 'validator',
  128. null,
  129. InputOption::VALUE_OPTIONAL,
  130. 'Adds validator reference to the repository.',
  131. null
  132. ],
  133. [
  134. 'force',
  135. 'f',
  136. InputOption::VALUE_NONE,
  137. 'Force the creation if file already exists.',
  138. null
  139. ]
  140. ];
  141. }
  142. }