#[RPC\Info]

Last modified by Ashterix on 2024/05/19 21:27

Summary

ClassnameInfo
NamespaceUfo\RpcObject\RPC
Targetclass
Arguments:
$aliastypestring
optionaltrue
defaultnull
$concattypestring
optionaltrue
default'.'

Class Aliases

Sometimes it may be necessary to set an alternative name for an API method, for example, if you have a very long class name due to some standards or naming conventions in your project.

In such cases, you can add the attribute #[RPC\Info] to your class, specifying an alias for the class. This will instruct the RPC server to associate this alias with the class.

1
2
3
4
5
6
7
8
9
10
<?php
namespace App\Api\Procedures;

use Ufo\RpcObject\RPC;

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

In this case, the API method users.getList will be available.

Note that the original naming of the method will be removed from the ServiceMap and will no longer be accessible.

That is, MySpecificApiUserServiceWithLongClassName.getList will no longer work!

Concatenation Symbol

The Info attribute also accepts a second argument concat, which specifies the character or characters that join the class name and method name when generating the ServiceMap for the RPC server.

The default value is "." (dot), but you can easily change it by specifying the symbol or characters you need.

1
2
3
4
5
6
7
8
9
10
<?php
namespace App\Api\Procedures;

use Ufo\RpcObject\RPC;

#[RPC\Info(alias: 'users', concat: '>')]
class MySpecificApiUserServiceWithLongClassName implements IRpcService
{
   public function getList(): void {}
}

The example code above will result in the API method users>getList being available.

Caveats

NOTE that there is no additional validation regarding the use of aliases or concatenation symbols, so your actions could lead to the aliasing of another existing class.

For example, if in your application there is already a class Foo with the method bar added to the API as the method Foo.bar, and you create a class Baz with the method bar and set its alias to Foo​​​​​​, this will lead to the registration of two API services with the same name. The outcome of these actions is unpredictable.

By using this mechanism, you act at your own risk!

In future

In the future, we plan to implement the ability to set aliases for each specific API method, not just classes.