\n"; } // provides the environment dependent classname for $ClassName public static function GetVersioned($ClassName){ $phpversion = phpversion(); if (is_null($ClassName) | $ClassName === ""){ return ["", $phpversion]; } if (strpos($phpversion, "5.") === 0) { return ["Version5".$ClassName, "php5path", $phpversion]; } else if (strpos($phpversion, "7.") === 0) { return ["Version7".$ClassName, "php7path", $phpversion]; } } // provides a new environment dependent object of class $ClassName public static function GetVersionedInstance($ClassName){ $versioninfo = VersionSelector::GetVersioned($ClassName); return new $versioninfo[0]; } // provides the environment dependent classname, if committed, the // methodname and the call parameters of a static function call as input // arrays for the php internal function call_user_func_array // string parameters in $StaticCall have to be enclosed in single quotes // and special characters to be escaped by backslash. public static function GetParams($StaticCall){ $exploded = explode("::", $StaticCall); if (count($exploded) > 1) { $classname = $exploded[0]; $classname = VersionSelector::GetVersioned($classname)[0]; $method = $exploded[1]; } else { $method = $exploded[0]; } $params = preg_split('/\(/', $method, 2, PREG_SPLIT_DELIM_CAPTURE); $params = trim($params[1]); $params = substr($params, 0, strlen($params) - 1); $method = explode("(", $method)[0]; $parameters = str_getcsv($params, ",", "'"); if (is_null($classname)) { return array($method, $parameters); } else { return array(array($classname, $method), $parameters); } } // provides the result of a static function call by calling the environment // dependent class's static function with the given parameters public static function GetStaticResult($StaticCall){ return call_user_func_array(VersionSelector::GetParams($StaticCall)[0], VersionSelector::GetParams($StaticCall)[1]); } // the non-static version of GetParams. Probably only for development // purposes public function GetParamsForStatic($StaticCall){ $exploded = explode("::", $StaticCall); if (count($exploded) > 1) { $classname = $exploded[0]; $classname = VersionSelector::GetVersioned($classname)[0]; $method = $exploded[1]; } else { $method = $exploded[0]; } $params = preg_split('/\(/', $method, 2, PREG_SPLIT_DELIM_CAPTURE); $params = trim($params[1]); $params = substr($params, 0, strlen($params) - 1); $method = explode("(", $method)[0]; $parameters = str_getcsv($params, ",", "'"); if (is_null($classname)) { return array($method, $parameters); } else { return array(array($classname, $method), $parameters); } } }