Skip to content

Commit 55c162c

Browse files
LOBsTerrenzolutions
authored andcommitted
4147 module validation (#4148)
* Add new arguments key and target. Make it possible use not only default target for db connections * Add validation for a module name, regex and also reserved words * Check machine name with correct regex and also check reserved names
1 parent 173a51d commit 55c162c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Utils/Validator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Validator
1515
const REGEX_CLASS_NAME = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/';
1616
const REGEX_COMMAND_CLASS_NAME = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+Command$/';
1717
const REGEX_CONTROLLER_CLASS_NAME = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+Controller$/';
18-
const REGEX_MACHINE_NAME = '/^[a-z0-9_]+$/';
18+
const REGEX_MACHINE_NAME = '/^[a-z][a-z\d_]+$/';
1919
const REGEX_DEPENDENCY_NAME = '/^[a-z0-9_:]+$/';
2020
const REGEX_URI_NAME = '/^[a-z0-9_.]+$/';
2121
// This REGEX remove spaces between words
@@ -134,7 +134,12 @@ public function validateControllerName($class_name)
134134

135135
public function validateMachineName($machine_name)
136136
{
137-
if (preg_match(self::REGEX_MACHINE_NAME, $machine_name)) {
137+
// @see https://www.drupal.org/docs/8/creating-custom-modules/naming-and-placing-your-drupal-8-module
138+
$reserved_words = [
139+
'src', 'lib', 'vendor', 'assets', 'css', 'files', 'images', 'js', 'misc', 'templates', 'includes',
140+
'fixtures', 'Drupal',
141+
];
142+
if (preg_match(self::REGEX_MACHINE_NAME, $machine_name) && !in_array($machine_name, $reserved_words)) {
138143
if (strlen($machine_name) > self::MAX_MACHINE_NAME) {
139144
throw new \InvalidArgumentException(
140145
sprintf(

0 commit comments

Comments
 (0)