/usr/share/php/Kdyby/Events/LazyEventManager.php is in php-kdyby-events 2.4.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | <?php
/**
* This file is part of the Kdyby (http://www.kdyby.org)
*
* Copyright (c) 2008 Filip Procházka (filip@prochazka.su)
*
* @license http://www.kdyby.org/license
*/
namespace Kdyby\Events;
use Doctrine;
use Kdyby;
use Nette;
/**
* Is aware of DI Container and accepts map of listener service ids which then loads when needed.
*
* @author Filip Procházka <filip@prochazka.su>
*/
class LazyEventManager extends EventManager
{
/**
* @var array
*/
private $listenerIds;
/**
* @var \Nette\DI\Container
*/
private $container;
/**
* @param array $listenerIds
* @param \Nette\DI\Container $container
*/
public function __construct(array $listenerIds, Nette\DI\Container $container)
{
$this->listenerIds = $listenerIds;
$this->container = $container;
}
public function setPanel(Diagnostics\Panel $panel)
{
parent::setPanel($panel);
$panel->setServiceIds($this->listenerIds);
}
/**
* @param string $eventName
* @param bool $asCallbacks
* @return \Doctrine\Common\EventSubscriber[]
*/
public function getListeners($eventName = NULL)
{
if (!empty($this->listenerIds[$eventName])) {
$this->initializeListener($eventName);
}
if ($eventName === NULL) {
while (($type = key($this->listenerIds)) !== NULL) {
$this->initializeListener($type);
}
}
return parent::getListeners($eventName);
}
/**
* @param array|string $unsubscribe
* @param Doctrine\Common\EventSubscriber|array $subscriber
*/
public function removeEventListener($unsubscribe, $subscriber = NULL)
{
foreach ((array) $unsubscribe as $eventName) {
if (array_key_exists($eventName, $this->listenerIds)) {
$this->initializeListener($eventName);
}
}
parent::removeEventListener($unsubscribe, $subscriber);
}
/**
* @param string $eventName
*/
private function initializeListener($eventName)
{
foreach ($this->listenerIds[$eventName] as $serviceName) {
$subscriber = $this->container->getService($serviceName);
/** @var Doctrine\Common\EventSubscriber $subscriber */
$this->addEventSubscriber($subscriber);
}
unset($this->listenerIds[$eventName]);
}
}
|