Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an interface for servers #89

Open
1 task done
sagikazarmark opened this issue Nov 3, 2021 · 0 comments
Open
1 task done

Add an interface for servers #89

sagikazarmark opened this issue Nov 3, 2021 · 0 comments
Labels
Milestone

Comments

@sagikazarmark
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant