mibadger/observer

This package is abandoned and no longer maintained. No replacement package was suggested.

The Observer Component

v3.0.0 2021-08-12 09:32 UTC

This package is auto-updated.

Last update: 2022-11-19 17:10:16 UTC


README

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

The Observer Component.

Example

<?php

use miBadger\Observer\ObserverInterface;
use miBadger\Observer\SubjectInterface;
use miBadger\Observer\SubjectTrait;

/**
 * The observer class.
 */
class Observer implements ObserverInterface
{
	/**
	 * {@inheritdoc}
	 */
	public function update(SubjectInterface $subject, $arguments = null)
	{
		echo 'test';
	}
}

/**
 * The subject class.
 */
class Subject implement SubjectInterface
{
	use SubjectTrait;
}
<?php

/**
 * Create a new subject.
 */
$subject = new Subject();

/**
 * Create a new observer.
 */
$observer = new Observer()

/**
 * Attach observer.
 */
$subject->attach($observer);

/**
 * Notify the attached observers.
 */
$subject->notify();