You won't find a better Self-Sealing Callable in this sector!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Dustin Wilson f3645a5f77 Initial commit 2 months ago
lib Initial commit 2 months ago
tests Initial commit 2 months ago
.gitignore Initial commit 2 months ago
AUTHORS Initial commit 2 months ago
LICENSE Initial commit 2 months ago
README.md Initial commit 2 months ago
composer.json Initial commit 2 months ago
composer.lock Initial commit 2 months ago
test Initial commit 2 months ago

README.md

Self-Sealing Callable

You won't find a better Self-Sealing Callable in this sector!

Self-Sealing Callable is a class that implements __invoke() which can enable and disable itself. When registering shutdown functions in PHP it's not possible to unregister them. This class exists to be used in this case. By calling SelfSealingCallable->disable() it will return false when invoked, allowing retroactive disabling of the shutdown handler.

Requirements

  • PHP 8.1

Installation

composer require mensbeam/self-sealing-callable

Usage

It's pretty simple:

use MensBeam\SelfSealingCallable;

$callable = new SelfSealingCallable(fn() => 'ook');
$ook = $callable();
// 'ook'
$callable->disable();
$ook = $callable();
// false
$callable->enable();
$ook = $callable();
// 'ook'