Skip to content
Permalink
Browse files

3954 machine name (#3962)

* Add new arguments key and target. Make it possible use not only default target for db connections

* Trim machine name and add additional validation
  • Loading branch information...
LOBsTerr committed Apr 10, 2019
1 parent ca380de commit a267393b2750d8bfe1e4322add64a7afb194eb93
@@ -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');
@@ -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');
@@ -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) {
@@ -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;
@@ -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(

0 comments on commit a267393

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