2017 © Pedro Peláez
 

library hookr

php hook system for binding any service in a action

image

nahid/hookr

php hook system for binding any service in a action

  • Sunday, July 15, 2018
  • by nahid
  • Repository
  • 2 Watchers
  • 4 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 75 % Grown

The README.md

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., (*1)

Installation

Write these command from you terminal., (*2)

composer require nahid/hookr

Laravel Configuration

After complete installation go to config/app.php and add this line in providers section, (*3)

Nahid\Hookr\HookrServiceProvider::class,

and add this line in aliases section, (*4)

'Hook'  =>  Nahid\Hookr\Facades\Hook::class,

Thats all, (*5)

Usages

Its so easy to use. Just follow the instruction and apply with your laravel project., (*6)

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., (*7)

```html , (*8)

{{hook_action('buttons')}}

```, (*9)

Demo, (*10)

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, (*11)

```php use Nahid\Hookr\Facades\Hook;, (*12)

class BlogController extends Controller { public function getWritePost() { Hook::bindAction('buttons', function() { echo ' '; }, 2);, (*13)

        return view('post');
   }

} ```, (*14)

After run this code add new button will add with existing button., (*15)

Demo, (*16)

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., (*17)

  <h1>{{$blog->title}}</h1>
  <p>
  {{hook_filter('posts', $blog->content)}}
  </p>

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., (*18)

```php use Nahid\Hookr\Facades\Hook;, (*19)

class BlogController extends Controller { public function getPosts() { Hook::bindFilter('posts', function($data) { return parse_markdown($data); }, 2);, (*20)

        return view('post');
   }

} ```, (*21)

Note: In filter, every callback function must have at least one param which is represent current data, (*22)

so if you want to bind multiple data then, (*23)

```php use Nahid\Hookr\Facades\Hook;, (*24)

class BlogController extends Controller { public function getPosts() { Hook::bindFilter('posts', function($data) { return parse_markdown($data); }, 2);, (*25)

        Hook::bindFilter('posts', function($data) {
            return parse_bbcode($data);
        }, 3);

        return view('post');
   }

} ```, (*26)

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., (*27)

The Versions

15/07 2018

dev-master

9999999-dev

php hook system for binding any service in a action

  Sources   Download

MIT

The Requires

  • php >=5.6

 

by Nahid Bin Azhar

15/07 2018

v1.1.0

1.1.0.0

php hook system for binding any service in a action

  Sources   Download

MIT

The Requires

  • php >=5.6

 

by Nahid Bin Azhar

08/01 2017

v1.0.0

1.0.0.0

php hook system for binding any service in a action

  Sources   Download

MIT

The Requires

  • php >=5.6

 

by Nahid Bin Azhar