Regex - isValidBundleName() method - returns information if given name of bundle is valid

This commit is contained in:
Meritoo
2017-12-21 21:47:45 +01:00
parent 5aaf7cde72
commit 66aefa2446
2 changed files with 82 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ class Regex
'windowsBasedPath' => '/^[A-Z]{1}:\\\.*$/',
'money' => '/^[-+]?\d+([\.,]{1}\d*)?$/',
'color' => '/^[a-f0-9]{6}$/i',
'bundleName' => '/^(([A-Z]{1}[a-z0-9]+)((?2))*)(Bundle)$/',
];
/**
@@ -723,4 +724,21 @@ class Regex
return strtolower($color);
}
/**
* Returns information if given name of bundle is valid
*
* @param string $bundleName Full name of bundle to verify, e.g. "MyExtraBundle"
* @return bool
*/
public static function isValidBundleName($bundleName)
{
if (!is_string($bundleName)) {
return false;
}
$pattern = self::$patterns['bundleName'];
return (bool)preg_match($pattern, $bundleName);
}
}