Documentation

IntegrationHook
in package
Uses BackwardCompatibility

Handles adding, removing, and calling hooked integration functions.

Table of Contents

Properties

$ignore_errors  : bool
$name  : array<string|int, mixed>
$results  : array<string|int, mixed>
$backcompat  : array<string|int, mixed>
$callables  : array<string|int, mixed>

Methods

__construct()  : mixed
Constructor.
add()  : void
Adds a function or method to an integration hook.
call()  : array<string|int, mixed>
Convenience method to create and execute an instance of this class.
execute()  : array<string|int, mixed>
Executes all the callables in $this->callables, passing the $parameters to each one.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
remove()  : void
Removes an integration hook function.

Properties

$ignore_errors

public bool $ignore_errors = false

If true, silently skip hooked functions that are not callable.

$name

public array<string|int, mixed> $name

The name of this integration hook.

$results

public array<string|int, mixed> $results = []

The results from executing this hook.

$backcompat

private static array<string|int, mixed> $backcompat = ['func_names' => ['call' => 'call_integration_hook', 'add' => 'add_integration_function', 'remove' => 'remove_integration_function']]

BackwardCompatibility settings for this class.

$callables

private array<string|int, mixed> $callables = []

The callables to execute for this hook.

Methods

__construct()

Constructor.

public __construct(string $name[, bool $ignore_errors = null ]) : mixed
Parameters
$name : string

The name of the integration hook.

$ignore_errors : bool = null

If true, silently skip hooked functions that are not callable. Defaults to Utils::$context['ignore_hook_errors'].

add()

Adds a function or method to an integration hook.

public static add(string $name, string $function[, bool $permanent = true ][, string $file = '' ][, bool $object = false ]) : void

Does nothing if the function is already added. Cleans up enabled/disabled variants before taking requested action.

Parameters
$name : string

The complete hook name.

$function : string

The function name. Can be a call to a method via Class::method.

$permanent : bool = true

If true, updates the value in settings table.

$file : string = ''

The filename. Must include one of the following wildcards: $boarddir, $sourcedir, $themedir. Example: $sourcedir/Test.php

$object : bool = false

Indicates if your class will be instantiated when its respective hook is called. If true, your function must be a method.

call()

Convenience method to create and execute an instance of this class.

public static call(string $name[, array<string|int, mixed> $parameters = [] ]) : array<string|int, mixed>
Parameters
$name : string

The name of the integration hook.

$parameters : array<string|int, mixed> = []

Parameters to pass to the hooked callables.

Return values
array<string|int, mixed>

The results returned by all the hooked callables.

execute()

Executes all the callables in $this->callables, passing the $parameters to each one.

public execute([array<string|int, mixed> $parameters = [] ]) : array<string|int, mixed>
Parameters
$parameters : array<string|int, mixed> = []

Parameters to pass to the hooked callables.

Return values
array<string|int, mixed>

The results returned by all the hooked callables.

exportStatic()

Provides a way to export a class's public static properties and methods to global namespace.

public static exportStatic() : void

To do so:

  1. Use this trait in the class.
  2. At the END of the class's file, call its exportStatic() method.

Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.

Regarding the $backcompat items:

A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].

$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.

$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.

Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.

remove()

Removes an integration hook function.

public static remove(string $name, string $function[, bool $permanent = true ][, string $file = '' ][, bool $object = false ]) : void

Removes the given function from the given hook. Does nothing if the function is not available. Cleans up enabled/disabled variants before taking requested action.

Parameters
$name : string

The complete hook name.

$function : string

The function name. Can be a call to a method via Class::method.

$permanent : bool = true

Irrelevant for the function itself but need to declare it to match.

$file : string = ''

The filename. Must include one of the following wildcards: $boarddir, $sourcedir, $themedir. Example: $sourcedir/Test.php

$object : bool = false

Indicates if your class will be instantiated when its respective hook is called. If true, your function must be a method.

Tags
see

IntegrationHook:add


        
On this page

Search results