Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3954 machine name #3962

Merged
merged 6 commits into from Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Command/Generate/EntityConfigCommand.php
Expand Up @@ -90,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$module = $this->validateModule($input->getOption('module'));
$entity_class = $input->getOption('entity-class');
$entity_name = $input->getOption('entity-name');
$entity_name = $this->validator->validateMachineName($input->getOption('entity-name'));
$label = $input->getOption('label');
$bundle_of = $input->getOption('bundle-of');
$base_path = $input->getOption('base-path');
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Generate/EntityContentCommand.php
Expand Up @@ -138,7 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$module = $this->validateModule($input->getOption('module'));
$entity_class = $input->getOption('entity-class');
$entity_name = $input->getOption('entity-name');
$entity_name = $this->validator->validateMachineName($input->getOption('entity-name'));
$label = $input->getOption('label');
$has_bundles = $input->getOption('has-bundles');
$base_path = $input->getOption('base-path');
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Generate/ModuleCommand.php
Expand Up @@ -248,7 +248,7 @@ function ($module) use ($validator) {

try {
$machineName = $input->getOption('machine-name') ?
$this->validator->validateModuleName(
$validator->validateModuleName(
$input->getOption('machine-name')
) : null;
} catch (\Exception $error) {
Expand Down
11 changes: 11 additions & 0 deletions src/Utils/Validator.php
Expand Up @@ -18,6 +18,8 @@ class Validator
const REGEX_MACHINE_NAME = '/^[a-z0-9_]+$/';
// This REGEX remove spaces between words
const REGEX_REMOVE_SPACES = '/[\\s+]/';
// Max length to 32
const MAX_MACHINE_NAME = 32;

protected $appRoot;

Expand Down Expand Up @@ -117,6 +119,15 @@ public function validateControllerName($class_name)
public function validateMachineName($machine_name)
{
if (preg_match(self::REGEX_MACHINE_NAME, $machine_name)) {
if (strlen($machine_name) > self::MAX_MACHINE_NAME) {
throw new \InvalidArgumentException(
sprintf(
'Machine name "%s" is longer than %s symbols.',
$machine_name,
self::MAX_MACHINE_NAME
)
);
}
return $machine_name;
} else {
throw new \InvalidArgumentException(
Expand Down