Skip to content

Commit 7a55589

Browse files
committed
Document registration of custom RPC endpoints
1 parent bb260af commit 7a55589

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/php/api/rpc_api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ Every endpoint needs to implement `wcf\system\endpoint\IController` which define
121121
Any endpoint can only ever serve a single verb, registered through the use of the `wcf\system\endpoint\GetRequest`, `wcf\system\endpoint\PostRequest` or `wcf\system\endpoint\DeleteRequest` class attribute.
122122
The attribute expects a single parameter to define the endpoint’s route.
123123

124+
## Registering of an Endpoint
125+
126+
Custom endpoints can be registered via the `ControllerCollecting` event in the [bootstrap script](../../package/bootstrap-scripts.md) of a package.
127+
128+
Example:
129+
130+
```php title="files/lib/bootstrap/com.example.bar.php"
131+
<?php
132+
return static function (): void {
133+
\wcf\system\event\EventHandler::getInstance()->register(
134+
\wcf\event\endpoint\ControllerCollecting::class,
135+
static function (\wcf\event\endpoint\ControllerCollecting $event) {
136+
$event->register(new \wcf\system\endpoint\controller\foo\bar\DeleteFooBar());
137+
}
138+
);
139+
};
140+
```
141+
142+
124143
### Placeholders
125144

126145
The route implementation uses [FastRoute](https://github.com/nikic/FastRoute) which supports named placeholders through the `{name}` syntax. Optionally, a validation pattern can be specified to further narrow down the valid value of the placeholder: `{id:\d+}`

0 commit comments

Comments
 (0)