From 38d544a5f7b5e4fad61328ed3e7af2882fb5d9a2 Mon Sep 17 00:00:00 2001 From: Bernd Storath Date: Tue, 11 Jun 2024 12:50:02 +0200 Subject: [PATCH] api: add grpc php support (#431) --- Makefile | 1 + api/Dockerfile-php | 9 +++++ api/Makefile | 7 +++- api/docker-compose.yml | 7 ++++ api/php/Makefile | 40 +++++++++++++++++++ api/php/README.md | 44 +++++++++++++++++++++ api/php/composer.json | 23 +++++++++++ api/proto/api/application.proto | 2 + api/proto/api/device.proto | 2 + api/proto/api/device_profile.proto | 2 + api/proto/api/device_profile_template.proto | 2 + api/proto/api/gateway.proto | 2 + api/proto/api/internal.proto | 2 + api/proto/api/multicast_group.proto | 2 + api/proto/api/relay.proto | 2 + api/proto/api/tenant.proto | 2 + api/proto/api/user.proto | 2 + api/proto/common/common.proto | 2 + api/proto/gw/gw.proto | 2 + api/proto/integration/integration.proto | 2 + api/proto/stream/api_request.proto | 2 + api/proto/stream/backend_interfaces.proto | 2 + api/proto/stream/frame.proto | 2 + api/proto/stream/meta.proto | 2 + 24 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 api/Dockerfile-php create mode 100644 api/php/Makefile create mode 100644 api/php/README.md create mode 100644 api/php/composer.json diff --git a/Makefile b/Makefile index 9a7fc35c..097d9303 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ version: sed -i 's/^version.*/version = "$(VERSION)"/g' ./api/rust/Cargo.toml sed -i 's/^version.*/version = "$(VERSION)"/g' ./api/java/build.gradle.kts sed -i 's/^version.*/version = "$(VERSION)"/g' ./api/kotlin/build.gradle.kts + sed -i 's/"version.*/"version": "$(VERSION)",/g' ./api/php/composer.json cd api && make make build-ui diff --git a/api/Dockerfile-php b/api/Dockerfile-php new file mode 100644 index 00000000..74ee6ccf --- /dev/null +++ b/api/Dockerfile-php @@ -0,0 +1,9 @@ +FROM php:8.1-bookworm + +RUN apt update -y +RUN apt install -y make protobuf-compiler protobuf-compiler-grpc + +ENV PROJECT_PATH=/chirpstack/api + +RUN mkdir -p PROJECT_PATH +WORKDIR $PROJECT_PATH diff --git a/api/Makefile b/api/Makefile index 0c03c39a..15659580 100644 --- a/api/Makefile +++ b/api/Makefile @@ -1,6 +1,6 @@ -.PHONY: rust grpc-web go js python md java kotlin csharp +.PHONY: rust grpc-web go js python md java kotlin csharp php -all: rust grpc-web go js python md java kotlin csharp +all: rust grpc-web go js python md java kotlin csharp php rust: cd rust && make @@ -28,3 +28,6 @@ kotlin: csharp: docker compose run --rm chirpstack-csharp + +php: + docker compose run --rm chirpstack-api-php \ No newline at end of file diff --git a/api/docker-compose.yml b/api/docker-compose.yml index aaa890d4..733f79c0 100644 --- a/api/docker-compose.yml +++ b/api/docker-compose.yml @@ -42,3 +42,10 @@ services: command: bash -c "cd csharp && make all" volumes: - ./:/chirpstack/api + chirpstack-api-php: + build: + context: . + dockerfile: Dockerfile-php + command: bash -c "cd php && make all" + volumes: + - ./:/chirpstack/api diff --git a/api/php/Makefile b/api/php/Makefile new file mode 100644 index 00000000..8f17aef9 --- /dev/null +++ b/api/php/Makefile @@ -0,0 +1,40 @@ +.PHONY: requirements common gw api integration stream google + +PROTOC_ARGS := -I=../proto --grpc_out=./generated --plugin=protoc-gen-grpc=/usr/bin/grpc_php_plugin --php_out=./generated + +all: requirements common gw api integration stream google + +requirements: + rm -rf generated + mkdir generated + +common: + protoc ${PROTOC_ARGS} common/common.proto + +gw: + protoc ${PROTOC_ARGS} gw/gw.proto + +api: + protoc ${PROTOC_ARGS} api/internal.proto + protoc ${PROTOC_ARGS} api/user.proto + protoc ${PROTOC_ARGS} api/tenant.proto + protoc ${PROTOC_ARGS} api/application.proto + protoc ${PROTOC_ARGS} api/device_profile.proto + protoc ${PROTOC_ARGS} api/device_profile_template.proto + protoc ${PROTOC_ARGS} api/device.proto + protoc ${PROTOC_ARGS} api/gateway.proto + protoc ${PROTOC_ARGS} api/multicast_group.proto + protoc ${PROTOC_ARGS} api/relay.proto + +integration: + protoc ${PROTOC_ARGS} integration/integration.proto + +stream: + protoc ${PROTOC_ARGS} stream/meta.proto + protoc ${PROTOC_ARGS} stream/frame.proto + protoc ${PROTOC_ARGS} stream/api_request.proto + protoc ${PROTOC_ARGS} stream/backend_interfaces.proto + +google: + protoc ${PROTOC_ARGS} google/api/annotations.proto + protoc ${PROTOC_ARGS} google/api/http.proto \ No newline at end of file diff --git a/api/php/README.md b/api/php/README.md new file mode 100644 index 00000000..9e1b854e --- /dev/null +++ b/api/php/README.md @@ -0,0 +1,44 @@ +# chirpstack-api + +ChirpStack gRPC API message and service wrappers for PHP. + +## Install + +With composer: + +```sh +composer require chirpstack/chirpstack-api +``` + +## Usage + +All messages, services, constants, etc. are auto-generated from the ChirpStack protobuf definitions. The result is that +this package structure matches that of the protobuf definitions. + +The protobuf definitions can be found here: https://github.com/chirpstack/chirpstack/tree/master/api/proto + +## Example + +```php + ChannelCredentials::createInsecure()]); + $client = new ApplicationServiceClient('url', [], $channel); + $request = new ListApplicationsRequest(); + $response = $client->List($request); + $data = $response->wait(); + print_r($data); +} + +main(); +``` diff --git a/api/php/composer.json b/api/php/composer.json new file mode 100644 index 00000000..acdd5994 --- /dev/null +++ b/api/php/composer.json @@ -0,0 +1,23 @@ +{ + "name": "chirpstack/chirpstack-api", + "description": "Chirpstack PHP API", + "license": "MIT", + "type": "library", + "version": "4.8.1", + "require": { + "php": ">=7.0.0", + "grpc/grpc": "^v1.57.0", + "google/protobuf": "^v4.27.1" + }, + "suggest": { + "ext-grpc": "To make it all work" + }, + "autoload": { + "psr-4": { + "Chirpstack\\": "generated/Chirpstack/", + "Google\\": "generated/Google/", + "GPBMetadata\\Chirpstack\\": "generated/GPBMetadata/Chirpstack/", + "GPBMetadata\\Google\\": "generated/GPBMetadata/Google/" + } + } +} diff --git a/api/proto/api/application.proto b/api/proto/api/application.proto index ca09c6a1..24397d79 100644 --- a/api/proto/api/application.proto +++ b/api/proto/api/application.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "ApplicationProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/api/device.proto b/api/proto/api/device.proto index ad1bafb7..f80a2f15 100644 --- a/api/proto/api/device.proto +++ b/api/proto/api/device.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "DeviceProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "common/common.proto"; import "google/api/annotations.proto"; diff --git a/api/proto/api/device_profile.proto b/api/proto/api/device_profile.proto index 0d6b3823..102dcc2c 100644 --- a/api/proto/api/device_profile.proto +++ b/api/proto/api/device_profile.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "DeviceProfileProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/api/device_profile_template.proto b/api/proto/api/device_profile_template.proto index 1f28a5d7..c302dd02 100644 --- a/api/proto/api/device_profile_template.proto +++ b/api/proto/api/device_profile_template.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "DeviceProfileTemplateProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/api/gateway.proto b/api/proto/api/gateway.proto index 1d007144..024d5f3e 100644 --- a/api/proto/api/gateway.proto +++ b/api/proto/api/gateway.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "GatewayProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/api/internal.proto b/api/proto/api/internal.proto index d033e252..49f68f11 100644 --- a/api/proto/api/internal.proto +++ b/api/proto/api/internal.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "InternalProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/protobuf/timestamp.proto"; import "google/protobuf/empty.proto"; diff --git a/api/proto/api/multicast_group.proto b/api/proto/api/multicast_group.proto index 7548e046..92104e0f 100644 --- a/api/proto/api/multicast_group.proto +++ b/api/proto/api/multicast_group.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "MulticastGroupProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/api/relay.proto b/api/proto/api/relay.proto index 2a29073f..fa12800b 100644 --- a/api/proto/api/relay.proto +++ b/api/proto/api/relay.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "RelayProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/api/tenant.proto b/api/proto/api/tenant.proto index e1a20f30..b3f48983 100644 --- a/api/proto/api/tenant.proto +++ b/api/proto/api/tenant.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "TenantProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/api/user.proto b/api/proto/api/user.proto index 68a51a5a..4b92f663 100644 --- a/api/proto/api/user.proto +++ b/api/proto/api/user.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "UserProto"; option csharp_namespace = "Chirpstack.Api"; +option php_namespace = "Chirpstack\\Api"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api"; import "google/api/annotations.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/common/common.proto b/api/proto/common/common.proto index 1a9a290e..ceb08aed 100644 --- a/api/proto/common/common.proto +++ b/api/proto/common/common.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api"; option java_multiple_files = true; option java_outer_classname = "CommonProto"; option csharp_namespace = "Chirpstack.Common"; +option php_namespace = "Chirpstack\\Common"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Common"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/gw/gw.proto b/api/proto/gw/gw.proto index 9acf6128..03e8f7f9 100644 --- a/api/proto/gw/gw.proto +++ b/api/proto/gw/gw.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api.gw"; option java_multiple_files = true; option java_outer_classname = "GatewayProto"; option csharp_namespace = "Chirpstack.Gateway"; +option php_namespace = "Chirpstack\\Gateway"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Gateway"; import "common/common.proto"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/integration/integration.proto b/api/proto/integration/integration.proto index 77e3b8e0..c96d32d9 100644 --- a/api/proto/integration/integration.proto +++ b/api/proto/integration/integration.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api.integration"; option java_multiple_files = true; option java_outer_classname = "IntegrationProto"; option csharp_namespace = "Chirpstack.Integration"; +option php_namespace = "Chirpstack\\Integration"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Integration"; import "common/common.proto"; import "gw/gw.proto"; diff --git a/api/proto/stream/api_request.proto b/api/proto/stream/api_request.proto index dd2d80e3..765da729 100644 --- a/api/proto/stream/api_request.proto +++ b/api/proto/stream/api_request.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api.stream"; option java_multiple_files = true; option java_outer_classname = "ApiRequestProto"; option csharp_namespace = "Chirpstack.Stream"; +option php_namespace = "Chirpstack\\Stream"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Stream"; import "google/protobuf/timestamp.proto"; import "common/common.proto"; diff --git a/api/proto/stream/backend_interfaces.proto b/api/proto/stream/backend_interfaces.proto index ca0957b4..cb59d510 100644 --- a/api/proto/stream/backend_interfaces.proto +++ b/api/proto/stream/backend_interfaces.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api.stream"; option java_multiple_files = true; option java_outer_classname = "BackendInterfacesProto"; option csharp_namespace = "Chirpstack.Stream"; +option php_namespace = "Chirpstack\\Stream"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Stream"; import "google/protobuf/timestamp.proto"; diff --git a/api/proto/stream/frame.proto b/api/proto/stream/frame.proto index 509e1e8b..75ebe20c 100644 --- a/api/proto/stream/frame.proto +++ b/api/proto/stream/frame.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api.stream"; option java_multiple_files = true; option java_outer_classname = "FrameProto"; option csharp_namespace = "Chirpstack.Stream"; +option php_namespace = "Chirpstack\\Stream"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Stream"; import "google/protobuf/timestamp.proto"; import "common/common.proto"; diff --git a/api/proto/stream/meta.proto b/api/proto/stream/meta.proto index 83a6b227..511aae7e 100644 --- a/api/proto/stream/meta.proto +++ b/api/proto/stream/meta.proto @@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api.stream"; option java_multiple_files = true; option java_outer_classname = "MetaProto"; option csharp_namespace = "Chirpstack.Stream"; +option php_namespace = "Chirpstack\\Stream"; +option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Stream"; import "common/common.proto"; import "gw/gw.proto";