Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated types for PHP #308

Open
francislavoie opened this issue Jul 31, 2020 · 0 comments
Open

Generated types for PHP #308

francislavoie opened this issue Jul 31, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request
Projects

Comments

@francislavoie
Copy link

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.

@BelfordZ BelfordZ self-assigned this Jul 31, 2020
@BelfordZ BelfordZ added the enhancement New feature or request label Jul 31, 2020
@BelfordZ BelfordZ added this to To do in OpenRPC via automation Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
OpenRPC
  
Icebox
Development

No branches or pull requests

2 participants