Download the PHP package bayfrontmedia/php-hooks without Composer
On this page you can find all versions of the php package bayfrontmedia/php-hooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bayfrontmedia/php-hooks
More information about bayfrontmedia/php-hooks
Files in bayfrontmedia/php-hooks
Package php-hooks
Short Description An easy to use hooks library for managing events and filters.
License MIT
Homepage https://github.com/bayfrontmedia/php-hooks
Informations about the package php-hooks
PHP hooks
An easy to use hooks library for managing events and filters.
- License
- Author
- Requirements
- Installation
- Usage
License
This project is open source and available under the MIT License.
Author
Requirements
- PHP
^8.0
Installation
Usage
Start using hooks
Public methods
Events
- addEvent
- hasEvent
- getEvents
- removeEvent
- removeEvents
- doEvent
Filters
- addFilter
- hasFilter
- getFilters
- removeFilter
- removeFilters
- doFilter
addEvent
Description:
Adds a hook for a given event name.
NOTE: Anonymous functions are unable to be removed with removeEvent()
, so use them carefully.
Parameters:
$name
(string): Name of event$function
(callable)$priority = 10
(int): Hooks will be executed by order of priority in ascending order (lower numbers = earlier execution)
Reserved names:
always
: These hooks will always be executed wheneverdoEvent()
is called, regardless of the name.destruct
: These hooks will be executed when the script terminates.
Returns:
- (void)
Examples:
Anonymous function
Named function
Inside class scope
Use variables from outside scope
hasEvent
Description:
Checks if any events exist for a given name.
Parameters:
$name
(string): Name of event
Returns:
- (bool)
Example:
getEvents
Description:
Return array of all hooks for all events, or of a given event name.
Parameters:
$name = NULL
(string|null): Name of event
Returns:
- (array)
Example:
removeEvent
Description:
Removes hook from a given event, if existing.
NOTE: Hooks using anonymous functions cannot be removed using this method.
Parameters:
$name
(string): Name of event$function
(callable): Hook to remove
Returns:
- (bool): Returns
true
if the hook existed
Example:
To remove a hook for a function from within a class scope, the $function
parameter must be an array whose first value is an instance of the class, and second value is the name of the function within the class:
removeEvents
Description:
Removes all hooks from a given event, if existing.
Parameters:
$name
(string): Name of event
Returns:
- (bool): Returns
true
if the hook existed
Example:
doEvent
Description:
Execute queued hooks for a given event in order of priority.
Parameters:
$name
(string): Name of event...$arg
(mixed): Optional additional argument(s) to be passed to the functions hooked to the event
Returns:
- (void)
Example:
addFilter
Description:
Adds a hook for a given filter name.
Parameters:
$name
(string): Name of filter$function
(callable)$priority = 10
(int): Filters will be executed in order of priority in ascending order (lower numbers = earlier execution)
Returns:
- (void)
Examples:
Anonymous function
Named function
Inside class scope
Use variables from outside scope
hasFilter
Description:
Checks if any filters exist for a given name.
Parameters:
$name
(string): Name of filter
Returns:
- (bool)
Example:
getFilters
Description:
Return array of all hooks for all filters, or of a given filter name.
Parameters:
$name = NULL
(string|null): Name of filter
Returns:
- (array)
Example:
removeFilter
Description:
Removes hook from a given filter, if existing.
NOTE: Hooks using anonymous functions cannot be removed using this method
Parameters:
$name
(string): Name of filter$function
(callable): Hook to remove
Returns:
- (bool): Returns
true
if the hook existed
Example:
To remove a hook for a function from within a class scope, the $function
parameter must be an array whose first value is an instance of the class, and second value is the name of the function within the class:
removeFilters
Description:
Removes all hooks from a given filter, if existing.
Parameters:
$name
(string): Name of filter
Returns:
- (bool): Returns
true
if the hook existed
Example:
doFilter
Description:
Filters value through queued filters in order of priority.
Parameters:
$name
(string): Name of filter$value
(mixed): Original value to be filtered
Returns:
- (mixed): Filtered value
Example: