1. Go to this page and download the library: Download tourze/json-rpc-lock-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/ */
use Tourze\JsonRPCLockBundle\Procedure\LockableProcedure;
use Tourze\JsonRPC\Core\Model\JsonRpcParams;
class MySecureProcedure extends LockableProcedure
{
public function execute(): array
{
// Your business logic here
$params = $this->getParams();
$userId = $params->get('user_id');
$amount = $params->get('amount');
// This will be automatically locked based on user identity
return ['result' => $this->processPayment($userId, $amount)];
}
private function processPayment(int $userId, float $amount): string
{
// Your payment processing logic
return 'payment_processed';
}
}
public function getLockResource(JsonRpcParams $params): ?array
{
// Custom lock based on specific parameters
$accountId = $params->get('account_id');
return ['account_lock_' . $accountId];
}
// To skip locking entirely, return null
public function getLockResource(JsonRpcParams $params): ?array
{
return null; // No locking applied
}