https://github.com/nahid/hookr
PHP action and filter hook system
https://github.com/nahid/hookr
action filter hook hookr hooks laravel php
Last synced: about 1 year ago
JSON representation
PHP action and filter hook system
- Host: GitHub
- URL: https://github.com/nahid/hookr
- Owner: nahid
- Created: 2017-01-05T05:31:49.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-10T11:46:47.000Z (over 7 years ago)
- Last Synced: 2025-04-13T16:07:56.285Z (about 1 year ago)
- Topics: action, filter, hook, hookr, hooks, laravel, php
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 42
- Watchers: 4
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# PHP hookr
A PHP package for action and filter hook. Its helps to you fire any event with your desire action. Its a similar service as WP action and filter.
## Installation
Write these command from you terminal.
```shell
composer require nahid/hookr
```
## Laravel Configuration
After complete installation go to `config/app.php` and add this line in providers section
```php
Nahid\Hookr\HookrServiceProvider::class,
```
and add this line in aliases section
```php
'Hook' => Nahid\Hookr\Facades\Hook::class,
```
Thats all
## Usages
Its so easy to use. Just follow the instruction and apply with your laravel project.
### Action
You want to extra control with your application without touching your code you apply Action. Suppose you have a blog editor panel. Where you want add extra buttons from others developer without rewrite your code.
so lets see.
```html
Title
Blog
Publish
{{hook_action('buttons')}}
```

See, here we use `hook_action()` helper function which is register as named `buttons`
So if others developer is want to add more buttons with this form they will do this
```php
use Nahid\Hookr\Facades\Hook;
class BlogController extends Controller
{
public function getWritePost()
{
Hook::bindAction('buttons', function() {
echo ' Draft';
}, 2);
return view('post');
}
}
```
After run this code add new button will add with existing button.

You can also bind multiple action with this hook. Hookr also support filter. Remind this when you bind multiple filter in a hook then every filter get data from previous filters return data. Suppose you want to add a filter hook in a blog view section.
```
{{$blog->title}}
{{hook_filter('posts', $blog->content)}}
```
So we register a filter as 'posts'. Now another developer wants to support markdown for blog posts. so he can bind a filter for parse markdown.
```php
use Nahid\Hookr\Facades\Hook;
class BlogController extends Controller
{
public function getPosts()
{
Hook::bindFilter('posts', function($data) {
return parse_markdown($data);
}, 2);
return view('post');
}
}
```
Note: In filter, every callback function must have at least one param which is represent current data
so if you want to bind multiple data then
```php
use Nahid\Hookr\Facades\Hook;
class BlogController extends Controller
{
public function getPosts()
{
Hook::bindFilter('posts', function($data) {
return parse_markdown($data);
}, 2);
Hook::bindFilter('posts', function($data) {
return parse_bbcode($data);
}, 3);
return view('post');
}
}
```
Now then given data is parse by markdown and bbcode. See, here is second param for `bindFilter()` is a priority for binding. Both `bindAction()` and `bindFilter()` has this feature.