Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

169 Zeilen
5.4 KiB

  1. <?php
  2. namespace Grav\Plugin\Console;
  3. use Symfony\Component\Console\Input\InputOption;
  4. use Symfony\Component\Console\Question\ChoiceQuestion;
  5. use Symfony\Component\Console\Question\Question;
  6. require_once(__DIR__ . '/../classes/DevToolsCommand.php');
  7. /**
  8. * Class NewPluginCommand
  9. * @package Grav\Console\Cli\DevTools
  10. */
  11. class NewPluginCommand extends DevToolsCommand
  12. {
  13. /**
  14. * @return void
  15. */
  16. protected function configure(): void
  17. {
  18. $this
  19. ->setName('new-plugin')
  20. ->setAliases(['newplugin'])
  21. ->addOption(
  22. 'name',
  23. null,
  24. InputOption::VALUE_OPTIONAL,
  25. 'The name of your new Grav plugin'
  26. )
  27. ->addOption(
  28. 'desc',
  29. null,
  30. InputOption::VALUE_OPTIONAL,
  31. 'A description of your new Grav plugin'
  32. )
  33. ->addOption(
  34. 'dev',
  35. null,
  36. InputOption::VALUE_OPTIONAL,
  37. 'The name/username of the developer'
  38. )
  39. ->addOption(
  40. 'github',
  41. null,
  42. InputOption::VALUE_OPTIONAL,
  43. 'The developer\'s GitHub ID'
  44. )
  45. ->addOption(
  46. 'email',
  47. 'e',
  48. InputOption::VALUE_OPTIONAL,
  49. 'The developer\'s email'
  50. )
  51. ->addOption(
  52. 'offline',
  53. 'o',
  54. InputOption::VALUE_NONE,
  55. 'Skip online name collision check'
  56. )
  57. ->setDescription('Creates a new Grav plugin with the basic required files')
  58. ->setHelp('The <info>new-plugin</info> command creates a new Grav instance and performs the creation of a plugin.');
  59. }
  60. /**
  61. * @return int
  62. */
  63. protected function serve(): int
  64. {
  65. $this->init();
  66. $input = $this->getInput();
  67. $io = $this->getIO();
  68. $this->component['type'] = 'plugin';
  69. $this->component['template'] = 'blank';
  70. $this->component['version'] = '0.1.0';
  71. $this->options = [
  72. 'name' => $input->getOption('name'),
  73. 'description' => $input->getOption('desc'),
  74. 'author' => [
  75. 'name' => $input->getOption('dev'),
  76. 'email' => $input->getOption('email'),
  77. 'githubid' => $input->getOption('github')
  78. ],
  79. 'offline' => $input->getOption('offline'),
  80. ];
  81. $this->validateOptions();
  82. $this->component = array_replace($this->component, $this->options);
  83. if (!$this->options['name']) {
  84. $question = new Question('Enter <yellow>Plugin Name</yellow>');
  85. $question->setValidator(function ($value) {
  86. return $this->validate('name', $value);
  87. });
  88. $this->component['name'] = $io->askQuestion($question);
  89. }
  90. if (!$this->options['description']) {
  91. $question = new Question('Enter <yellow>Plugin Description</yellow>');
  92. $question->setValidator(function ($value) {
  93. return $this->validate('description', $value);
  94. });
  95. $this->component['description'] = $io->askQuestion($question);
  96. }
  97. if (!$this->options['author']['name']) {
  98. $question = new Question('Enter <yellow>Developer Name</yellow>');
  99. $question->setValidator(function ($value) {
  100. return $this->validate('developer', $value);
  101. });
  102. $this->component['author']['name'] = $io->askQuestion($question);
  103. }
  104. if (!$this->options['author']['githubid']) {
  105. $question = new Question('Enter <yellow>GitHub ID</yellow> (can be blank)');
  106. $question->setValidator(function ($value) {
  107. return $this->validate('githubid', $value);
  108. });
  109. $this->component['author']['githubid'] = $io->askQuestion($question);
  110. }
  111. if (!$this->options['author']['email']) {
  112. $question = new Question('Enter <yellow>Developer Email</yellow>');
  113. $question->setValidator(function ($value) {
  114. return $this->validate('email', $value);
  115. });
  116. $this->component['author']['email'] = $io->askQuestion($question);
  117. }
  118. $question = new ChoiceQuestion(
  119. 'Please choose an option',
  120. ['blank' => 'Basic Plugin',
  121. 'flex' => 'Basic Plugin prepared for custom Flex Objects'
  122. ]
  123. );
  124. $this->component['template'] = $io->askQuestion($question);
  125. if ($this->component['template'] === 'flex') {
  126. $question = new Question('Enter Flex Object Name');
  127. $question->setValidator(function ($value) {
  128. return $this->validate('name', $value);
  129. });
  130. $this->component['flex_name'] = $io->askQuestion($question);
  131. $question = new ChoiceQuestion('Please choose a storage type', [
  132. 'simple' => 'Basic Storage (1 file for all objects) - no media support',
  133. 'file' => 'File Storage (1 file per object)',
  134. 'folder' => 'Folder Storage (1 folder per object)'
  135. ]);
  136. $this->component['flex_storage'] = $io->askQuestion($question);
  137. }
  138. $this->createComponent();
  139. return 0;
  140. }
  141. }