'x', 'run' => function(array $ctx){...}, ...policy] if (is_array($def) && !empty($def['intent']) && is_string($def['intent']) && isset($def['run']) && is_callable($def['run'])) { $intent_id = $def['intent']; $policy = [ 'capability' => $def['capability'] ?? 'manage_options', 'scope' => $def['scope'] ?? 'core', 'unsafe' => !empty($def['unsafe']), 'requires_live' => !empty($def['requires_live']), 'dry_run_exempt' => !empty($def['dry_run_exempt']), 'notes' => $def['notes'] ?? '', 'tags' => is_array($def['tags'] ?? null) ? $def['tags'] : [], ]; $run = $def['run']; $registry->register( $intent_id, function(array $payload, array $meta, array $ctx) use ($run) : array { // Normalize to the ctx contract expected by declarative handlers $ctx = is_array($ctx) ? $ctx : []; $ctx['payload'] = $payload; $ctx['meta'] = $meta; $res = $run($ctx); return is_array($res) ? $res : ['ok' => false, 'error' => 'handler_invalid_response']; }, $policy ); continue; } // Unknown handler format -> ignore (but keep registry working) } } } return $registry; }