本文整理匯總了PHP中Hooks::fire方法的典型用法代碼示例。如果您正苦於以下問題:PHP Hooks::fire方法的具體用法?PHP Hooks::fire怎麽用?PHP Hooks::fire使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Hooks
的用法示例。
在下文中一共展示了Hooks::fire方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getCallbacks
}
$this->hooks[$name][] = $callback;
}
public function getCallbacks($name)
{
return isset($this->hooks[$name]) ? $this->hooks[$name] : array();
}
public function fire($name)
{
foreach ($this->getCallbacks($name) as $callback) {
// prevent fatal errors, do your own warning or
// exception here as you need it.
if (!is_callable($callback)) {
continue;
}
call_user_func($callback);
}
}
}
/**
*
*/
$hooks = new Hooks();
$hooks->add('event', function () {
echo 'morally disputed.';
});
$hooks->add('event', function () {
echo 'explicitly called.';
});
$hooks->fire('event');
示例2: test_fire
/**
* Tests Hooks::fire().
*
* @test
* @dataProvider provider_fire
* @param array functions
* @param string expected
*/
public function test_fire($parameters, $expected)
{
foreach ($parameters as $parameter) {
Hooks::register('event', function ($k, &$array) {
for ($i = $k; $i < $k + 10; $i++) {
$array[] = $i;
}
}, array($parameter));
}
$array = array();
Hooks::fire('event', array(&$array));
$count = 0;
foreach ($parameters as $parameter) {
for ($i = $parameter; $i < $parameter + 10; $i++) {
$count++;
$this->assertContains($i, $array);
}
}
$this->assertSame($count, sizeof($array));
}