PHP Classes

hookr: Register and call action hooks and filters

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 134 All time: 9,300 This week: 64Up
Version License PHP version Categories
hookr 1.0MIT/X Consortium ...5.6PHP 5
Description 

Author

This package can register and call action hooks and filters.

It can register callback functions that will be called when certain action events are triggered.

It can also register multiple callback functions that will be called in sequence when a filtering event is triggered.

The return value of a filter callback will be passed to the next filter that may have been registered, so the filtering actions are chained.

Picture of Nahid Bin Azhar
  Performance   Level  
Name: Nahid Bin Azhar <contact>
Classes: 24 packages by
Country: United States United States
Age: 33
All time rank: 792109 in United States United States
Week rank: 187 Up27 in United States United States Up
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

Documentation

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.

composer require nahid/hookr

Laravel Configuration

After complete installation go to config/app.php and add this line in providers section

Nahid\Hookr\HookrServiceProvider::class,

and add this line in aliases section

'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.

  <!-- post.blade.php -->
  <form>
      <div class="form-group">
          <label for="title">Title</label>
          <input type="email" class="form-control" id="title" placeholder="Email">
      </div>

      <div class="form-group">
          <label for="blog">Blog</label>
          <textarea id="blog" cols="30" rows="10" class="form-control"></textarea>
      </div>

      <button type="submit" class="btn btn-default">Publish</button>
      {{hook_action('buttons')}}
  </form>

Demo

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

  use Nahid\Hookr\Facades\Hook;
  
  class BlogController extends Controller
  {
        public function getWritePost()
        {
            Hook::bindAction('buttons', function() {
                echo ' <button class="btn btn-info">Draft</button>';
            }, 2);
            
            return view('post');
       }
  }

After run this code add new button will add with existing button.

Demo

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.

  <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.

  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

  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.


  Files folder image Files (5)  
File Role Description
Files folder imageExample (1 file)
Files folder imagesrc (1 file, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files (5)  /  Example  
File Role Description
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files (5)  /  src  
File Role Description
Files folder imagehelpers (1 file)
  Plain text file Hook.php Class Class source

  Files folder image Files (5)  /  src  /  helpers  
File Role Description
  Accessible without login Plain text file hook.php Aux. Auxiliary script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:134
This week:0
All time:9,300
This week:64Up