Recommend this page to a friend! |
Classes of Josantonius | PHP Hook Function Call | README.md | Download |
|
DownloadPHP Hook libraryLibrary for handling hooks.
RequirementsThis library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher. InstallationThe preferred way to install this extension is through Composer. To install PHP Hook library, simply:
The previous command will only install the necessary files, if you prefer to download the entire source code you can use:
You can also clone the complete repository with Git: $ git clone https://github.com/Josantonius/PHP-Hook.git Or install it manually:
Available MethodsAvailable methods in this library: - Get Hook instance:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $id | Unique ID for multiple instances. | string | No | '0' | # Return (object) ? Hook instance - Set method name for use singleton pattern:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $method | Set method name for use singleton pattern. | callable | No | | # Return (void) - Attach custom function to action hook:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $tag | Action hook name. | string | Yes | | | $function | Function to attach to action hook. | callable | Yes | | | $priority | Order in which the action is executed. | int | No | 8 | | $args | Number of arguments accepted. | int | No | 0 | # Return (boolean) - Add actions hooks from array:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $actions | Actions hooks | array | Yes | | # Return (boolean) - Run all hooks attached to the hook:By default it will look for getInstance method to use singleton pattern and create a single instance of the class. If it does not exist it will create a new object.
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $tag | Action hook name | string | Yes | | | $args | Optional arguments | mixed | No | array() | | $remove | Delete hook after executing actions | boolean | No | true | # Return (mixed|false) ? output of the last action or false - Returns the current action hook:
# Return (string|false) ? current action hook - Check if there is a certain action hook:
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $tag | Action hook name | string | Yes | | # Return (boolean) Quick StartTo use this library with Composer:
Or If you installed it manually, use it:
UsageExample of use for this library: - Add action hook:
- Add action hook with priority:
- Add action hook with priority and arguments number:
- Add action hook and set singleton method:
- Add multiple action hooks:
- Add multiple action hooks and set singleton method:
- Check if is action:
- Execute action hooks:
- Execute action hook with arguments:
TestsTo run tests you just need composer and to execute the following:
Run unit tests with PHPUnit:
Run PSR2 code standard tests with PHPCS:
Run PHP Mess Detector tests to detect inconsistencies in code style:
Run all previous tests:
? TODO
ContributeIf you would like to help, please take a look at the list of issues or the To Do checklist. Pull requests
RepositoryThe file structure from this repository was created with PHP-Skeleton. LicenseThis project is licensed under MIT license. See the LICENSE file for more info. Copyright2017 - 2018 Josantonius, josantonius.com If you find it useful, let me know :wink: |