1. Go to this page and download the library: Download ufo-tech/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/ */
ufo-tech / json-rpc-bundle example snippets
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Ufo\JsonRpcBundle\Routing\RpcYamlFileLoader;
#[AutoconfigureTag('routing.loader', ['priority' => 200])]
class AdapterYamlFileLoader extends RpcYamlFileLoader
{
protected function getRouteNamePrefixAttribute(array $config, string $path): ?string
{
if ($this->isResourceImport($config['resource'], $path, __DIR__.'/../../config/router.yaml')) {
return '_adapter_name_prefix';
}
return parent::getRouteNamePrefixAttribute($config, $path);
}
}
use Ufo\JsonRpcBundle\ApiMethod\Interfaces\IRpcService;
use Ufo\RpcObject\RPC;
#[RPC\Info('catalog')]
#[RPC\APIGroups(['internal', 'public'], false)]
class CatalogApi implements IRpcService
{
public function list(): array
{
return [['id' => 1, 'name' => 'Coffee']];
} // shared by internal and public API
#[RPC\APIGroups(['internal'], false)]
public function updatePrice(int $productId, int $price): true { return true; } // internal only
#[RPC\APIGroups(['public'], false)]
public function featured(): array { return [1]; } // public only
#[RPC\APIGroups()]
public function status(): string { return 'ok'; } // general only
#[RPC\APIGroups(['internal'], false)]
#[RPC\IgnoreApi]
public function rebuildIndex(): true { return true; } // never published
}
$message = new \Ufo\RpcObject\RpcAsyncRequest(
$request,
$token,
apiGroup: 'internal',
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.