PHP code example of insidestyles / json-rpc-bundle
1. Go to this page and download the library: Download insidestyles/json-rpc-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/ */
insidestyles / json-rpc-bundle example snippets
Insidestyles\JsonRpcBundle\JsonRpcBundle::class => ['all' => true],
/**
* @JsonRpcApi(namespace = "main")
*
* @author Fuong <[email protected] >
*/
interface HelloWordJsonRpcApiInterface extends JsonRpcApiInterface
{
public function helloWorld(string $name);
}
namespace Insidestyles\Core\Exceptions;
use Doctrine\ORM\EntityNotFoundException;
use Insidestyles\JsonRpcBundle\Server\ErrorHandler\Handler\ErrorHandlerInterface;
use Throwable;
class ApiErrorHandler implements ErrorHandlerInterface
{
private const SYSTEM_ERRORS = [
EntityNotFoundException::class,
];
public function parse(Throwable $e): array
{
if (!$this->isSupported($e)) {
return [];
}
return [
'code' => $e->getCode(),
'message' => $e->getMessage(),
'data' => [],
];
}
public function isSupported(Throwable $e): bool
{
return $e instanceof IsExceptionInterface || in_array(get_class($e), static::SYSTEM_ERRORS);
}
}
namespace Insidestyles\JsonRpcBundle\Message;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @author Fuong <[email protected] >
*/
class HelloWorldMessage
{
/**
* @Assert\NotBlank()
* @var string
*/
private $message;
public function __construct(string $message)
{
$this->message = $message;
}
/**
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
}
$container->get('hello.remote_services.hello')->helloWorld('Hi');