Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.

Commit 1bf09dd

Browse files
committed
add base path support to controller maker
1 parent f1ed059 commit 1bf09dd

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Maker/MakeController.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
7373
'Add a command bus dependency.',
7474
null
7575
)
76+
->addOption(
77+
'base-path',
78+
null,
79+
InputOption::VALUE_REQUIRED,
80+
'Base path from which to generate model & config.',
81+
null
82+
)
7683
;
7784
}
7885

@@ -103,16 +110,26 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
103110
);
104111
$input->setOption('include-command-bus', $includeCommandBus);
105112
}
113+
114+
if (null === $input->getOption('base-path')) {
115+
$basePath = $io->ask(
116+
'Which base path should be used? Default is "' . PathGenerator::DEFAULT_BASE_PATH . '"',
117+
PathGenerator::DEFAULT_BASE_PATH,
118+
);
119+
$input->setOption('base-path', $basePath);
120+
}
106121
}
107122

108123
/**
109124
* @inheritDoc
110125
*/
111126
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
112127
{
128+
$pathGenerator = new PathGenerator($input->getOption('base-path'));
129+
113130
$classNameDetails = $generator->createClassNameDetails(
114131
$input->getArgument('name'),
115-
self::NAMESPACE_PREFIX,
132+
$pathGenerator->namespacePrefix(self::NAMESPACE_PREFIX),
116133
'Controller',
117134
);
118135

@@ -155,7 +172,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
155172
self::CONFIG_PATH,
156173
$templatePathConfig,
157174
[
158-
'path' => '../../src/Infrastructure/Http/Controller/',
175+
'path' => $pathGenerator->path('../../src/', 'Infrastructure/Http/Controller/'),
159176
'namespace' => str_replace('\\' . $classNameDetails->getShortName(), '', $classNameDetails->getFullName())
160177
]
161178
);

0 commit comments

Comments
 (0)