Download the PHP package kristos80/hook without Composer

On this page you can find all versions of the php package kristos80/hook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hook

🪝 Hook

A lightweight, WordPress-style hooks system for PHP. Add actions and filters with priority support to create extensible, event-driven applications.


Quality Gate Status Bugs Coverage Reliability Rating Security Rating Maintainability Rating Vulnerabilities

Features

Requirements

Installation

Usage

Basic Filter

Priority-based Execution

Lower priority numbers run first (default is 10):

Actions

Actions are filters that don't return values:

Multiple Arguments

Multiple Hook Names

Register the same callback to multiple hooks at once:

Per-Hook Priority

When registering multiple hook names, you can assign a different priority to each hook by passing an array of priorities. Each hook name is mapped to the priority at the same index, with a fallback to the first priority if the index doesn't exist:

Callable Types

The library accepts any valid PHP callable:

Enforcing Type Hints on Callbacks

Use the requireTypedParameters named argument to enforce that all callback parameters have type hints:

The requireTypedParameters argument is stripped and never passed to callbacks. This feature helps enforce stricter contracts when the hook owner wants to ensure all registered callbacks follow type safety conventions.

Priority Constants

Use HookInterface::FIRST and HookInterface::LAST to guarantee a callback runs before or after all others:

The constants are also accessible via Hook::FIRST and Hook::LAST. Multiple callbacks at the same constant priority follow FIFO order, consistent with the rest of the priority system.

Priority Introspection

Query the lowest or highest registered priority for a given hook:

Exceptions

Every exception the library throws extends the abstract HookException, so a single catch (HookException $e) will trap any hook-related failure:

Exception Thrown by When
CircularDependencyException applyFilter() / doAction() A hook is dispatched while it is already on the running stack (a callback for X re-triggers X).
InvalidPriorityException addFilter() / addAction() A resolved priority is not an integer.
MissingTypeHintException applyFilter() / doAction() requireTypedParameters: true was passed and a registered callback has an untyped parameter.
HookException (abstract base) — Never thrown directly; use it as a catch-all supertype.

API Reference

addFilter(string|array $hookNames, callable $callback, int|array $priority = 10): void

Add a filter callback to one or more hooks.

addAction(string|array $hookNames, callable $callback, int|array $priority = 10): void

Alias for addFilter(). Use for hooks that don't return values.

Note: The $acceptedArgs parameter exists for backwards compatibility but is deprecated and no longer used. PHP natively handles argument count validation.

applyFilter(string $hookName, ...$arg): mixed

Execute all callbacks registered to a filter hook.

doAction(string $hookName, ...$arg): void

Execute all callbacks registered to an action hook.

HookInterface::FIRST / HookInterface::LAST

Priority constants for guaranteed earliest (PHP_INT_MIN) and latest (PHP_INT_MAX) execution. Also accessible as Hook::FIRST / Hook::LAST.

getMinPriority(string $hookName): ?int

Get the lowest registered priority for a hook.

getMaxPriority(string $hookName): ?int

Get the highest registered priority for a hook.

Interface-based Design

The Hook class implements HookInterface, providing several benefits:

Testing & Static Analysis

The project is held to three gates that all pass at 100%:

Substitute herd coverage with your own coverage driver (Xdebug, PCOV) if you are not on Laravel Herd.

License

MIT

Author

Christos Athanasiadis - [email protected]


All versions of hook with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kristos80/hook contains the following files

Loading the files please wait ...