<?php function e($n,$p,$c=0){static $a;@krsort($a[$n]);if($c)$a[$n][$p][]=$c;else foreach($a[$n] as$q)foreach($q as$r)$r($p);}
function it($m,$p){echo ($p?'✔︎':'✘')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);}
ob_start();
e(
'event',
0,
function ($data) {
echo "event, $data, priority 0;";
}
);
e(
'event',
10,
function ($data) {
echo "event, $data, priority 10;";
}
);
e(
'other_event',
-5,
function ($data) {
echo "other_event, $data, priority -5;";
}
);
e(
'other_event',
5,
function ($data) {
echo "other_event, $data priority 5;";
}
);
e('event', 'dataX');
e('other_event', 'dataY');
$output = ob_get_contents();
ob_end_clean();
it(
'calls event listeners in the right order',
$output === 'event, dataX, priority 10;event, dataX, priority 0;other_event, dataY priority 5;other_event, dataY, priority -5;'
);
preferences:
40.26 ms | 402 KiB | 5 Q