speedyspec/speedyspec-wp-hook-infra-memory 问题修复 & 功能扩展

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

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

speedyspec/speedyspec-wp-hook-infra-memory

最新稳定版本:0.0.4

Composer 安装命令:

composer require speedyspec/speedyspec-wp-hook-infra-memory

包简介

SpeedySpec Rewrite of WordPress - Hook API Infrastructure Memory Package

README 文档

README

An in-memory implementation of the WordPress hook system for the SpeedySpec WP Hook Domain package. This package provides lightweight, fast hook storage suitable for testing, CLI applications, and scenarios where persistent hook storage is not required.

Note: Version 1.x is not semver-compatible and should not be considered stable. Consider the 1.0 version 0.x for usage purposes. Version 2.x will be semver-compatible.

Installation

composer require speedyspec/speedyspec-wp-hook-infra-memory

Requirements

  • PHP 8.4 or higher
  • speedyspec/speedyspec-wp-hook-domain ^1.0

Quick Start

Basic Setup

use SpeedySpec\WP\Hook\Domain\HookServiceContainer;
use SpeedySpec\WP\Hook\Domain\Contracts\HookContainerInterface;
use SpeedySpec\WP\Hook\Domain\Contracts\CurrentHookInterface;
use SpeedySpec\WP\Hook\Domain\Contracts\HookRunAmountInterface;
use SpeedySpec\WP\Hook\Domain\Services\CurrentHookService;
use SpeedySpec\WP\Hook\Domain\Services\HookRunAmountService;
use SpeedySpec\WP\Hook\Infra\Memory\Services\MemoryHookContainer;

// Get the service container
$container = HookServiceContainer::getInstance();

// Register the memory infrastructure services (using interfaces for flexibility)
$container->add(HookRunAmountInterface::class, fn() => new HookRunAmountService());
$container->add(CurrentHookInterface::class, fn() => new CurrentHookService());
$container->add(
    HookContainerInterface::class,
    fn($c) => new MemoryHookContainer(
        $c->get(HookRunAmountInterface::class),
        $c->get(CurrentHookInterface::class)
    )
);

// Now use the hook system
$hooks = $container->get(HookContainerInterface::class);

Using the ServiceProvider

For convenience, you can use the included service provider:

use SpeedySpec\WP\Hook\Infra\Memory\ServiceProvider;
use SpeedySpec\WP\Hook\Domain\HookServiceContainer;
use SpeedySpec\WP\Hook\Domain\Contracts\CalledDeprecatedHookInterface;
use SpeedySpec\WP\Hook\Infra\Memory\Services\CalledDeprecatedHook;

$provider = new ServiceProvider();
$provider->register();

// If you need deprecated hook support, register CalledDeprecatedHook
$container = HookServiceContainer::getInstance();
$container->add(
    CalledDeprecatedHookInterface::class,
    fn() => new CalledDeprecatedHook()
);

// Services are now registered and ready to use

Adding and Executing Hooks

use SpeedySpec\WP\Hook\Domain\Entities\ObjectHookInvoke;
use SpeedySpec\WP\Hook\Domain\ValueObject\StringHookName;

// Get the hook container
$hooks = HookServiceContainer::getInstance()->get(HookContainerInterface::class);

// Add a filter callback
$callback = new ObjectHookInvoke(
    fn(string $value) => strtoupper($value),
    priority: 10
);
$hooks->add(new StringHookName('my_filter'), $callback);

// Apply the filter
$result = $hooks->filter(new StringHookName('my_filter'), 'hello');
// Result: 'HELLO'

// Add an action callback
$actionCallback = new ObjectHookInvoke(
    fn(string $message) => error_log($message),
    priority: 10
);
$hooks->add(new StringHookName('my_action'), $actionCallback);

// Dispatch the action
$hooks->dispatch(new StringHookName('my_action'), 'Something happened');

When to Use This Package

Use this package when:

  • Writing unit or integration tests
  • Building CLI applications
  • Creating lightweight scripts
  • Prototyping hook-based features
  • Running in environments where hook state doesn't need persistence

Consider alternatives when:

  • You need hooks to persist across requests
  • You're building a full WordPress-compatible application
  • You need the WP_Hook class compatibility

Documentation

For comprehensive documentation, see the docs directory:

  • Services - Detailed documentation of MemoryHookContainer and MemoryHookSubject
  • Testing - How to use this package in your tests
  • Examples - Common usage patterns and recipes

Testing

composer install
./vendor/bin/pest

License

BSD-3-Clause

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固