1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66:
<?php
namespace Guzzle\Tests\Mock;
use Guzzle\Common\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MockObserver implements \Countable, EventSubscriberInterface
{
public $events = array();
public static function getSubscribedEvents()
{
return array();
}
public function has($eventName)
{
foreach ($this->events as $event) {
if ($event->getName() == $eventName) {
return true;
}
}
return false;
}
public function getLastEvent()
{
return end($this->events);
}
public function count()
{
return count($this->events);
}
public function getGrouped()
{
$events = array();
foreach ($this->events as $event) {
if (!isset($events[$event->getName()])) {
$events[$event->getName()] = array();
}
$events[$event->getName()][] = $event;
}
return $events;
}
public function getData($event, $key, $occurrence = 0)
{
$grouped = $this->getGrouped();
if (isset($grouped[$event])) {
return $grouped[$event][$occurrence][$key];
}
return null;
}
public function update(Event $event)
{
$this->events[] = $event;
}
}