Last active
August 24, 2021 11:08
-
-
Save sukei/9070924 to your computer and use it in GitHub Desktop.
An Observer in a Tweet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The Signal class is the smallest and fastest observer written in PHP 5.6 and | |
* using some new features such as the variadic functions and the arguments | |
* unpacking. | |
* | |
* ...and it fits in a tweet. | |
* | |
* @author Quentin Schuler aka Sukei <[email protected]> | |
*/ | |
class Signal { | |
private $c = []; | |
function listen($c) { $this->c[] = $c; } | |
function notify(...$a) { foreach ($this->c as $c) $c(...$a); } | |
} |
Author
sukei
commented
Feb 18, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment