定制 nahid/hookr 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nahid/hookr

Composer 安装命令:

composer require nahid/hookr

包简介

php hook system for binding any service in a action

README 文档

README

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.

nahid/hookr 适用场景与选型建议

nahid/hookr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 392 次下载、GitHub Stars 达 42, 最近一次更新时间为 2017 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 nahid/hookr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nahid/hookr 我们能提供哪些服务?
定制开发 / 二次开发

基于 nahid/hookr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 392
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 42
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 42
  • Watchers: 4
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-08