mibadger/observer

v1.0.1 2016-07-14 09:14 UTC

README

Build Status Code Coverage Scrutinizer Code Quality

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