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 / diagnostics / HookInstrumentationRegistration.php

HookInstrumentationRegistration.php in 404 Solution trunk, at includes/diagnostics/HookInstrumentationRegistration.php

42 lines 1.1 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 /**
8 * Stable registry identities for reversible hook instrumentation entries.
9 *
10 * The instrumenter owns mutation and restoration. This collaborator owns only
11 * collision-safe keys for remembering those mutations.
12 */
13 final class ABJ_404_Solution_HookInstrumentationRegistration {
14
15 public static function key(string $hook, int $priority, string $id): string {
16 return $hook . '|' . $priority . '|' . $id;
17 }
18
19 /**
20 * @param array<array-key, mixed> $existing
21 * @param array<array-key, mixed> $result
22 */
23 public static function markerId(
24 string $position,
25 string $hook,
26 int $priority,
27 string $id,
28 array $existing,
29 array $result
30 ): string {
31 $base = 'abj404-trace-' . $position . '-'
32 . substr(hash('sha256', $hook . '|' . $priority . '|' . $id), 0, 16);
33 $candidate = $base;
34 $suffix = 0;
35 while (array_key_exists($candidate, $existing) || array_key_exists($candidate, $result)) {
36 $suffix++;
37 $candidate = $base . '-' . $suffix;
38 }
39 return $candidate;
40 }
41 }
42