diff --git a/.github/workflows/ci-depot.yaml b/.github/workflows/ci-depot.yaml index 4ebe7e2..54e1336 100644 --- a/.github/workflows/ci-depot.yaml +++ b/.github/workflows/ci-depot.yaml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"] + php: ["8.1", "8.2", "8.3", "8.4"] steps: - name: Checkout repository diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8127d14..c9bba69 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"] + php: ["8.1", "8.2", "8.3", "8.4"] steps: - name: Checkout repository diff --git a/composer.json b/composer.json index 0beb628..8de3382 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^7.3 || ^8.0", + "php": "^8.1", "php-http/discovery": "^1.19", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", diff --git a/lib/src/Router.php b/lib/src/Router.php index 91952d7..3c797c7 100644 --- a/lib/src/Router.php +++ b/lib/src/Router.php @@ -52,6 +52,11 @@ public function registerHandler(string $path, RequestHandlerInterface $handler): $this->handlers[$path] = $handler; } + public function registerServer(ServerWithPathPrefix&RequestHandlerInterface $server): void + { + $this->handlers[$server->getPathPrefix()] = $server; + } + public function handle(ServerRequestInterface $request): ResponseInterface { foreach ($this->handlers as $path => $handler) { diff --git a/lib/src/ServerWithPathPrefix.php b/lib/src/ServerWithPathPrefix.php new file mode 100644 index 0000000..21a4178 --- /dev/null +++ b/lib/src/ServerWithPathPrefix.php @@ -0,0 +1,15 @@ +/./" + * that is everything in a Twirp route except for the . This can be used for routing, + * for example, to identify the requests that are targeted to this service in a mux. + */ + public function getPathPrefix(): string; +} diff --git a/protoc-gen-twirp_php/templates/service/Server.php.tmpl b/protoc-gen-twirp_php/templates/service/Server.php.tmpl index 62a61c4..b64cab2 100644 --- a/protoc-gen-twirp_php/templates/service/Server.php.tmpl +++ b/protoc-gen-twirp_php/templates/service/Server.php.tmpl @@ -17,13 +17,16 @@ use Twirp\BaseServerHooks; use Twirp\Context; use Twirp\ErrorCode; use Twirp\ServerHooks; +use Twirp\ServerWithPathPrefix; /** * @see {{ .Service | phpServiceName .File }} * * Generated from protobuf service {{ .Service.Desc.FullName }} */ -final class {{ .Service | phpServiceName .File }}Server implements RequestHandlerInterface +final class {{ .Service | phpServiceName .File }}Server implements + RequestHandlerInterface, + ServerWithPathPrefix { /** * A convenience constant that may identify URL paths.