google/common-protos
Generated PHP classes for Google’s common Protocol Buffer types used across Google APIs. Stable, backwards-compatible shared dependencies published as the google/common-protos Composer package (Apache 2.0), part of the Google Cloud PHP ecosystem.
google.api.Http rules).google/protobuf (v4+), which must be installed separately. Laravel’s composer.json can include:
"require": {
"google/common-protos": "^4.0",
"google/protobuf": "^4.0"
}
grpc/grpc) or REST/JSON (via google/protobuf's JSON encoding). Laravel’s HTTP layer (e.g., Illuminate\Http\Request) can validate incoming JSON against Protobuf schemas using libraries like spatie/laravel-protobuf (if available).google.api.Http may change). Breaking changes (e.g., field removals) could require updates to Laravel’s API contracts. Mitigate by:
optional fields, oneof).google/protobuf's built-in validation or integrate with Laravel’s exception handling:
try {
$message = YourProtobufClass::parseFromString($data);
} catch (\Google\Protobuf\Exception $e) {
throw new \InvalidArgumentException("Protobuf decode error: " . $e->getMessage());
}
Illuminate\Validation or custom middleware. Example:
use Google\Api\HttpRule;
use Google\Protobuf\Internal\Message;
public function validateProtobuf(Request $request, string $protoClass): void
{
$data = $request->json()->all();
$message = new $protoClass();
if (!$message->mergeFromArray($data)) {
throw new \InvalidArgumentException("Invalid Protobuf structure");
}
}
grpc/grpc and Laravel’s HTTP server (e.g., via reactphp or swoole). Protobuf messages will replace Laravel’s native request/response objects.Illuminate\Queue) or Laravel Events for decoupled communication.google.protobuf.Any or domain-specific messages).// Before: JSON-based
public function store(Request $request) {
$data = $request->validate([...]);
return User::create($data);
}
// After: Protobuf-based
public function store(Request $request) {
$protoData = new UserProto();
$protoData->mergeFromArray($request->json()->all());
$user = User::create([
'name' => $protoData->getName(),
'email' => $protoData->getEmail(),
]);
return response()->json($user->toProtobuf());
}
.proto files against Laravel’s API specs).owlbot as shown in the changelog).deprecated() helper or custom middleware to warn clients.php-version constraint in composer.json is updated:
"config": {
"platform": {
"php": "8.2"
}
}
google/protobuf:^4.0 (latest stable). Avoid mixing versions.$this->app->bind(YourProtobufClass::class, function () {
return new YourProtobufClass();
});
google/cloud-storage), ensure they are compatible versions (e.g., google/cloud-common-protos may be a dependency).google/protobuf's JSON encoding for backward compatibility.How can I help you explore Laravel packages today?