google/gax
Google API Core for PHP (gax-php) provides shared infrastructure for Google API clients, especially generated libraries using gRPC. Includes helpers for retries, pagination/page streaming, long-running operations, and Google API conventions. Requires PHP 8.1+.
google/protobuf (v4.31+), which may necessitate additional tooling (e.g., protoc for protobuf compilation). Laravel’s monolithic structure could complicate protobuf management unless modularized..proto files (via gapic-generator-php). Laravel teams must adopt this workflow, which may conflict with existing REST-based APIs or require dual-maintenance.TransportCallMiddleware and prependMiddleware align with Laravel’s middleware stack (e.g., Illuminate\Http\Middleware), enabling custom interceptors for logging, auth, or retries.GapicClientTrait, OperationResponse) are unfamiliar to most Laravel devs. Training or documentation gaps could slow adoption.protoc) and dependency management (e.g., google/protobuf) add complexity. Laravel’s composer.json may need strict version pinning to avoid conflicts.ApiException and ApiException::getErrorDetails() require custom handling in Laravel’s exception stack (e.g., App\Exceptions\Handler). May need to extend Laravel’s render() method.InsecureCredentialsWrapper for local testing complicate CI/CD pipelines (e.g., Docker setups must include emulator dependencies)..proto files be managed? Will the team adopt auto-generation, or will manual clients be written?ApiException be mapped to Laravel’s exception system (e.g., HttpResponseException)?gax-php be isolated in a microservice, or integrated directly into Laravel’s monolith? Risk of version conflicts with other packages.AppServiceProvider::boot()) and middleware stack (e.g., wrap GapicClientTrait in Laravel middleware).react/grpc).bus:dispatch).GapicClientTrait methods in PHPUnit), but emulator setup may be needed for integration tests.Log facade for TransportCallMiddleware logging.gapic-generator-php to generate clients and integrate via composer require google/gax.config/caching.php to toggle between REST/gRPC routes.HttpClient facade to support gRPC (e.g., Http::gRPC()).protoc is installed in CI/CD (e.g., GitHub Actions) and local dev environments.grpc and grpc_cpp_plugin). Docker containers must include these (e.g., FROM php:8.1-cli with RUN pecl install grpc).google/protobuf (e.g., spatie/laravel-google-drive). Use composer.json overrides or monorepo isolation.protoc and gRPC extensions to devops pipelines.composer.json with strict google/gax and google/protobuf versions.app/Google/Api/ (or a module).AppServiceProvider:
$this->app->singleton(StorageClient::class, function ($app) {
return new StorageClient(['credentials' => $app['google.credentials']]);
});
app/Http/Middleware/GrpcAuth.php):
public function handle($request, Closure $next) {
$client = app(StorageClient::class);
$client->prependMiddleware(new TransportCallMiddleware(new Logger()));
return $next($request);
}
class ProcessPubSubMessage implements ShouldQueue {
public function handle() {
$client = app(PubSubClient::class);
$client->streamingPull(...)->each(fn ($message) => Log::info($message));
}
}
google/gax is GA but requires careful version updates due to protobuf dependencies. Use composer why-not to audit changes..proto files, regenerate clients and test thoroughly. Consider a CI check to validate schema compatibility.Log facade for TransportCallMiddleware logs. Centralize gRPC logs in a dedicated channel (e.g., gax).ApiException::getErrorDetails() to surface gRPC-specific errors in Laravel’s exception handler:
public function render($request, Throwable $exception) {
if ($exception instanceof ApiException) {
return response()->json([
'error' => $exception->getMessage(),
'details' => $exception->getErrorDetails(),
], 400);
}
return parent::render($request, $exception);
}
README.md (e.g., Docker Compose for emulator + Laravel).grpc_health_probe or custom scripts to test gRPC endpoints under load. Laravel’s queue workers can handle async gRPC responses.Illuminate\Cache to implement gRPC-specific circuit breakers (e.g., retry logic in GapicClientTrait).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| gRPC connection drops | Timeouts |
How can I help you explore Laravel packages today?