$method( ...$args ); } // If the class is a singleton, use the "instance" method. if ( method_exists( $class_name, 'instance' ) ) { return $class_name::instance( ...$args ); } // If the class has a "load" method, use it. if ( method_exists( $class_name, 'load' ) ) { return $class_name::load( ...$args ); } // Fallback to simply creating a new instance of the class. return new $class_name( ...$args ); } /** * Get an instance of a class implementing WC_Queue_Interface. * * @return \WC_Queue_Interface The instance. */ private function get_instance_of_wc_queue_interface() { return \WC_Queue::instance(); } /** * Call a user function. This should be used to execute any non-idempotent function, especially * those in the `includes` directory or provided by WordPress. * * @param string $function_name The function to execute. * @param mixed ...$parameters The parameters to pass to the function. * * @return mixed The result from the function. */ public function call_function( $function_name, ...$parameters ) { return call_user_func_array( $function_name, $parameters ); } /** * Call a static method in a class. This should be used to execute any non-idempotent method in classes * from the `includes` directory. * * @param string $class_name The name of the class containing the method. * @param string $method_name The name of the method. * @param mixed ...$parameters The parameters to pass to the method. * * @return mixed The result from the method. */ public function call_static( $class_name, $method_name, ...$parameters ) { return call_user_func_array( "$class_name::$method_name", $parameters ); } /** * Get the value of a global. * * @param string $global_name The name of the global to get the value for. * @return mixed The value of the global. */ public function get_global( string $global_name ) { return $GLOBALS[ $global_name ]; } /** * Terminates execution of the script. * * @param int|string $status An error code to be returned, or an error message to be shown. * @return void */ public function exit( $status = '' ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped exit( $status ); } }