Overview

Namespaces

  • Core
    • Auth
    • Exceptions
    • Helpers
    • Providers
  • Kernel
    • Dispatch
    • Providers
  • None
  • Vendor
    • ExampleVendor

Classes

  • Flash
  • Hooks
  • Overview
  • Namespace
  • Class
  • Download

Class Hooks

Hooks is a class that manages all the hooks set throughout the framework.
Hooks are useful to attach actions to other actions, or to alter the execution thread without changing the code.

Hooks is based on the Wordpress hooks system, to allow for plugin flexibility

Namespace: Core\Helpers
Defaults:

The hooks included by default in the framework are:

Kernel\AppKernel:

('After_Hooks_Setup', $hooks) // called right after the constructor
('exec_beforestart', ['controller' => $controllerName, 'action' => $action]) // just after \Kernel\Router::matchRoute
('permission_unallowed', [
    'permission' => $permission,
    'controller' => $controllerName,
    'action' => $action]) // when it's an unauthorized request
('general_exception', ['e' => $e]) // when an Exception is thrown
('exec_afterend', ['controller' => $controllerName, 'action' => $action]) // When execution has finished


Core\ParentController:

('include_show_view', ['vars' => $this->vars]) // Called just before including the view file \Core\ParentController::show
('include_get_view', ['vars' => $_vars]) // Called just before including a view file  \Core\ParentController::get
('extra_params_path', ['route' => $route]) // If extra parameters are required when creating a url \Core\ParentController::path


\Core\LoginController:

('on_userauth', ['user' => $user]) // Called just after the login session has been created \Core\LoginController::login
('on_userdeauth', ['user' => Session::getUser()]) // Called just before destroying the login session. \Core\LoginController::deauthenticateUser


\Core\ExceptionController:

('show_prod_exception', ['e' => $e]) // Called when an exception is thrown on the PROD environment \Core\ExceptionController::showException
('show_dev_exception', ['e' => $e]) // Called when an exception is thrown on the DEV environment \Core\ExceptionController::showException

\Kernel\Logger:

('logger_post', $postArray) // Called before posting an error log \Kernel\Logger::sendLog

See \Core\Hooks::do_action and \Core\Hooks::add_action functions to learn how to use them


Located at app/Kernel/Helpers/Hooks.php
Methods summary
public
# __construct( $args = null )

__construct class constructor

__construct class constructor

Since

0.1
public static Core\Helpers\Hooks
# init( $args = null )

Singleton initializer

Singleton initializer

Returns

Core\Helpers\Hooks
public boolean
# add_filter( string $tag, callable $function_to_add, integer $priority = 10, integer $accepted_args = 1 )

add_filter Hooks a function or method to a specific filter action.

add_filter Hooks a function or method to a specific filter action.

Parameters

$tag
The name of the filter to hook the $function_to_add to.
$function_to_add
The name of the function to be called when the filter is applied.
$priority

optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.

$accepted_args
optional. The number of arguments the function accept (default 1).

Returns

boolean
true

Since

0.1
public boolean
# remove_filter( string $tag, callable $function_to_remove, integer $priority = 10, integer $accepted_args,… )

remove_filter Removes a function from a specified filter hook.

remove_filter Removes a function from a specified filter hook.

Parameters

$tag
The filter hook to which the function to be removed is hooked.
$function_to_remove
The name of the function which should be removed.
$priority
optional. The priority of the function (default: 10).
$accepted_args,…
optional. The number of arguments the function accepts (default: 1).

Returns

boolean
Whether the function existed before it was removed.

Since

0.1
public boolean
# remove_all_filters( string $tag, integer $priority = false )

remove_all_filters Remove all of the hooks from a filter.

remove_all_filters Remove all of the hooks from a filter.

Parameters

$tag
The filter to remove hooks from.
$priority
The priority number to remove.

Returns

boolean
True when finished.

Since

0.1
public mixed
# has_filter( string $tag, callable $function_to_check = false )

has_filter Check if any filter has been registered for a hook.

has_filter Check if any filter has been registered for a hook.

Parameters

$tag
The name of the filter hook.
$function_to_check
optional.

Returns

mixed

If $function_to_check is omitted, returns boolean for whether the hook has anything registered. When checking a specific function, the priority of that hook is returned, or false if the function is not attached. When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false (e.g.) 0, so use the === operator for testing the return value.

Since

0.1
public mixed
# apply_filters( string $tag, mixed $value )

apply_filters Call the functions added to a filter hook.

apply_filters Call the functions added to a filter hook.

Parameters

$tag
The name of the filter hook.
$value
The value on which the filters hooked to $tag are applied on.

Returns

mixed
The filtered value after all hooked functions are applied to it.

Since

0.1
public mixed
# apply_filters_ref_array( string $tag, array $args )

apply_filters_ref_array Execute functions hooked on a specific filter hook, specifying arguments in an array.

apply_filters_ref_array Execute functions hooked on a specific filter hook, specifying arguments in an array.

Parameters

$tag
The name of the filter hook.
$args
The arguments supplied to the functions hooked to $tag

Returns

mixed
The filtered value after all hooked functions are applied to it.

Since

0.1
public boolean|true
# add_action( string $tag, callable $function_to_add, integer $priority = 10, integer $accepted_args = 1 )

add_action Hooks a function on to a specific action.

add_action Hooks a function on to a specific action.

Parameters

$tag
The name of the action to which the $function_to_add is hooked.
$function_to_add
The name of the function you wish to be called.
$priority

optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.

$accepted_args
optional. The number of arguments the function accept (default 1).

Returns

boolean|true
The result of the add_filter

Since

0.1
public mixed
# has_action( string $tag, callable $function_to_check = false )

has_action Check if any action has been registered for a hook.

has_action Check if any action has been registered for a hook.

Parameters

$tag
The name of the action hook.
$function_to_check
optional.

Returns

mixed

If $function_to_check is omitted, returns boolean for whether the hook has anything registered. When checking a specific function, the priority of that hook is returned, or false if the function is not attached. When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false (e.g.) 0, so use the === operator for testing the return value.

Since

0.1
public boolean
# remove_action( string $tag, callable $function_to_remove, integer $priority = 10 )

remove_action Removes a function from a specified action hook.

remove_action Removes a function from a specified action hook.

Parameters

$tag
The action hook to which the function to be removed is hooked.
$function_to_remove
The name of the function which should be removed.
$priority
optional The priority of the function (default: 10).

Returns

boolean
Whether the function is removed.

Since

0.1
public boolean
# remove_all_actions( string $tag, integer $priority = false )

remove_all_actions Remove all of the hooks from an action.

remove_all_actions Remove all of the hooks from an action.

Parameters

$tag
The action to remove hooks from.
$priority
The priority number to remove them from.

Returns

boolean
True when finished.

Since

0.1
public mixed
# do_action( string $tag, mixed $arg = '' )

do_action Execute functions hooked on a specific action hook.

do_action Execute functions hooked on a specific action hook.

Parameters

$tag
The name of the action to be executed.
$arg

Optional additional arguments which are passed on to the functions hooked to the action.

Returns

mixed
The response of the last called action

Since

0.1
public null
# do_action_ref_array( string $tag, array $args )

do_action_ref_array Execute functions hooked on a specific action hook, specifying arguments in an array.

do_action_ref_array Execute functions hooked on a specific action hook, specifying arguments in an array.

Parameters

$tag
The name of the action to be executed.
$args
The arguments supplied to the functions hooked to $tag

Returns

null
Will return null if $tag does not exist in $filter array

Since

0.1
public integer
# did_action( string $tag )

did_action Retrieve the number of times an action is fired.

did_action Retrieve the number of times an action is fired.

Parameters

$tag
The name of the action hook.

Returns

integer
The number of times action hook $tag is fired

Since

0.1
public string
# current_filter( )

current_filter Retrieve the name of the current filter or action.

current_filter Retrieve the name of the current filter or action.

Returns

string
Hook name of the current filter or action.

Since

0.1
public string
# current_action( )

Retrieve the name of the current action.

Retrieve the name of the current action.

Returns

string
Hook name of the current action.

Since

0.1.2

Uses

Core\Helpers\Hooks::$current_filter
public boolean
# doing_filter( null|string $filter = null )

Retrieve the name of a filter currently being processed.

Retrieve the name of a filter currently being processed.

The function current_filter() only returns the most recent filter or action being executed. did_action() returns true once the action is initially processed. This function allows detection for any filter currently being executed (despite not being the most recent filter to fire, in the case of hooks called from hook callbacks) to be verified.

Parameters

$filter

Optional. Filter to check. Defaults to null, which checks if any filter is currently being run.

Returns

boolean
Whether the filter is currently in the stack

Since

0.1.2

See

Core\Helpers\Hooks::$current_filter
Core\Helpers\Hooks::did_action()

Used by

Core\Helpers\Hooks::doing_action()
public boolean
# doing_action( string|null $action = null )

Retrieve the name of an action currently being processed.

Retrieve the name of an action currently being processed.

Parameters

$action

Optional. Action to check. Defaults to null, which checks if any action is currently being run.

Returns

boolean
Whether the action is currently in the stack.

Since

0.1.2

Uses

Core\Helpers\Hooks::doing_filter()
public
# __call_all_hook( (array) $args )

__call_all_hook

__call_all_hook

Parameters

$args
[description]

Since

0.1
Properties summary
protected static $hooks
# null
public array $filters

$filters holds list of hooks

$filters holds list of hooks

Since

0.1
# array()
public array $merged_filters

$merged_filters

$merged_filters

# array()
public array $actions

$actions

$actions

# array()
public array $current_filter

$current_filter holds the name of the current filter

$current_filter holds the name of the current filter

Since

0.1

Used by

Core\Helpers\Hooks::current_action()
# array()
Ribosome API documentation generated by ApiGen