for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @link https://github.com/Izumi-kun/yii2-longpoll
* @copyright Copyright (c) 2017 Viktor Khokhryakov
* @license http://opensource.org/licenses/BSD-3-Clause
*/
namespace izumi\longpoll;
use Yii;
use yii\base\BaseObject;
use yii\base\InvalidConfigException;
* Class EventCollection
* @property EventInterface[] $events array of events.
* @author Viktor Khokhryakov <[email protected]>
class EventCollection extends BaseObject implements EventCollectionInterface
{
* @var EventInterface[] array of events (key => event).
private $_events = [];
* @var string event class name.
public $eventClass = Event::class;
* @inheritdoc
* @throws InvalidConfigException
public function addEvent($event)
if (!$event instanceof EventInterface) {
if (!is_array($event)) {
$event = [
'class' => $this->eventClass,
'key' => $event,
];
}
$event = Yii::createObject($event);
throw new InvalidConfigException('The event should be an instance of "\izumi\longpoll\EventInterface".');
$this->_events[$event->getKey()] = $event;
return $event;
public function getEvents()
return $this->_events;
public function setEvents($events)
$this->_events = [];
if (!is_array($events)) {
$events = [$events];
foreach ($events as $event) {
$this->addEvent($event);