From 6e70d461e1877cc51ecfda1081a2cb42ebfb7364 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Thu, 15 Nov 2018 19:33:56 +0100 Subject: [PATCH] [Bridge] Add function isBridgeName This function returns true if the provided name is a valid bridge name. --- lib/Bridge.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Bridge.php b/lib/Bridge.php index 113e4380..f3488183 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -78,7 +78,7 @@ class Bridge { * @return object|bool The bridge object or false if the class is not instantiable. */ public static function create($name){ - if(!preg_match('/^[A-Z][a-zA-Z0-9-]*$/', $name)) { + if(!self::isBridgeName($name)) { throw new \InvalidArgumentException('Bridge name invalid!'); } @@ -140,6 +140,19 @@ class Bridge { return self::$workingDir; } + /** + * Returns true if the provided name is a valid bridge name. + * + * A valid bridge 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 bridge name. + * @return bool true if the name is a valid bridge name, false otherwise. + */ + public static function isBridgeName($name){ + return is_string($name) && preg_match('/^[A-Z][a-zA-Z0-9-]*$/', $name) === 1; + } + /** * Returns the list of bridge names based on the working directory. *