Skip to content

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

License

Notifications You must be signed in to change notification settings

mensbeam/SelfSealingCallable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages