agent id, in one option, as `KeyBindings` keeps * WooCommerce keys. The mapping is the authority; the parent checks that * the agent is linked to the user the credential runs as. */ final class PathDBindings { /** * The option. */ public const OPTION = 'adafwc_mcp_bindings'; /** * The agent a principal is bound to, or null. * * @param string $principal Principal id. */ public function agent_for( string $principal ): ?int { $agent = self::all()[ $principal ] ?? null; return is_int( $agent ) && $agent > 0 ? $agent : null; } /** * Bind a principal. * * @param string $principal Principal id. * @param int $agent_id Agent. */ public function bind( string $principal, int $agent_id ): void { $all = self::all(); $all[ $principal ] = $agent_id; update_option( self::OPTION, $all, false ); } /** * Unbind a principal. * * @param string $principal Principal id. */ public function unbind( string $principal ): void { $all = self::all(); unset( $all[ $principal ] ); update_option( self::OPTION, $all, false ); } /** * Every binding. * * @return array */ public static function all(): array { $stored = get_option( self::OPTION, array() ); $all = array(); foreach ( is_array( $stored ) ? $stored : array() as $principal => $agent ) { if ( is_string( $principal ) && is_numeric( $agent ) ) { $all[ $principal ] = (int) $agent; } } return $all; } }