public function testGetDbWorksWithLateStaticBinding() { $this->assertSame(null, EventTrackerEvent::getDb()); $connection = new Connection(); EventTrackerEvent::$db = $connection; $this->assertSame($connection, EventTrackerEvent::getDb()); }
/** * Initializes a new event tracker object. * * @throws InvalidConfigException If invalid configurations are set. */ public function init() { parent::init(); if (null === $this->types_config || null === $this->keys_config) { throw new InvalidConfigException('Both $types_config and $keys_config should be set for the EventTracker'); } $event_types_instance = Yii::createObject($this->types_config); if (!$event_types_instance instanceof BaseEventTypes) { throw new InvalidConfigException('$types_config should indicate a class subclassing BaseEventTypes to specify the event types.'); } $state_keys_instance = Yii::createObject($this->keys_config); if (!$state_keys_instance instanceof BaseStateKeys) { throw new InvalidConfigException('$keys_config should indicate a class subclassing BaseStateKeys to specify the state keys.'); } $this->_state_keys = $state_keys_instance; $this->_event_types = $event_types_instance; $this->db = Instance::ensure($this->db, Connection::className()); if (null !== $this->post_event_handler) { $handler = Yii::createObject($this->post_event_handler); if (!$handler instanceof PostEventInterface) { throw new InvalidConfigException('$post_event_handler should indicate a class implementing the PostEventInterface.'); } $this->_post_event_handler = $handler; } EventTrackerEvent::$db = $this->db; EventTrackerEvent::$table = $this->event_table; }