#[RPC\Info]
Summary
Classname | Info | |
Namespace | Ufo\RpcObject\RPC | |
Target | class | |
Arguments: | ||
$alias | type | string |
optional | true | |
default | null | |
$concat | type | string |
optional | true | |
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.
2
3
4
5
6
7
8
9
10
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.
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.
2
3
4
5
6
7
8
9
10
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.
In future
In the future, we plan to implement the ability to set aliases for each specific API method, not just classes.