Download the PHP package apricity/handler without Composer
On this page you can find all versions of the php package apricity/handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download apricity/handler
More information about apricity/handler
Files in apricity/handler
Package handler
Short Description A PHP class for parsing and executing various types of handlers, including strings in the format 'Class@method', callable functions, and arrays with class and method names.
License BSD-3-Clause
Informations about the package handler
Handler
The Handler
class is responsible for triggering and parsing handlers. Handlers can be strings in the format
Class@method
, callable
functions, array
s containing a class and method name or array
s containing callable
function. The class ensures the handler is valid and can be executed with the provided variables.
Installation
Table of contents
- Usage
- API
- Handler::simpleTrigger
- Handler::trigger
- Handler::parse
- API
- Tests
- Contributing
- Changelog
- License
Handler::simpleTrigger
Executes a given handler with provided variables.
This method can handle multiple types of handlers: an array with a class and method, a callable, or a string. It attempts to execute the handler with the provided variables and returns the result. If the handler is invalid or execution fails, it throws a HandlerException.
Parameters:
array|callable|string $handler
: The handler to be executed.- It can be:
- A callable/closure function.
- A string representing a function name.
- An array containing a single string element representing a function name.
- An array containing a class and method.
- An array containing a class name and method as strings.
- It can be:
array $vars
: [optional] The variables to pass to the handler. Default is an empty array.
Returns: mixed
- The result of the handler execution.
Throws: HandlerException
- If the handler is invalid or execution fails.
Example
Handler::trigger
Triggers the execution of a given handler with provided variables.
This method first parses the handler to ensure it's in the correct format, and then executes it using the simpleTrigger method. The handler can be a string, callable, or an array. It returns the result of the handler execution.
Parameters:
array|callable|string $handler
: The handler to be executed.- It can be:
- A string in the format "Class@method".
- A string representing a function name.
- An array containing a single string element representing a function name.
- An array containing a class and method.
- An array containing a class name and method as strings.
- It can be:
array $vars
: [optional] The variables to pass to the handler. Default is an empty array.
Returns: mixed
- The result of the handler execution.
Throws: HandlerException
- If the handler is invalid or execution fails.
Example
Handler::parse
Parses a given handler into a standardized array format.
This method accepts a handler in various formats and returns it as an array. It handles strings, callables, and arrays, caching the result for future use. If the handler is invalid, it throws a HandlerException.
Parameters:
array|callable|string $handler
: The handler to be executed.- It can be:
- A string in the format "Class@method".
- A string representing a function name.
- An array containing a single string element representing a function name.
- An array containing a class and method.
- An array containing a class name and method as strings.
- It can be:
Returns: array
- The parsed handler as an array.
Throws: HandlerException
- If the handler is invalid or not found.
Example
Run tests
Contributing
We welcome contributions from the community! For guidelines on how to contribute, please refer to the CONTRIBUTING.md file.
License
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
The repository has been migrated from GitLab.