PHPackages                             speedyspec/speedyspec-wp-hook-domain - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. speedyspec/speedyspec-wp-hook-domain

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

speedyspec/speedyspec-wp-hook-domain
====================================

SpeedySpec Rewrite of WordPress - Hook API Domain Package

1.1.2(5mo ago)014[1 PRs](https://github.com/SpeedySpec/speedyspec-wp-hook-domain/pulls)2BSD-3-ClausePHPPHP &gt;=8.4CI passing

Since Jan 17Pushed 5mo agoCompare

[ Source](https://github.com/SpeedySpec/speedyspec-wp-hook-domain)[ Packagist](https://packagist.org/packages/speedyspec/speedyspec-wp-hook-domain)[ RSS](/packages/speedyspec-speedyspec-wp-hook-domain/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (1)Versions (7)Used By (2)

SpeedySpec WP Hook Domain
=========================

[](#speedyspec-wp-hook-domain)

A modern, domain-driven reimplementation of WordPress's Hook API (actions and filters system). This library provides a clean, testable, and extensible architecture for event-driven programming with full backwards compatibility with WordPress's plugin API.

Features
--------

[](#features)

- **Domain-Driven Design**: Clean separation of concerns with contracts, entities, value objects, and services
- **Testable Architecture**: Dependency injection and interface-based design make testing straightforward
- **WordPress Compatible**: Drop-in replacement for WordPress's `add_filter()`, `do_action()`, and related functions
- **Type-Safe**: Full PHP 8.4+ type declarations with strict types
- **Extensible**: Implement your own storage backends (memory, database, etc.)
- **Flexible Callbacks**: Support for dedicated action and filter callback types

Requirements
------------

[](#requirements)

- PHP 8.4 or higher

Installation
------------

[](#installation)

```
composer require speedyspec/speedyspec-wp-hook-domain
```

Quick Start
-----------

[](#quick-start)

### 1. Configure the Service Container

[](#1-configure-the-service-container)

Register your infrastructure implementations with the service container:

```
use SpeedySpec\WP\Hook\Domain\HookServiceContainer;
use SpeedySpec\WP\Hook\Domain\Contracts\HookContainerInterface;
use SpeedySpec\WP\Hook\Domain\Contracts\UseCases\LegacyAddFilterUseCaseInterface;
// ... other interfaces

$container = HookServiceContainer::getInstance();

// Register your implementations
$container->add(HookContainerInterface::class, fn($c) => new YourHookContainer());
$container->add(LegacyAddFilterUseCaseInterface::class, fn($c) => new YourAddFilterUseCase());
// ... register other use cases
```

### 2. Use the Legacy API (WordPress-Compatible)

[](#2-use-the-legacy-api-wordpress-compatible)

Once configured, include the functions file and use the familiar WordPress API:

```
require_once 'vendor/speedyspec/speedyspec-wp-hook-domain/functions/plugins.php';

// Add a filter using a named function
function my_content_modifier($value) {
    return $value . ' modified';
}
add_filter('my_filter', 'my_content_modifier');

// Apply the filter
$result = apply_filters('my_filter', 'original');
// Result: 'original modified'

// Add an action using an object method
class MyPlugin {
    public function handleAction($arg) {
        echo "Action fired with: $arg";
    }
}
$plugin = new MyPlugin();
add_action('my_action', [$plugin, 'handleAction']);

// Fire the action
do_action('my_action', 'hello');
// Output: Action fired with: hello
```

> **Warning: Never use anonymous closures with the legacy API**
>
> ```
> // DO NOT DO THIS - closures cannot be removed!
> add_filter('my_filter', function($value) {
>     return $value . ' modified';
> });
> ```
>
>
>
> Anonymous closures cannot be removed with `remove_filter()` or `remove_action()` because each closure has a unique internal identifier. Always use named functions, static methods, or object methods that can be referenced for removal.

### 3. Use the Modern API (Domain Objects)

[](#3-use-the-modern-api-domain-objects)

For new code, use the domain objects directly. Priority is now built into the callback entities:

```
use SpeedySpec\WP\Hook\Domain\HookServiceContainer;
use SpeedySpec\WP\Hook\Domain\Contracts\HookContainerInterface;
use SpeedySpec\WP\Hook\Domain\ValueObject\StringHookName;
use SpeedySpec\WP\Hook\Domain\Entities\ObjectHookInvoke;

$container = HookServiceContainer::getInstance();
$hooks = $container->get(HookContainerInterface::class);

// Add a filter with priority 10 (default)
$hookName = new StringHookName('my_filter');
$callback = new ObjectHookInvoke(fn($value) => strtoupper($value));

$hooks->add($hookName, $callback);

// Add a filter with custom priority
$highPriorityCallback = new ObjectHookInvoke(
    fn($value) => $value . '!',
    priority: 5  // Runs before priority 10
);
$hooks->add($hookName, $highPriorityCallback);

// Apply the filter
$result = $hooks->filter($hookName, 'hello');
// Result: 'HELLO!' (priority 5 runs first, then priority 10)
```

Architecture Overview
---------------------

[](#architecture-overview)

 ```
graph TB
    subgraph "Legacy Functions API"
        A[add_filter / do_action / apply_filters]
    end

    subgraph "Use Case Layer"
        B[LegacyAddFilterUseCaseInterface]
        C[LegacyDispatchFilterHookUseCaseInterface]
        D[LegacyDispatchActionHookUseCaseInterface]
    end

    subgraph "Domain Layer"
        E[HookContainerInterface]
        F[HookSubjectInterface]
        G[Entities: StringHookInvoke, ArrayHookInvoke, ObjectHookInvoke]
        H[Value Objects: StringHookName, ClassNameHookName]
    end

    subgraph "Infrastructure Layer"
        I[MemoryHookContainer]
        J[WP_Hook Integration]
    end

    A --> B
    A --> C
    A --> D
    B --> E
    C --> E
    D --> E
    E --> F
    E --> G
    E --> H
    E -.-> I
    E -.-> J
```

      Loading ### Directory Structure

[](#directory-structure)

```
src/
├── Contracts/              # Interfaces defining the API
│   ├── HookContainerInterface.php
│   ├── HookPriorityInterface.php
│   ├── HookSubjectInterface.php
│   ├── HookInvokableInterface.php
│   ├── HookNameInterface.php
│   ├── HookActionInterface.php
│   ├── HookFilterInterface.php
│   ├── HookValidationInterface.php
│   ├── CalledDeprecatedHookInterface.php
│   ├── CurrentHookInterface.php
│   ├── HookRunAmountInterface.php
│   └── UseCases/
│       └── Legacy*UseCaseInterface.php
├── Entities/               # Callback wrappers (with built-in priority)
│   ├── StringHookInvoke.php
│   ├── ArrayHookInvoke.php
│   └── ObjectHookInvoke.php
├── ValueObject/            # Immutable value types
│   ├── StringHookName.php
│   └── ClassNameHookName.php
├── Services/               # Domain services
│   ├── CurrentHookService.php
│   └── HookRunAmountService.php
├── Exceptions/             # Domain exceptions
│   └── HookIsNotCallableException.php
└── HookServiceContainer.php  # Dependency injection container

functions/
└── plugins.php             # WordPress-compatible function API

```

Documentation
-------------

[](#documentation)

For comprehensive documentation, see the [docs](./docs) directory:

- [Architecture](./docs/architecture.md) - Design principles and patterns
- [Contracts](./docs/contracts.md) - Interface documentation
- [Entities](./docs/entities.md) - Callback wrapper classes
- [Value Objects](./docs/value-objects.md) - Immutable value types
- [Services](./docs/services.md) - Domain services
- [Legacy API](./docs/legacy-api.md) - WordPress-compatible functions

Related Packages
----------------

[](#related-packages)

- `speedyspec/speedyspec-wp-hook-infra-memory` - In-memory implementation
- `speedyspec/speedyspec-wp-hook-infra-wp` - WordPress integration

License
-------

[](#license)

BSD-3-Clause

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance72

Regular maintenance activity

Popularity6

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

161d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/314942?v=4)[Jacob Santos](/maintainers/jacobsantos)[@jacobsantos](https://github.com/jacobsantos)

---

Top Contributors

[![jacobsantos](https://avatars.githubusercontent.com/u/314942?v=4)](https://github.com/jacobsantos "jacobsantos (33 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/speedyspec-speedyspec-wp-hook-domain/health.svg)

```
[![Health](https://phpackages.com/badges/speedyspec-speedyspec-wp-hook-domain/health.svg)](https://phpackages.com/packages/speedyspec-speedyspec-wp-hook-domain)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
