Skip to content

Add an interface for servers #89

Description

@sagikazarmark

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Problem Description

#86 introduced custom server path prefixes as defined by the v7 specification.

It also introduced a new method called getPathPrefix, replacing the PATH_PREFIX constant as a better alternative for registering servers in a router.

With the introduction of this method, the signature of \Twirp\Server::registerServer becomes somewhat redundant:

public function registerServer(string $prefix, RequestHandlerInterface $server): void

(Now that I think of it: it was somewhat redundant before too because of the PATH_PREFIX constant)

Proposed Solution

Simplify the definition of registerServer:

public function registerServer(RequestHandlerInterface $server): void

This is probably not enough thought as the RequestHandlerInterface itself doesn't implement getPathPrefix, so we need a custom interface (see #88):

public function registerServer(Server $server): void

Alternatives Considered

Make the $prefix parameter optional and try to call getPathPrefix if it exists as a method, but sadly there is no way (other than reflection) to ensure that the method accepts no parameters and returns a string.

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions