Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-depot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions lib/src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions lib/src/ServerWithPathPrefix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Twirp;

interface ServerWithPathPrefix
{
/**
* Returns the base service path, in the form: "/<prefix>/<package>.<Service>/"
* that is everything in a Twirp route except for the <Method>. 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;
}
5 changes: 4 additions & 1 deletion protoc-gen-twirp_php/templates/service/Server.php.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>{{ .Service.Desc.FullName }}</code>
*/
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.
Expand Down
Loading