Merge pull request #22808 from colemanw/searchKitMailingTask
[civicrm-core.git] / Civi / Core / Event / EventPrinter.php
1 <?php
2
3
4 namespace Civi\Core\Event;
5
6 /**
7 * This provides some rarely used debug utilities.
8 *
9 * @package Civi\Core\Event
10 */
11 class EventPrinter {
12
13 /**
14 * Prepare a name to identify a callable element.
15 *
16 * @param mixed $callback
17 * @return string
18 */
19 public static function formatName($callback): string {
20 $normalizeNamespace = function($symbol) {
21 return $symbol{0} === '\\' ? substr($symbol, 1) : $symbol;
22 };
23 if (is_array($callback)) {
24 [$a, $b] = $callback;
25 if (is_object($a)) {
26 return $normalizeNamespace(get_class($a)) . "->$b(\$e)";
27 }
28 elseif (is_string($a)) {
29 return $normalizeNamespace($a) . "::$b(\$e)";
30 }
31 }
32 elseif (is_string($callback)) {
33 return $normalizeNamespace($callback) . '(\$e)';
34 }
35 elseif ($callback instanceof ServiceListener || $callback instanceof HookStyleListener) {
36 return (string) $callback;
37 }
38 else {
39 try {
40 $f = new \ReflectionFunction($callback);
41 return 'closure<' . $f->getFileName() . '@' . $f->getStartLine() . '>($e)';
42 }
43 catch (\ReflectionException $e) {
44 }
45 }
46
47 return 'unidentified';
48 }
49
50 }