PHP code example of timiki / rpc-server-bundle

1. Go to this page and download the library: Download timiki/rpc-server-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

timiki / rpc-server-bundle example snippets




declare(strict_types=1);

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

class RpcController extends AbstractController
{
    public function indexAction(Request $request)
    {
        return $this->get('rpc.server.http_handler.default')->handleHttpRequest($request);
    }
}



declare(strict_types=1);

namespace App\Method;

use Timiki\Bundle\RpcServerBundle\Attribute as RPC;
use Symfony\Component\Validator\Constraints as Assert;

#[RPC\Method("name")]
#[RPC\Roles(["ROLE_NAME"])]
#[RPC\Cache(3600)]
class Method
{
    #[RPC\Param]
    #[Assert\NotBlank]
    protected $param;

    #[RPC\Execute] 
    public function execute()
    {
        $param = $this->param;
        
        ...
        
        return $result;
    }
}
    



declare(strict_types=1);

namespace App\Method;

use Timiki\Bundle\RpcServerBundle\Attribute as RPC;
use Symfony\Component\Validator\Constraints as Assert;

#[RPC\Method("name")]
#[RPC\Roles(["ROLE_NAME"])]
#[RPC\Cache(3600)]
class Method
{
    #[RPC\Param]
    #[Assert\NotBlank]
    protected $param;

    public function __invoke()
    {
        $param = $this->param;
        
        ...
        
        return $result;
    }
}
    



declare(strict_types=1);

namespace App\Method;

use Timiki\Bundle\RpcServerBundle\Attribute as RPC;
use Timiki\Bundle\RpcServerBundle\Method\Context;
use Symfony\Component\Validator\Constraints as Assert;

#[RPC\Method("name")]
#[RPC\Roles(["ROLE_NAME"])]
#[RPC\Cache(3600)]
class Method
{
    #[RPC\Param]
    #[Assert\NotBlank]
    protected $param;

    public function __invoke(Context $context)
    {
        $param = $this->param;
        
        ...
        
        return $result;
    }
}
    

#[Method("name")]

#[Roles(["ROLE_NAME", "ROLE_OTHER"])]

#[Cache(3600)]

#[Param]
protected $param;

#[Param]
protected $param = null'; // Default value for param

#[Execute]
public function execute()
{
    // Code
}

public function __invoke()
{
    // Code
}




declare(strict_types=1);

namespace App\Serializer;

use Timiki\Bundle\RpcServerBundle\Serializer\SerializerInterface;

class MySerializer implements SerializerInterface
{
    public function serialize(mixed $data): string 
        // You serialize logic
    }
    
    public function toArray(mixed $data): array 
        // You serialize logic
    }
}