Skip to content

Commit 8a5b438

Browse files
committed
DD#main: refactor: bring plugin generator interface in line with other methods
1 parent 410006b commit 8a5b438

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ Create or update a plugin class.
4444

4545
You can update an existing plugin to add new methods.
4646

47-
`magegen make:plugin [<subject> [<method> [<class> [<type> [<area>]]]]]`
47+
`magegen make:plugin [<module> [<subject> [<method> [<class> [<type> [<area>]]]]]]`
4848

49+
* module - The module name, e.g. MyCompany_MyModule
4950
* subject - The plugin subject class or interface, e.g \Magento\Checkout\Api\PaymentInformationManagementInterface
5051
* method - The plugin subject method e.g. savePaymentInformationAndPlaceOrder
51-
* class - The fully qualified class name for your plugin class, e.g.
52-
\MyCompany\MyModule\Plugin\Model\PaymentInformationPlugin
52+
* class - The class path and name relative to modules Plugin directory, e.g Model\PaymentInformationPlugin
5353
* type - The plugin type, before, around, after.
5454
* area - The plugin area, global, frontend, adminhtml, etc.
5555

src/MakePluginCommand.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace MageGen;
1313

14+
use MageGen\Autocomplete\ModuleAutocomplete;
1415
use MageGen\Generator\DiGenerator;
1516
use MageGen\Writer\ClassFile;
1617
use Nette\PhpGenerator\ClassType;
@@ -54,9 +55,10 @@ public function __construct(Environment $twig, string $name = null)
5455
protected function configure(): void
5556
{
5657
parent::configure();
58+
$this->addArgument('module', InputArgument::OPTIONAL, 'Module name');
5759
$this->addArgument('subject', InputArgument::OPTIONAL, 'Plugin subject / target');
5860
$this->addArgument('method', InputArgument::OPTIONAL, 'Subject method');
59-
$this->addArgument('class', InputArgument::OPTIONAL, 'Plugin class name');
61+
$this->addArgument('class', InputArgument::OPTIONAL, 'Plugin class name relative to module Plugin/');
6062
$this->addArgument('type', InputArgument::OPTIONAL, "before, around, after");
6163
$this->addArgument(
6264
'area',
@@ -74,6 +76,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7476

7577
$io = new SymfonyStyle($input, $output);
7678

79+
$module = $input->getArgument('module');
80+
if (!$module) {
81+
$module = $io->askQuestion(
82+
(new Question('Module'))->setAutocompleterValues(
83+
(new ModuleAutocomplete())->getAutocompleteValues(
84+
$input->getOption('magepath')
85+
)
86+
)
87+
);
88+
}
89+
7790
$subject = $input->getArgument('subject');
7891
if (!$subject) {
7992
$subject = $io->askQuestion(
@@ -86,11 +99,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8699
new Question('method')
87100
);
88101
}
89-
$classFqn = $input->getArgument('class');
90-
if (!$classFqn) {
91-
$classFqn = $io->askQuestion(new Question('Class'));
102+
$className = $input->getArgument('class');
103+
if (!$className) {
104+
$className = $io->askQuestion(new Question('Class'));
92105
}
93106

107+
$classFqn = implode(
108+
'\\',
109+
[
110+
str_replace('_', '\\', $module),
111+
'Plugin',
112+
$className,
113+
]
114+
);
115+
94116
$type = $input->getArgument('type');
95117
if (!$type) {
96118
$type = $io->choice('Type', ['before', 'around', 'after']);

0 commit comments

Comments
 (0)