tourze/json-rpc-procedure-collect-bundle

JSON-RPC过程收集模块

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/json-rpc-procedure-collect-bundle

0.0.2 2025-06-01 05:58 UTC

This package is auto-updated.

Last update: 2025-11-01 19:18:43 UTC


README

English | 中文

PHP Version Symfony Version License Build Status Code Coverage

A Symfony Bundle that collects all services marked as JSON-RPC methods and provides an API to query all available methods.

Features

  • Automatically collect all JSON-RPC methods marked with #[MethodExpose] attribute
  • Provide GetProcedureList JSON-RPC method to retrieve all registered methods
  • Support for method documentation and tagging via #[MethodDoc] and #[MethodTag] attributes
  • Dependency injection integration for automatic service discovery

Installation

composer require tourze/json-rpc-procedure-collect-bundle

Bundle Registration

Add to config/bundles.php:

Tourze\JsonRPCProcedureCollectBundle\JsonRPCProcedureCollectBundle::class => ['all' => true],

Quick Start

Creating a JSON-RPC Method

<?php

namespace App\Procedure;

use Tourze\JsonRPC\Core\Attribute\MethodDoc;
use Tourze\JsonRPC\Core\Attribute\MethodExpose;
use Tourze\JsonRPC\Core\Attribute\MethodTag;
use Tourze\JsonRPC\Core\Procedure\BaseProcedure;

#[MethodTag(name: 'User Service')]
#[MethodDoc(summary: 'Get user information')]
#[MethodExpose(method: 'GetUserInfo')]
class GetUserInfo extends BaseProcedure
{
    public function execute(): array
    {
        // Implement your method logic
        return ['user' => 'data'];
    }
}

Retrieving All Available Methods

Call the GetProcedureList JSON-RPC method to get all registered JSON-RPC methods and their corresponding implementation classes:

{
  "jsonrpc": "2.0",
  "method": "GetProcedureList",
  "params": {},
  "id": 1
}

Response example:

{
  "jsonrpc": "2.0",
  "result": {
    "GetProcedureList": "Tourze\\JsonRPCProcedureCollectBundle\\Procedure\\GetProcedureList",
    "GetUserInfo": "App\\Procedure\\GetUserInfo"
  },
  "id": 1
}

Requirements

  • PHP >= 8.1
  • Symfony >= 7.3
  • tourze/json-rpc-core package

Testing

Run the test suite:

./vendor/bin/phpunit packages/json-rpc-procedure-collect-bundle/tests

Contributing

Please see CONTRIBUTING.md for details.

License

The MIT License (MIT). Please see License File for more information.