saschaende/laravel-hookable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

saschaende/laravel-hookable

Composer 安装命令:

composer require saschaende/laravel-hookable

包简介

The WordPress filter/action system in Laravel

README 文档

README

Latest Version on Packagist

Laravel Hookable is a package that allows you to use hooks (actions and filters) in Laravel applications – similar to the hook system in WordPress.

Installation

You can install the package via Composer:

composer require saschaende/laravel-hookable

The package is automatically registered by Laravel (see composer.json).

How it works

  • Actions: Execute code without modifying data (e.g., for events or extensions).
  • Filters: Allow modification of data.

The package provides a Hookable facade that exposes the main methods. The binding is handled automatically via the ServiceProvider.

Usage

Adding actions

use SaschaEnde\Hookable\Facades\Hookable;

Hookable::action('my_action', function ($arg1, $arg2) {
    // Do something with $arg1 and $arg2
});

To execute the action (e.g., at a specific point in your code):

Hookable::renderActions('my_action', $arg1, $arg2);

Adding filters

use SaschaEnde\Hookable\Facades\Hookable;

Hookable::filter('my_filter', function ($value) {
    // Modify $value
    return $value;
});

Apply the filter:

$value = Hookable::applyFilters('my_filter', $value);

Priorities and arguments

You can specify the priority and the number of arguments for hooks:

Hookable::action('my_action', function ($arg1, $arg2) {
    // Do something
}, 20);

In this example, the action will be executed with priority 20 and will receive 2 arguments.

Blade Directives

The package registers two Blade directives to use hooks directly in Blade templates:

@applyFilter('my_filter', $value)
@doAction('my_action', $arg1, $arg2)
  • @applyFilter('filter_name', $value): Applies a filter to a value and outputs the result.
  • @doAction('action_name', ...): Executes an action and outputs its result.

Testing

You can run the tests using PHPUnit:

vendor/bin/phpunit

Contributing

Contributions are welcome! Please submit a pull request or open an issue on GitHub.

License

This package is open-source software licensed under the MIT license.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固