/** * Excecute trigger * * @param string $triggerName * @param array $arguments * @return int|string * * @throws \JBZoo\Event\ExceptionStop */ public function trigger($triggerName, array $arguments = array()) { array_unshift($arguments, $this->_cms); $count = $this->_eManager->trigger($triggerName, $arguments); if ($this->_isAdmin) { $count += $this->_eManager->trigger($triggerName . self::POSTFIX_ADMIN, $arguments); } else { $count += $this->_eManager->trigger($triggerName . self::POSTFIX_SITE, $arguments); } return $count; }
public function testComplexRandom() { $eManager = new EventManager(); $parts = array('foo', 'bar', 'woo', 'bazz', '*', '*', '*'); for ($i = 0; $i < 100; $i++) { shuffle($parts); $partsRand = implode('.', array_slice($parts, 0, mt_rand(1, count($parts)))); if ($partsRand === '*') { $partsRand .= '.foo'; } $eManager->on($partsRand, function () { // noop }, mt_rand(0, $i)); } runBench(array('Many' => function () use($eManager) { $parts = array('foo', 'bar', 'woo', 'bazz'); shuffle($parts); $partsRand = implode('.', array_slice($parts, 0, mt_rand(1, count($parts)))); $eManager->trigger($partsRand); }), array('name' => 'Complex random', 'count' => 1000)); }
public function testComplex2() { $eManager = new EventManager(); $eManager->on('*.save', $this->noop); $eManager->on('*.save.*', $this->noop); $eManager->on('*.save.*', $this->noop); $eManager->on('*.save.*', $this->noop); $eManager->on('*.save.*.*', $this->noop); $eManager->on('*.save.before', $this->noop); $eManager->on('item.save.before', $this->noop); $eManager->on('category.save.before', $this->noop); $eManager->on('category.load.before', $this->noop); $eManager->on('category', $this->noop); is(0, $eManager->trigger('item.load')); is(0, $eManager->trigger('item.load.before')); is(0, $eManager->trigger('save.before')); is(0, $eManager->trigger('item.save.before.realy.deep.name')); is(0, $eManager->trigger('category.save.before.realy.deep.name')); is(1, $eManager->trigger('item.save')); is(1, $eManager->trigger('category')); is(1, $eManager->trigger('item.save.after.deep')); is(3, $eManager->trigger('item.save.after')); is(5, $eManager->trigger('item.save.before')); }
/** * @expectedException \JBZoo\Event\Exception */ public function testEmptyEventNameTrigger() { $eManager = new EventManager(); $eManager->trigger(' '); }