public function getHooks($method = '', $type = 0)
{
$hooks = array();
// first determine which local hooks when should include
if ($type !== 2) {
if ($method && $method !== '*') {
// populate all local hooks for given method
if (isset($this->localHooks[$method])) {
$hooks = $this->localHooks[$method];
}
} else {
// populate all local hooks, regardless of method
// note: sort of return hooks is no longer priority based
// @todo account for '*' method, which should return all hooks regardless of instance
foreach ($this->localHooks as $method => $methodHooks) {
$hooks = array_merge(array_values($hooks), array_values($methodHooks));
}
}
}
// if only local hooks requested, we can return them now
if ($type === 1) {
return $hooks;
}
$needSort = false;
// join in static hooks
foreach (self::$staticHooks as $className => $staticHooks) {
if (!$this instanceof $className && $method !== '*') {
continue;
}
// join in any related static hooks to the local hooks
if ($method && $method !== '*') {
// retrieve all static hooks for method
if (!empty($staticHooks[$method])) {
if (count($hooks)) {
$collisions = array_intersect_key($hooks, $staticHooks[$method]);
$hooks = array_merge($hooks, $staticHooks[$method]);
if (count($collisions)) {
// identify and resolve priority collisions
foreach ($collisions as $priority => $hook) {
$n = 0;
while (isset($hooks["{$priority}.{$n}"])) {
$n++;
}
$hooks["{$priority}.{$n}"] = $hook;
}
}
$needSort = true;
} else {
$hooks = $staticHooks[$method];
}
}
} else {
// no method specified, retrieve all for class
// note: priority-based array indexes are no longer in tact
$hooks = array_values($hooks);
foreach ($staticHooks as $_method => $methodHooks) {
$hooks = array_merge($hooks, array_values($methodHooks));
}
}
}
if ($needSort && count($hooks) > 1) {
defined("SORT_NATURAL") ? ksort($hooks, SORT_NATURAL) : uksort($hooks, "strnatcmp");
}
return $hooks;
}