PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / logs / RoutineLoggingBridge.php

RoutineLoggingBridge.php in 404 Solution trunk, at includes/logs/RoutineLoggingBridge.php

59 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /** Diagnostics-neutral adapter for request-scoped routine-log attribution. */
8 final class ABJ_404_Solution_RoutineLoggingBridge {
9
10 /** @var callable(string,array<string,mixed>,callable):mixed|null */
11 private static $tracer = null;
12
13 /** @var callable(string,string,callable):mixed|null */
14 private static $authorizationTracer = null;
15
16 /** @param callable(string,array<string,mixed>,callable):mixed|null $tracer */
17 public static function setTracer($tracer): void {
18 self::$tracer = is_callable($tracer) ? $tracer : null;
19 }
20
21 /** @param callable(string,string,callable):mixed|null $tracer */
22 public static function setAuthorizationTracer($tracer): void {
23 self::$authorizationTracer = is_callable($tracer) ? $tracer : null;
24 }
25
26 /**
27 * @template T
28 * @param array<string,mixed> $fields
29 * @param callable():T $work
30 * @return T
31 */
32 public static function trace(string $operation, array $fields, callable $work) {
33 return is_callable(self::$tracer)
34 ? call_user_func(self::$tracer, $operation, $fields, $work)
35 : $work();
36 }
37
38 /**
39 * @template T
40 * @param callable():T $work
41 * @return T
42 */
43 public static function traceAuthorized(
44 string $authorizationOperation,
45 string $routineOperation,
46 callable $work
47 ) {
48 if (is_callable(self::$authorizationTracer)) {
49 return call_user_func(
50 self::$authorizationTracer,
51 $authorizationOperation,
52 $routineOperation,
53 $work
54 );
55 }
56 return self::trace($routineOperation, array(), $work);
57 }
58 }
59