WooCommerce Code Reference

LegacyProxy
in package

Proxy class to access legacy WooCommerce functionality.

This class should be used to interact with code outside the src directory, especially functions and classes in the includes directory, unless a more specific proxy exists for the functionality at hand (e.g. ActionsProxy). Idempotent functions can be executed directly.

Table of Contents

call_function()  : mixed
Call a user function. This should be used to execute any non-idempotent function, especially those in the `includes` directory or provided by WordPress.
call_static()  : mixed
Call a static method in a class. This should be used to execute any non-idempotent method in classes from the `includes` directory.
get_global()  : mixed
Get the value of a global.
get_instance_of()  : object
Gets an instance of a given legacy class.
get_instance_of_wc_queue_interface()  : WC_Queue_Interface
Get an instance of a class implementing WC_Queue_Interface.

Methods

call_function()

Call a user function. This should be used to execute any non-idempotent function, especially those in the `includes` directory or provided by WordPress.

public call_function(string $function_name, mixed ...$parameters) : mixed
Parameters
$function_name : string

The function to execute.

$parameters : mixed

The parameters to pass to the function.

Return values
mixedThe result from the function.

call_static()

Call a static method in a class. This should be used to execute any non-idempotent method in classes from the `includes` directory.

public call_static(string $class_name, string $method_name, mixed ...$parameters) : mixed
Parameters
$class_name : string

The name of the class containing the method.

$method_name : string

The name of the method.

$parameters : mixed

The parameters to pass to the method.

Return values
mixedThe result from the method.

get_global()

Get the value of a global.

public get_global(string $global_name) : mixed
Parameters
$global_name : string

The name of the global to get the value for.

Return values
mixedThe value of the global.

get_instance_of()

Gets an instance of a given legacy class.

public get_instance_of(string $class_name, mixed ...$args) : object

This must not be used to get instances of classes in the src directory.

If a given class needs a special procedure to get an instance of it, please add a private get_instance_of_(lowercased_class_name) and it will be automatically invoked. See also how objects of classes having a static instance method are retrieved, similar approaches can be used as needed to make use of existing factory methods such as e.g. 'load'.

Parameters
$class_name : string

The name of the class to get an instance for.

$args : mixed

Parameters to be passed to the class constructor or to the appropriate internal 'get_instance_of_' method.

Tags
throws
Exception

The requested class belongs to the src directory, or there was an error creating an instance of the class.

Return values
objectThe instance of the class.