neuron-php / patterns
PHP Patterns.
Installs: 13 803
Dependents: 5
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- ext-curl: *
- ext-json: *
- neuron-php/data: 0.6.*
Requires (Dev)
- phpmd/phpmd: ^2.15
- phpunit/phpunit: 9.*
README
About Neuron PHP
Patterns
Criteria
Observer
An ObserverableTrait and IObserver interface make up the Observer pattern implementation.
class Observable
{
use ObservableTrait;
public function updated()
{
$this->notifyObservers( 1, 2, 3 );
}
}
class Observer implements IObserver
{
public $State = 0;
// IObserver implementation method..
public function observableUpdate( $Observable, ...$param )
{
// Will set $State to 1.
$this->State = $param[ 0 ];
}
}
$Observer = new Observer;
$Observable = new Observable;
$Observable->addObserver( $Observer );
$Observable->updated();
// Will notify all attached observers..
// Later on, clean up..
$Observable->removeObserver( $Observer );