/** * Get hooks debug info for the given Wire object * * @param Wire $obj * @return array * */ public function getHooksInfo(Wire $obj) { $hooks = array(); foreach ($obj->getHooks() as $hook) { list($class, $priority) = explode(':', $hook['id']); $key = ''; $value = ''; if ($hook['options']['before']) { $key .= "before "; } if ($hook['options']['type'] == 'property') { $key .= "property "; } else { if ($hook['options']['after']) { if (method_exists($class, $hook['method']) || method_exists($class, '___' . $hook['method'])) { $key .= "after "; } } } if ($hook['options']['type'] == 'property' || !$hook['options']['allInstances']) { $key .= "{$class}" . '->' . "{$hook['method']}"; } else { $key .= "{$class}::{$hook['method']}"; } $filename = ''; if (!empty($hook['toObject'])) { $value .= $hook['toObject']->className() . "->"; $ref = new ReflectionClass($hook['toObject']); $filename = $ref->getFileName(); } if (!empty($hook['toMethod'])) { if (is_string($hook['toMethod'])) { $value .= "{$hook['toMethod']}()"; } else { if (is_callable($hook['toMethod'])) { $ref = new ReflectionFunction($hook['toMethod']); $filename = $ref->getFileName(); $value = "anonymous function()"; } } } if ($filename) { $value .= " in " . basename($filename); } if (!isset($hooks[$key])) { $hooks[$key] = $value; } else { if (!is_array($hooks[$key])) { $hooks[$key] = array($hooks[$key]); } $hooks[$key][] = $value; } } return $hooks; }