Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hjuarez20 committed May 29, 2019
2 parents a95b7e6 + f6981bc commit ddf7739
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Command/Generate/ControllerCommand.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/Utils/Validator.php
Expand Up @@ -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)) {
Expand Down

0 comments on commit ddf7739

Please sign in to comment.