X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flibs%2FXhprof.php;h=a1ddfd077290557e3cd6c5673f76fecef180cebb;hb=f48096d81b7ec89b718ede1d140811fb3df6e0cc;hp=e58d98fcc3bf10d2d62aa4a983e83a49e9af52be;hpb=3f59cb9f3a53ad28f8a95fe299c5de6abd24b453;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/Xhprof.php b/includes/libs/Xhprof.php index e58d98fcc3..a1ddfd0772 100644 --- a/includes/libs/Xhprof.php +++ b/includes/libs/Xhprof.php @@ -54,13 +54,14 @@ class Xhprof { throw new Exception( 'Profiling is already enabled.' ); } self::$enabled = true; - if ( function_exists( 'xhprof_enable' ) ) { - xhprof_enable( $flags, $options ); - } elseif ( function_exists( 'tideways_enable' ) ) { - tideways_enable( $flags, $options ); - } else { - throw new Exception( "Neither xhprof nor tideways are installed" ); - } + self::callAny( + [ + 'xhprof_enable', + 'tideways_enable', + 'tideways_xhprof_enable' + ], + [ $flags, $options ] + ); } /** @@ -71,12 +72,30 @@ class Xhprof { public static function disable() { if ( self::isEnabled() ) { self::$enabled = false; - if ( function_exists( 'xhprof_disable' ) ) { - return xhprof_disable(); - } else { - // tideways - return tideways_disable(); + return self::callAny( [ + 'xhprof_disable', + 'tideways_disable', + 'tideways_xhprof_disable' + ] ); + } else { + return null; + } + } + + /** + * Call the first available function from $functions. + * @param array $functions + * @param array $args + * @return mixed + * @throws Exception + */ + protected static function callAny( array $functions, array $args = [] ) { + foreach ( $functions as $func ) { + if ( function_exists( $func ) ) { + return $func( ...$args ); } } + + throw new Exception( "Neither xhprof nor tideways are installed" ); } }