Skip to content

Micro Runtime Cleanup 1: Slim the public Request API #71

Closed

Description

@matkomat

Parent issue: #42

Summary

The public micro request API currently exposes raw response machinery via RequestInterface::msg() and internal bookkeeping via RequestInterface::hasResponded(). That leaks core Message behavior into the micro layer and forces lifecycle workarounds higher up in Service.

Goal

Make Request the only public micro reply surface. Handlers should keep the legitimate inbound metadata they need (data(), headers(), subject(), replyTo()), but should not be able to bypass micro reply semantics through a raw mutable Message.

Preferred direction

  • remove msg() from RequestInterface
  • remove hasResponded() from the public interface
  • keep any duplicate-reply bookkeeping as an internal detail of the concrete Request
  • if raw inbound inspection is still needed, prefer a read-only DTO rather than exposing core Message

Scope

  • src/Micro/RequestInterface.php
  • src/Micro/Request.php
  • tests/Integration/Micro/ServiceExtendedTest.php
  • any micro tests/docs that assert msg() / hasResponded()

Out of scope

  • graceful Service::stop() work
  • control-subject hardening
  • docs refresh beyond minimal compile/test fallout

Deliverables

  • narrowed public RequestInterface
  • updated tests that prove legitimate handler use-cases still work without msg()
  • no new coupling added to core Message

Acceptance criteria

  • public micro handlers can reply only through Request
  • no public RequestInterface escape hatch exposes a core Message with respond()
  • duplicate-reply state is not part of the public handler contract
  • micro integration tests pass after the API cleanup

Parallelism

Can run in parallel with the config cleanup and the initial service error-tracking work.
Blocks the duplicate-reply enforcement issue and the final docs refresh.

Activity

  1. matkomat commented on Mar 31, 2026

    @matkomat
    ContributorAuthor

    Implementation plan for whoever picks this up:

    Goal

    Target API after this issue

    RequestInterface should expose only:

    • respond(string $data, ?Headers $headers = null): void
    • respondJson(mixed $data, ?Headers $headers = null): void
    • error(string $code, string $description, string $data = ''): void
    • data(): string
    • headers(): ?Headers
    • subject(): string
    • replyTo(): ?string

    Explicitly remove from the public micro API:

    • msg()
    • hasResponded()

    Request.php should no longer expose those methods publicly either.

    File scope

    Touch only what is needed for this boundary cleanup:

    • src/Micro/RequestInterface.php
    • src/Micro/Request.php
    • tests/Integration/Micro/ServiceExtendedTest.php
    • any micro tests that still directly assert msg() / hasResponded() on your working branch

    Avoid folding in unrelated runtime/lifecycle work from:

    Test changes

    Replace testRequestMsg() with a test that proves handlers still have enough inbound context without a raw Message.

    Preferred shape:

    • publish a request with payload and at least one header
    • inside the handler capture values from:
      • data()
      • subject()
      • replyTo()
      • headers()?->get(...)
    • send the reply through normal Request::respond()
    • assert the captured values after the request completes

    If your branch already contains a hasResponded() test, remove it rather than preserving that API.

    Explicit non-goals / forbidden changes

    • do not modify src/Message.php
    • do not add a replacement raw-message escape hatch under another name
    • do not add respond hooks/callback plumbing anywhere in the core layer
    • do not refactor src/Micro/Service.php here beyond trivial compile fallout, if any
    • do not refresh README/micro docs beyond minimal fallout; the real docs pass is Micro Runtime Cleanup 8: Refresh micro docs and examples after the API cleanup #78

    Acceptance checklist

    • RequestInterface no longer imports or returns Message
    • public micro handlers cannot obtain a reply-capable raw message from the request API
    • inbound metadata needed by handlers is still available through data(), headers(), subject(), and replyTo()
    • integration tests cover the new boundary and no longer depend on msg() / hasResponded()
    • no new core/micro coupling was introduced

    Suggested verification

    • vendor/bin/phpunit tests/Integration/Micro/ServiceExtendedTest.php
    • vendor/bin/phpunit tests/Integration/Micro/ServiceTest.php if touched

    Review notes

    The review for this issue will check specifically for:

    • accidental src/Message.php changes
    • replacement escape hatches under a different name
    • unrelated Service.php runtime changes folded into the same PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:microMicro/service frameworkenhancementNew feature or requestpriority:P2Medium-priority parity or feature gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions