aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar logmanoriginal <logmanoriginal@users.noreply.github.com> 2018-11-15 19:33:56 +0100
committerGravatar logmanoriginal <logmanoriginal@users.noreply.github.com> 2018-11-15 19:33:56 +0100
commit6e70d461e1877cc51ecfda1081a2cb42ebfb7364 (patch)
tree1f6bff9e9b1069d2dd80e882ba4c0fd7112d6abb
parent0a92b5d29b202fdb13b29c401bb9fb229ee47a12 (diff)
downloadrss-bridge-6e70d461e1877cc51ecfda1081a2cb42ebfb7364.tar.gz
rss-bridge-6e70d461e1877cc51ecfda1081a2cb42ebfb7364.tar.zst
rss-bridge-6e70d461e1877cc51ecfda1081a2cb42ebfb7364.zip
[Bridge] Add function isBridgeName
This function returns true if the provided name is a valid bridge name.
-rw-r--r--lib/Bridge.php15
1 files changed, 14 insertions, 1 deletions
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!');
}
@@ -141,6 +141,19 @@ class Bridge {
}
/**
+ * 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.
*
* The list is cached internally to allow for successive calls.