Hook::is()

Checks the hook name that is being executed.

Table of Contents
  1. Description
  2. Example

Description

Hook::is(?string $name = null): bool;

This method checks the name of the currently executing hook container. Useful when applied to multiple hooks executing concurrently with the same hook function. I’d rather suggest you to create an individual function for each hook container if it doesn’t seem repetitive. It’s easier to read that way.

Example

Hook::set([
    'content',
    'title',
    'type'
], static function ($v) {
    if (Hook::is('content')) {
        return '<p>' . $v . '</p>';
    }
    if (Hook::is('title')) {
        return '<h2>' . $v . '</h2>';
    }
    return $v;
});

Hook::is()

Checks the hook name that is being executed.