Download .zip |
Info | Documentation | View files (15) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2018-05-07 (4 months ago) | Not yet rated by the users | Total: 97 This week: 1 | All time: 9,029 This week: 468 |
Version | License | PHP version | Categories | |||
php-hook 1.0.8 | MIT/X Consortium ... | 5.6 | PHP 5, Language |
Description | Author | |
This package can register hooks and execute associated actions. |
Library for handling hooks.
This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.
The preferred way to install this extension is through Composer.
To install PHP Hook library, simply:
$ composer require Josantonius/Hook
The previous command will only install the necessary files, if you prefer to download the entire source code you can use:
$ composer require Josantonius/Hook --prefer-source
You can also clone the complete repository with Git:
$ git clone https://github.com/Josantonius/PHP-Hook.git
Or install it manually:
$ wget https://raw.githubusercontent.com/Josantonius/PHP-Hook/master/src/Hook.php
Available methods in this library:
Hook::getInstance();
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $id | Unique ID for multiple instances. | string | No | '0' |
# Return (object) ? Hook instance
Hook::setSingletonName($method);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $method | Set method name for use singleton pattern. | callable | No | |
# Return (void)
Hook::addAction($tag, $function, $priority, $args);
| 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)
Hook::addActions($actions);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $actions | Actions hooks | array | Yes | |
# Return (boolean)
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.
Hook::doAction($tag, $args, $remove);
| 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
Hook::current();
# Return (string|false) ? current action hook
Hook::isAction($tag);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $tag | Action hook name | string | Yes | |
# Return (boolean)
To use this library with Composer:
require __DIR__ . '/vendor/autoload.php';
use Josantonius\Hook\Hook;
Or If you installed it manually, use it:
require_once __DIR__ . '/Hook.php';
use Josantonius\Hook\Hook;
Example of use for this library:
Hook::addAction('css', ['Josantonius\Hook\Test\Example', 'css']);
Hook::addAction('js', ['Josantonius\Hook\Test\Example', 'js'], 1);
$instance = new Example;
Hook::addAction('meta', [$instance, 'meta'], 2, 1);
Hook::setSingletonName('singletonMethod');
$instance = call_user_func(
'Josantonius\Hook\Test\Example::singletonMethod'
);
Hook::addAction('article', [$instance, 'article'], 3, 0);
$instance = new Example;
Hook::addActions([
['after-body', [$instance, 'afterBody'], 4, 0],
['footer', [$instance, 'footer'], 5, 0],
]);
Hook::setSingletonName('singletonMethod');
$instance = call_user_func(
'Josantonius\Hook\Test\Example::singletonMethod'
);
Hook::addActions([
['slide', [$instance, 'slide'], 6, 0],
['form', [$instance, 'form'], 7, 2],
]);
Hook::setSingletonName('singletonMethod');
Hook::isAction('meta');
Hook::doAction('css');
Hook::doAction('js');
Hook::doAction('after-body');
Hook::doAction('article');
Hook::doAction('footer');
Hook::doAction('meta', 'The title');
Hook::doAction('form', ['input', 'select']);
To run tests you just need composer and to execute the following:
$ git clone https://github.com/Josantonius/PHP-Hook.git
$ cd PHP-Hook
$ composer install
Run unit tests with PHPUnit:
$ composer phpunit
Run PSR2 code standard tests with PHPCS:
$ composer phpcs
Run PHP Mess Detector tests to detect inconsistencies in code style:
$ composer phpmd
Run all previous tests:
$ composer tests
If you would like to help, please take a look at the list of issues or the To Do checklist.
Pull requests
composer install
to install the dependencies.
This will also install the dev dependencies.composer fix
to excute code standard fixers.The file structure from this repository was created with PHP-Skeleton.
This project is licensed under MIT license. See the LICENSE file for more info.
2017 - 2018 Josantonius, josantonius.com
If you find it useful, let me know :wink:
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 file) | ||||
tests (2 files) | ||||
.editorconfig | Data | Auxiliary data | ||
.php_cs.dist | Example | Example script | ||
.travis.yml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONDUCT.md | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.xml | Data | Auxiliary data | ||
phpmd.xml | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
README-ES.md | Doc. | Documentation | ||
README.md | Doc. | Documentation |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.