caseboxdev/rpc-bundle
Symfony 3 bundle for integrating Casebox with CMF and ExtJS RPC services. Provides RPC controllers, service integration, and centralized exception handling to connect your Symfony app to Casebox RPC endpoints.
Installation
Add the bundle to your composer.json:
composer require caseboxdev/rpc-bundle
Enable it in config/bundles.php:
return [
// ...
Casebox\RpcBundle\CaseboxRpcBundle::class => ['all' => true],
];
Configuration Follow the Casebox documentation for Symfony CMF integration. Key steps:
casebox_rpc in config/packages/casebox_rpc.yaml (if provided).services.yaml includes the RPC service bindings:
services:
Casebox\RpcBundle\Service\RpcService: ~
First Use Case: RPC Endpoint
Create a basic RPC controller extending CaseboxRpcBundle's base controller:
// src/Controller/CaseboxRpcController.php
namespace App\Controller;
use Casebox\RpcBundle\Controller\AbstractRpcController;
class CaseboxRpcController extends AbstractRpcController
{
public function indexAction()
{
return $this->rpcService->handleRequest('your_rpc_method', [/* params */]);
}
}
Route it in config/routes.yaml:
casebox_rpc:
path: /api/rpc
controller: App\Controller\CaseboxRpcController::indexAction
methods: [POST]
ExtJS Client Setup
Configure your ExtJS app to target the /api/rpc endpoint with JSON payloads:
Ext.Ajax.request({
url: '/api/rpc',
method: 'POST',
jsonData: {
method: 'your_rpc_method',
params: ['data1', 'data2']
},
success: function(response) {
console.log(response.responseData);
}
});
Service Integration
RpcService into controllers/services:
public function __construct(private RpcService $rpcService) {}
handleRequest() to delegate RPC calls:
$result = $this->rpcService->handleRequest('method_name', [$arg1, $arg2]);
Exception Handling
Casebox\RpcBundle\Exception\RpcException for custom errors.config/packages/casebox_rpc.yaml:
casebox_rpc:
exception_handler: App\Service\CustomRpcExceptionHandler
Symfony CMF Integration
CaseboxRpcBundle's CMF listeners to sync data between Casebox and Symfony CMF routes.Casebox\RpcBundle\EventListener\CmfListener for custom logic.ExtJS RPC Patterns
jsonData: [
{ method: 'method1', params: [...] },
{ method: 'method2', params: [...] }
]
Promise for async RPC calls:
Ext.Ajax.request({...}).then(function(response) { ... });
Validator:
use Symfony\Component\Validator\Validator\ValidatorInterface;
public function __construct(private ValidatorInterface $validator) {}
public function validateRpcParams(array $params): void
{
$errors = $this->validator->validate($params);
if (count($errors)) {
throw new RpcException('Validation failed', $errors);
}
}
# config/routes.yaml
casebox_rpc:
path: /api/rpc
controller: App\Controller\CaseboxRpcController::indexAction
methods: [POST]
defaults: { _security: "authenticated" }
use Psr\Log\LoggerInterface;
public function __construct(private LoggerInterface $logger) {}
public function logRpcCall(string $method, array $params): void
{
$this->logger->info('RPC Call', ['method' => $method, 'params' => $params]);
}
Deprecated Symfony 3
ExtJS Version Mismatch
public function handleExtJsRequest(Request $request)
{
$data = json_decode($request->getContent(), true);
if (isset($data['method'])) {
// ExtJS 4/5 format
return $this->handleRpc($data['method'], $data['params'] ?? []);
} elseif (isset($data[0]['method'])) {
// ExtJS 6+ batch format
return array_map(function($call) {
return $this->handleRpc($call['method'], $call['params'] ?? []);
}, $data);
}
}
CMF Route Conflicts
casebox_rpc:
path: /api/v1/rpc
# ...
AGPL License Risks
Enable RPC Logging
Add to config/packages/monolog.yaml:
handlers:
casebox_rpc:
type: stream
path: "%kernel.logs_dir%/casebox_rpc.log"
level: debug
channels: ["casebox_rpc"]
Then log in your RPC service:
$this->logger->debug('RPC Request', ['data' => $requestData]);
Inspect Raw Requests Dump RPC payloads in a controller:
public function debugRpc(Request $request)
{
file_put_contents(
'/tmp/rpc_debug.log',
print_r($request->toArray(), true)
);
return $this->rpcService->handleRequest(...);
}
Test with curl
Manually test RPC endpoints:
curl -X POST http://localhost/api/rpc \
-H "Content-Type: application/json" \
-d '{"method":"test_method","params":["arg1"]}'
Custom RPC Methods
Register new RPC methods in services.yaml:
services:
App\Rpc\CustomRpcMethod:
tags: [casebox_rpc.method]
arguments:
$methodName: 'custom_method'
$handler: '@app.service.custom_handler'
Override Exception Handler Create a custom handler:
// src/Service/CustomRpcExceptionHandler.php
namespace App\Service;
use Casebox\RpcBundle\Exception\RpcExceptionHandlerInterface;
class CustomRpcExceptionHandler implements RpcExceptionHandlerInterface
{
public function handle(RpcException $exception): array
{
return [
'success' => false,
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
'details' => $exception->getDetails() ?? []
];
}
}
Configure in config/packages/casebox_rpc.yaml:
casebox_rpc:
exception_handler: App\Service\CustomRpcExceptionHandler
Add Middleware Extend the RPC pipeline with middleware:
// src/EventSubscriber/RpcMiddlewareSubscriber.php
namespace App\EventSubscriber;
use Casebox\RpcBundle\Event\RpcEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class RpcMiddlewareSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
RpcEvent::PRE_HANDLE => 'onPreHandle',
RpcEvent::POST_HANDLE => 'onPostHandle'
];
}
public function onPreHandle(RpcEvent $event): void
{
// Pre-processing logic
}
public function onPostHandle(RpcEvent $event): void
How can I help you explore Laravel packages today?