Skip to content

Generated types for PHP #308

@francislavoie

Description

@francislavoie

After some discussion in discord, I think the best approach would be to generate PHP interfaces that have the appropriate docblocks for each service method.

Example:

<?php

namespace Rpc/Types;

interface MathService
{
    /**
     * My awesome method description
     *
     * @param int|float $a is a really cool number
     * @param int|float $a another cool number
     * @return int|float the result of $a + $b
    */
    public function addition($a, $b);
}

Namespace & output path should be configurable ideally (didn't dig much into this repo yet to see the CLI params).

Some users may want their interfaces strongly typed with param/return types, but the easiest thing for the time being is to skip that part and just do docblocks at first. Could have some config to allow for enabling strong types, for example, using PHP 8.0 union types:

<?php

namespace Rpc/Types;

interface MathService
{
    /**
     * My awesome method description
     *
     * @param int|float $a is a really cool number
     * @param int|float $a another cool number
     * @return int|float the result of $a + $b
    */
    public function addition(int|float $a, int|float $b) : int|float;
}

P.S. My preferred JSON-RPC server lib in PHP is https://github.com/datto/php-json-rpc, also includes a client which is useful for testing etc.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions