Elgg  Version 3.0
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Elgg\HooksRegistrationService Class Reference

Base class for events and hooks. More...

Inheritance diagram for Elgg\HooksRegistrationService:
Elgg\EventsService Elgg\PluginHooksService

Public Member Functions

 registerHandler ($name, $type, $callback, $priority=500)
 Register a callback as a plugin hook handler. More...
 
 unregisterHandler ($name, $type, $callback)
 Unregister a callback as a plugin hook of event handler. More...
 
 clearHandlers ($name, $type)
 Clears all callback registrations for a plugin hook. More...
 
 getAllHandlers ()
 Returns all registered handlers as array( $name => array( $type => array( $priority => array( callback, callback, ) ) ) More...
 
 hasHandler ($name, $type)
 Is a handler registered for this specific name and type? "all" handlers are not considered. More...
 
 getOrderedHandlers ($name, $type)
 Returns an ordered array of handlers registered for $name and $type. More...
 
 backup ()
 Temporarily remove all event/hook registrations (before tests) More...
 
 restore ()
 Restore backed up event/hook registrations (after tests) More...
 

Public Attributes

const REG_KEY_PRIORITY = 0
 
const REG_KEY_INDEX = 1
 
const REG_KEY_HANDLER = 2
 
const OPTION_DEPRECATION_MESSAGE = 'deprecation_message'
 
const OPTION_DEPRECATION_VERSION = 'deprecation_version'
 

Protected Member Functions

 getMatcher ($spec)
 Create a matcher for the given callable (if it's for a static or dynamic method) More...
 
 checkDeprecation ($name, $type, array $options=[])
 Check if handlers are registered on a deprecated hook/event. More...
 

Detailed Description

Base class for events and hooks.

Definition at line 10 of file HooksRegistrationService.php.

Member Function Documentation

Elgg\HooksRegistrationService::backup ( )

Temporarily remove all event/hook registrations (before tests)

Call backup() before your tests and restore() after.

Note
This behaves like a stack. You must call restore() for each backup() call.
Returns
void
See also
HooksRegistrationService::restore()

Definition at line 245 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::checkDeprecation (   $name,
  $type,
array  $options = [] 
)
protected

Check if handlers are registered on a deprecated hook/event.

If so Display a message

Parameters
string$namethe name of the hook/event
string$typethe type of the hook/event
array$optionsdeprecation options
Returns
void

Definition at line 272 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::clearHandlers (   $name,
  $type 
)

Clears all callback registrations for a plugin hook.

Parameters
string$nameThe name of the hook
string$typeThe type of the hook
Returns
void
See also
elgg_clear_plugin_hook_handlers()

Definition at line 111 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::getAllHandlers ( )

Returns all registered handlers as array( $name => array( $type => array( $priority => array( callback, callback, ) ) )

Returns
array

Definition at line 128 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::getMatcher (   $spec)
protected

Create a matcher for the given callable (if it's for a static or dynamic method)

Parameters
callable$specCallable we're creating a matcher for
Returns
MethodMatcher|null

Definition at line 214 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::getOrderedHandlers (   $name,
  $type 
)

Returns an ordered array of handlers registered for $name and $type.

Parameters
string$nameThe name of the hook
string$typeThe type of the hook
Returns
callable[]
See also
::getAllHandlers()

Definition at line 165 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::hasHandler (   $name,
  $type 
)

Is a handler registered for this specific name and type? "all" handlers are not considered.

If you need to consider "all" handlers, you must check them independently, or use (bool)elgg_get_ordered_hook_handlers().

Parameters
string$nameThe name of the hook
string$typeThe type of the hook
Returns
boolean

Definition at line 153 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::registerHandler (   $name,
  $type,
  $callback,
  $priority = 500 
)

Register a callback as a plugin hook handler.

Parameters
string$nameThe name of the hook
string$typeThe type of the hook
callable$callbackThe name of a valid function or an array with object and method
int$priorityThe priority - 500 is default, lower numbers called first
Returns
bool
Warning
This doesn't check if a callback is valid to be called, only if it is in the correct format as a callable.
See also
elgg_register_plugin_hook_handler()

Definition at line 48 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::restore ( )

Restore backed up event/hook registrations (after tests)

Returns
void
See also
HooksRegistrationService::backup()

Definition at line 256 of file HooksRegistrationService.php.

Elgg\HooksRegistrationService::unregisterHandler (   $name,
  $type,
  $callback 
)

Unregister a callback as a plugin hook of event handler.

Parameters
string$nameThe name of the hook/event
string$typeThe name of the type of entity (eg "user", "object" etc)
callable$callbackThe PHP callback to be removed. Since 1.11, static method callbacks will match dynamic methods
Returns
bool
See also
elgg_unregister_plugin_hook_handler()
elgg_unregister_event_handler()

Definition at line 76 of file HooksRegistrationService.php.

Member Data Documentation

const Elgg\HooksRegistrationService::OPTION_DEPRECATION_MESSAGE = 'deprecation_message'

Definition at line 16 of file HooksRegistrationService.php.

const Elgg\HooksRegistrationService::OPTION_DEPRECATION_VERSION = 'deprecation_version'

Definition at line 17 of file HooksRegistrationService.php.

const Elgg\HooksRegistrationService::REG_KEY_HANDLER = 2

Definition at line 14 of file HooksRegistrationService.php.

const Elgg\HooksRegistrationService::REG_KEY_INDEX = 1

Definition at line 13 of file HooksRegistrationService.php.

const Elgg\HooksRegistrationService::REG_KEY_PRIORITY = 0

Definition at line 12 of file HooksRegistrationService.php.


The documentation for this class was generated from the following file: