/** * Test the removeArgument method. * * @return void * * @since 1.0 */ public function testRemoveArgument() { $this->assertNull($this->instance->removeArgument('non-existing')); $this->instance->addArgument('foo', 'bar'); $old = $this->instance->removeArgument('foo'); $this->assertEquals('bar', $old); $this->assertFalse($this->instance->hasArgument('foo')); }
/** * Triggers an event if a listener is set * * @param string $eventName Name of the event to trigger * @param AbstractDatabaseTable $table Table object * @param array $optional Associative array of optional arguments for the event * * @return void * * @since 1.0 */ protected function triggerEvent($eventName, AbstractDatabaseTable $table, array $optional = array()) { if ($this->listenerSet) { $event = new Event($eventName); // Add the event params $event->addArgument('hookData', $this->hookData)->addArgument('table', $table)->addArgument('github', $this->github)->addArgument('logger', $this->logger)->addArgument('project', $this->project); // Add optional params if present if (count($optional) > 0) { foreach ($optional as $name => $value) { $event->addArgument($name, $value); } } // Trigger the event $this->dispatcher->triggerEvent($event); } }
/** * Triggers an event if a listener is set. * * @param string $eventName Name of the event to trigger. * @param array $arguments Associative array of arguments for the event. * * @return void * * @since 1.0 */ protected function triggerEvent($eventName, array $arguments) { if (!$this->listenerSet) { return; } /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $event = new Event($eventName); // Add default event arguments. $event->addArgument('github', $this->github ?: GithubFactory::getInstance($application))->addArgument('logger', $application->getLogger())->addArgument('project', $application->getProject()); // Add event arguments passed as parameters. foreach ($arguments as $name => $value) { $event->addArgument($name, $value); } // Trigger the event. $this->dispatcher->triggerEvent($event); }