Class aliases

← Class aliases

Ashterix

docs: rewrite JsonRpcBundle docs, add SDK docs, move them under docs/api

en/docs/api/json-rpc-bundle/add_rpc_service/info.md new file +75 āˆ’0

1 + ## Summary
2 +
3 + | | |
4 + | --- | --- |
5 + | **Classname** | `Info` |
6 + | **Namespace** | `Ufo\RpcObject\RPC` |
7 + | **Target** | class |
8 +
9 + ```php
10 + public function __construct(
11 + public string $alias,
12 + public string $concat = '.',
13 + ?int $version = 1,
14 + array $removedMethods = [],
15 + )
16 + ```
17 +
18 + # Class aliases
19 +
20 + Sometimes you need an alternative name for API methods — for example, when the class name is too long because of the project's naming conventions. The `#[RPC\Info]` attribute sets an alias under which the class methods are available in the API.
21 +
22 + ```php
23 + <?php
24 +
25 + namespace App\Api\Procedures;
26 +
27 + use Ufo\JsonRpcBundle\ApiMethod\Interfaces\IRpcService;
28 + use Ufo\RpcObject\RPC;
29 +
30 + #[RPC\Info('users')]
31 + class MySpecificApiUserServiceWithLongClassName implements IRpcService
32 + {
33 + public function getList(): array { return []; }
34 + }
35 + ```
36 +
37 + The API will expose the method `users.getList`. The original name (`MySpecificApiUserServiceWithLongClassName.getList`) no longer works.
38 +
39 + The alias also becomes the methods' tag in the [documentation](/docs/api/json-rpc-bundle/documentation), and the full class name becomes the tag description.
40 +
41 + # Concatenation character
42 +
43 + The second argument, `concat`, sets the character (or characters) between the alias and the method name. The default is `.` (a dot).
44 +
45 + ```php
46 + #[RPC\Info('users', concat: '_')]
47 + class UserApi implements IRpcService
48 + {
49 + public function getList(): array { return []; }
50 + }
51 + ```
52 +
53 + The API will expose the method `users_getList`.
54 +
55 + :::warning subtitle="Versions 10.0.0–10.3.0"
56 + In these versions `concat` was ignored, and methods always used the `.` separator. Since 10.3.1 it is applied again: if you have `concat` set while clients call methods with `.`, the method names will change after the upgrade — update the clients or remove `concat`.
57 + :::
58 +
59 + # API version and removed methods
60 +
61 + The `version` and `removedMethods` arguments describe which API version the class belongs to and which methods from previous versions were removed in it:
62 +
63 + ```php
64 + #[RPC\Info('user', version: 2, removedMethods: ['legacySearch'])]
65 + class UserApiV2 implements IRpcService
66 + {
67 + public function get(string $uuid): array { /* ... */ }
68 + }
69 + ```
70 +
71 + See [API versions](/docs/api/json-rpc-bundle/functionality/versions) for details.
72 +
73 + # Caveats
74 +
75 + The bundle rejects two implementations with the same method name within the same API group and version (taking class inheritance rules into account). Identical names in different [API groups](/docs/api/json-rpc-bundle/functionality/groups) are allowed, but for independent implementations it is better to use different names.