neuron-php/patterns

PHP Patterns.

0.6.2 2024-12-16 17:54 UTC

This package is auto-updated.

Last update: 2024-12-16 17:55:08 UTC


README

Build Status

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 );

Registry

Singleton