Skip to content

iCalcreator/HookMgr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Class HookMgr manages PHP hooks

A hook is a (HookMgr) key for invoking callable(s)

A callable can be

  • simple function
  • anonymous function
  • instantiated object+method : [ $object, 'methodName' ]
  • class name and static method : [ 'namespaceClassName', 'methodName' ]
  • instantiated object, class with (magic) __call method : [ $object, 'someMethod' ]
  • class name, class with (magic) __callStatic method : [ 'namespaceClassName', 'someMethod' ]
  • instantiated object, class with (magic) __invoke method : $object

Define a hook with callable

HookMgr::addAction( $hook, $callable );

Invoke callable using hook

$result = HookMgr::apply( $hook );
Methods

HookMgr::addAction( hook, callable )

  • Add single hook with single callable, syntax_only callable check
  • hook string
  • callable callable
  • Throws InvalidArgumentException
  • static

HookMgr::addActions( hook, callables )

  • Add single hook invoking an array of callables
  • Note, if invoked with arguments, arguments are used for all callables
  • hook string
  • callables callable[]
  • Throws InvalidArgumentException
  • static

HookMgr::setActions( actions )

  • Set all hooks, each for invoking single or array of callables
  • actions array *( hook => callable(s) )
  • Throws InvalidArgumentException
  • static

HookMgr::apply( hook [, args ] )

  • Invoke 'hook' action(s), return (last) result
  • hook string
  • args array opt, [ arg1, arg2... ]
    • Opt arguments are used in all hook invokes
    • To use an argument by-reference, use HookMgr::apply( 'hook', [ & $arg ] );
  • Return mixed
  • Throws RuntimeException
  • static

HookMgr::count( hook )

  • Return count of callables for hook, not found return 0
  • hook string
  • Return bool
  • static

HookMgr::exists( hook )

  • Return bool true if hook is set
  • hook string
  • Return bool
  • static

HookMgr::getCallables( hook )

  • Return array callables for hook, not found return []
  • hook string
  • Return callable[]
  • static

HookMgr::getHooks()

  • Return array (string[]) hooks
  • static

HookMgr::init()

  • Clear (remove) all hooks with callables
  • static

HookMgr::remove( hook )

  • Remove single hook with callable(s)
  • hook string
  • static

HookMgr::toString()

  • Return string nice rendered hooks with callable(s)
  • static
Sponsorship

Donation using paypal.me/kigkonsult are appreciated. For invoice, please e-mail.

INSTALL
composer require kigkonsult/hookmgr:dev-master

Composer, in your composer.json:

{
    "require": {
        "kigkonsult/hookmgr": "dev-master"
    }
}

Version 1.4 supports PHP 8, 1.2 7.4, 1.1 7.0.

Composer, acquire access

use Kigkonsult\HookMgr\HookMgr;
...
include 'vendor/autoload.php';

Otherwise , download and acquire..

use Kigkonsult\HookMgr\HookMgr;
...
include 'pathToSource/kigkonsult/HookMgr/autoload.php';
Support

For support go to github.com HookMgr

License

This project is licensed under the LGPLv3 License

About

PHP hook callables manager

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages