PHP code example of earc / observer

1. Go to this page and download the library: Download earc/observer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

earc / observer example snippets


$ composer 

use eArc\DI\DI;

DI::init();

use eArc\Observer\Interfaces\EventInterface;
use eArc\Observer\Interfaces\ListenerInterface;

class SomeEvent implements EventInterface
{
    public static function getApplicableListener(): array
    {
        return [ListenerInterface::class];     
    }
}

use eArc\Observer\Observer;

$observer = di_get(Observer::class);

$observer->registerListener(SomeListener::class); 

use eArc\Observer\Observer;

di_tag(Observer::class, SomeListener::class); 

use eArc\Observer\Observer;

$observer = di_get(Observer::class);

$observer->registerListener(SomeListener::class, 0.2); 

use eArc\Observer\Observer;

di_tag(Observer::class, SomeListener::class, -12.7);

$observer->unregisterListener(SomeListener::class); 

use eArc\Observer\Observer;

di_clear_tags(Observer::class, SomeListener::class); 

use eArc\Observer\Dispatcher;

$dispatcher = di_get(Dispatcher::class);
$event = $dispatcher->dispatch($event); 

use \eArc\Observer\Interfaces\ObserverInterface;

di_decorate(ObserverInterface::class, TheNewObserver::class);