| 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 |
|