- Notifications
You must be signed in to change notification settings - Fork1
Inspired by@WordPress Hooks (filters and actions) into modern PHP Hooks system
License
simplemediacode/hooks
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A lightweight, dependency-free implementation of an action and filter hook system inspired by WordPress hooks but designed for modern PHP applications.
- Modern PHP Support: Fully typed, supports PHP 8.0+
- Dependency Injection Ready: Use the
HooksInterfacein your classes - Static Facade: Convenient static methods for quick integration
- No Dependencies: Lightweight implementation with zero dependencies
- WordPress Inspired: Familiar API if you're coming from WordPress
Viacomposer:
composer require simplemediacode/hooks
useSimplemediacode\Hooks\Hooks;// Add a filterHooks::addFilter('content',function($content) {returnstrtoupper($content);});// Apply a filter$content = Hooks::applyFilters('content','Hello World');// Returns "HELLO WORLD"// Add an actionHooks::addAction('save_post',function($postId) {// Do something when a post is savedecho"Post{$postId} was saved!";});// Execute an actionHooks::doAction('save_post',123);
useSimplemediacode\Hooks\HooksInterface;class MyClass{private ?HooksInterface$hooks;publicfunction__construct( ?HooksInterface$hooks =null ) {$this->hooks =$hooks; }publicfunctionprocessContent(string$content):string {// If hooks are available, filter the contentif ($this->hooks) {$content =$this->hooks->executeHook('content',$content); }return$content; }}
You can implement your own version ofHooksInterface to provide custom hook functionality:
$customHooks =newMyCustomHooksImplementation();Hooks::setInstance($customHooks);
This package is a complete rewrite of the original WordPress hook system. Key differences:
- Renamed
WP_HooktoHook - Introduced proper interfaces for better type safety
- Added dependency injection support
- Replaced global variables with proper class properties
- Improved naming conventions and method signatures
Read atCHANGELOG.md.
This library is released under the GPL-2.0 license. See the complete license in the bundledLICENSE file.
About
Inspired by@WordPress Hooks (filters and actions) into modern PHP Hooks system
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.