[Format] Add function isFormatName
Returns true if the provided format name is valid
This commit is contained in:
parent
6b6ab6486a
commit
d7c374bd8c
1 changed files with 14 additions and 1 deletions
|
@ -64,7 +64,7 @@ class Format {
|
|||
* @return object|bool The format object or false if the class is not instantiable.
|
||||
*/
|
||||
public static function create($name){
|
||||
if(!preg_match('@^[A-Z][a-zA-Z]*$@', $name)) {
|
||||
if(!self::isFormatName($name)) {
|
||||
throw new \InvalidArgumentException('Format name invalid!');
|
||||
}
|
||||
|
||||
|
@ -126,6 +126,19 @@ class Format {
|
|||
return self::$workingDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the provided name is a valid format name.
|
||||
*
|
||||
* A valid format name starts with a capital letter ([A-Z]), followed by
|
||||
* zero or more alphanumeric characters or hyphen ([A-Za-z0-9-]).
|
||||
*
|
||||
* @param string $name The format name.
|
||||
* @return bool true if the name is a valid format name, false otherwise.
|
||||
*/
|
||||
public static function isFormatName($name){
|
||||
return is_string($name) && preg_match('/^[A-Z][a-zA-Z0-9-]*$/', $name) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read format dir and catch informations about each format depending annotation
|
||||
* @return array Informations about each format
|
||||
|
|
Loading…
Reference in a new issue