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

Summary

Classname Info
Namespace Ufo\RpcObject\RPC
Target class
public function __construct(
    public string $alias,
    public string $concat = '.',
    ?int $version = 1,
    array $removedMethods = [],
)

Class aliases

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.

<?php

namespace App\Api\Procedures;

use Ufo\JsonRpcBundle\ApiMethod\Interfaces\IRpcService;
use Ufo\RpcObject\RPC;

#[RPC\Info('users')]
class MySpecificApiUserServiceWithLongClassName implements IRpcService
{
    public function getList(): array { return []; }
}

The API will expose the method users.getList. The original name (MySpecificApiUserServiceWithLongClassName.getList) no longer works.

The alias also becomes the methods' tag in the documentation, and the full class name becomes the tag description.

Concatenation character

The second argument, concat, sets the character (or characters) between the alias and the method name. The default is . (a dot).

#[RPC\Info('users', concat: '_')]
class UserApi implements IRpcService
{
    public function getList(): array { return []; }
}

The API will expose the method users_getList.

Versions 10.0.0–10.3.0

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.

API version and removed methods

The version and removedMethods arguments describe which API version the class belongs to and which methods from previous versions were removed in it:

#[RPC\Info('user', version: 2, removedMethods: ['legacySearch'])]
class UserApiV2 implements IRpcService
{
    public function get(string $uuid): array { /* ... */ }
}

See API versions for details.

Caveats

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 are allowed, but for independent implementations it is better to use different names.