Download the PHP package language/yii2-protobuf without Composer
On this page you can find all versions of the php package language/yii2-protobuf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download language/yii2-protobuf
More information about language/yii2-protobuf
Files in language/yii2-protobuf
Package yii2-protobuf
Short Description a wrapper to decode/encode protobuf
License MIT
Informations about the package yii2-protobuf
Yii Protobuf Extension is a wrapper for php protobuf c-extension.It provides an easy way to decode/encoder protobuf data with Yii.In addition to,it provides a tool to generate php proto files from .proto.
You must install php c-ext before you can use this extension
Requirements
To use PHP runtime library requires:
- C extension:protobuf >= 3.5.0
- PHP package:php >= 7.0.0
- Yii2.0 or above
Installation
You can install this extension by composer, as follows:
Configure
You need to add protobuf parser/formatter for request/response Component, as follows:
As you can see, this extension use Content-Type to distinguish protobuf binary data.So, Client should set Content-Type as when it send protobuf binary data to Server
Generate Proto
You can run build.sh shell script to generate proto files after Editing msg.proto. it will generate and .You should always edit .proto instead of editing generated proto files
Register Proto
You need to register .proto.php files for encode protobuf data after generate proto files.You can create a base controller and register them, As follows:
ProtobufTrait provides method to convert php hash table to protobuf data
Usage
You should alway get request params with intead of .ProtobufParser parser protobuf to array
Sample
Customized Request Struct
By default, protobuf parser can only parser map<string,string> protobuf data as message-defined
You can define your request proto, as follows
Then, you should tell ProtobufFormatter which class to serialize Array Data
If you need more flexiable data-struct, you can parser the protobuf raw data, as follows:
FlexiableRequest is a internal proto define. So, don't change the message name.