From 3bb3353897c0cf453e7c5f2e77ef76ad82af59a7 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 10 Nov 2018 22:31:38 +0100 Subject: [PATCH] [Bridge] Use static variable in listBridges() This prevents the function from re-loading the same data over and over again. Instead the same data is returned on each call, during a single request. --- lib/Bridge.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Bridge.php b/lib/Bridge.php index 84b9901a..e450662c 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -70,13 +70,17 @@ EOD; * @return array List of the bridges */ static public function listBridges(){ - $listBridge = array(); - $dirFiles = scandir(self::getDir()); - if($dirFiles !== false) { - foreach($dirFiles as $fileName) { - if(preg_match('@^([^.]+)Bridge\.php$@U', $fileName, $out)) { - $listBridge[] = $out[1]; + static $listBridge = array(); // Initialized on first call + + if(empty($listBridge)) { + $dirFiles = scandir(self::getDir()); + + if($dirFiles !== false) { + foreach($dirFiles as $fileName) { + if(preg_match('@^([^.]+)Bridge\.php$@U', $fileName, $out)) { + $listBridge[] = $out[1]; + } } } }