Skip to content
Permalink
Browse files

[generate:controller] Validate class file is already exist (#4066)

  • Loading branch information...
harold20 authored and enzolutions committed May 29, 2019
1 parent df8b95b commit f6981bcfa6fb80909d66ea33b2d1e4d99f1283ba
Showing with 21 additions and 2 deletions.
  1. +4 −2 src/Command/Generate/ControllerCommand.php
  2. +17 −0 src/Utils/Validator.php
@@ -137,6 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$module = $this->validateModule($input->getOption('module'));
$class = $this->validator->validateControllerName($input->getOption('class'));
$this->validator->validateControllerClassExists($class, $module);
$routes = $input->getOption('routes');
$test = $input->getOption('test');
$services = $input->getOption('services');
@@ -176,8 +177,9 @@ protected function interact(InputInterface $input, OutputInterface $output)
$class = $this->getIo()->ask(
$this->trans('commands.generate.controller.questions.class'),
'DefaultController',
function ($class) {
return $this->validator->validateControllerName($class);
function ($class) use($module) {
$class = $this->validator->validateControllerName($class);
return $this->validator->validateControllerClassExists($class, $module);
}
);
$input->setOption('class', $class);
@@ -132,6 +132,23 @@ public function validateControllerName($class_name)
}
}
public function validateControllerClassExists($class_name, $module_name)
{
$class_exists = $this->extensionManager->getModule($module_name)->getControllerPath() . '/' . $class_name . '.php';
if (!$class_exists) {
return $class_name;
} else {
throw new \InvalidArgumentException(
sprintf(
'Controller file with the name "%s.php" is already exist. Enter a different controller class name',
$class_name,
$module_name
)
);
}
}
public function validateMachineName($machine_name)
{
if (preg_match(self::REGEX_MACHINE_NAME, $machine_name)) {

0 comments on commit f6981bc

Please sign in to comment.
You can’t perform that action at this time.