Skip to content

Commit a6b77be

Browse files
add php rpc (#76)
* add php grpc * update usage * update usage * update usage * update * update usage * add php rpc
1 parent 87b4060 commit a6b77be

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

php/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wechaty-php-grpc.*/

php/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Makefile for PHP Wechaty
2+
#
3+
# GitHb: https://github.com/wechaty/php-wechaty
4+
# Author: Chunsheng Zhang <zhangchunsheng423@gmail.com> https://git.io/JJmKd
5+
#
6+
7+
.PHONY: all
8+
all : clean lint
9+
10+
.PHONY: clean
11+
clean:
12+
rm -fr generated/*
13+
14+
.PHONY: test
15+
test:
16+
bash -x ./generate.sh
17+
php grpc_test.php
18+
19+
.PHONY: generate
20+
generate:
21+
bash -x ./generate.sh
22+
23+
.PHONY: publish
24+
publish: clean generate
25+
./publish.sh
26+

php/generate.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
PROTO_BASE_DIR=../proto
6+
PROTO_PUPPET_DIR=$PROTO_BASE_DIR/wechaty/puppet
7+
PROTO_WECHATY_DIR=$PROTO_BASE_DIR/wechaty
8+
9+
OUT_WECHATY_DIR=./generated/wechaty
10+
OUT_PUPPET_DIR=$OUT_WECHATY_DIR
11+
12+
if [ ! -d "$PUPPET_GEN_DIR" ]; then
13+
mkdir -p $OUT_PUPPET_DIR
14+
fi
15+
16+
protoc --version
17+
18+
protoc \
19+
-I $PROTO_PUPPET_DIR \
20+
--php_out=$OUT_PUPPET_DIR \
21+
--grpc_out=$OUT_PUPPET_DIR \
22+
--plugin=protoc-gen-grpc=../../grpc-demo/grpc/bins/opt/grpc_php_plugin \
23+
$PROTO_PUPPET_DIR/*.proto
24+
25+
protoc \
26+
-I $PROTO_WECHATY_DIR \
27+
-I $PROTO_PUPPET_DIR \
28+
--php_out=$OUT_WECHATY_DIR \
29+
--grpc_out=$OUT_WECHATY_DIR \
30+
--plugin=protoc-gen-grpc=../../grpc-demo/grpc/bins/opt/grpc_php_plugin \
31+
$PROTO_WECHATY_DIR/*.proto

php/grpc_test.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: peterzhang
5+
* Date: 2020/7/10
6+
* Time: 2:11 PM
7+
*/
8+
9+
define("ROOT", __DIR__);
10+
11+
function autoload($clazz) {
12+
$file = str_replace('\\', '/', $clazz);
13+
if(is_file(ROOT . "/generated/wechaty/$file.php")) {
14+
require ROOT . "/generated/wechaty/$file.php";
15+
} else {
16+
$file = str_replace('\\', '/', $clazz);
17+
if(is_file("/usr/share/pear/$file.php")) {
18+
require "/usr/share/pear/$file.php";
19+
}
20+
}
21+
}
22+
23+
spl_autoload_register("autoload");
24+
25+
$client = new \Wechaty\PuppetClient("localhost:8788", [
26+
'credentials' => Grpc\ChannelCredentials::createInsecure()
27+
]);
28+
$request = new \Wechaty\Puppet\DingRequest();
29+
list($response, $status) = $client->Ding($request)->wait();
30+
echo sprintf("code: %s, msg: %s \n", $status->code, $status->details);

php/publish.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
GENERATED_DIR="$(pwd)/generated"
6+
7+
VERSION=$(jq -r .version ../package.json)
8+
DEPLOY_DIR="wechaty-php-grpc.$$"
9+
10+
mkdir "$DEPLOY_DIR"
11+
pushd "$DEPLOY_DIR"
12+
# trap "rm -rfv $(pwd)/$DEPLOY_DIR" EXIT
13+
14+
git clone git@github.com:wechaty/php-grpc.git
15+
cd php-grpc
16+
cp -Rav "$GENERATED_DIR"/wechaty .
17+
echo "$VERSION" > VERSION
18+
19+
if [ -z "$(git status --porcelain)" ]; then
20+
echo
21+
echo "[Publish] There's no new generated code found"
22+
echo
23+
exit 0
24+
fi
25+
26+
git \
27+
-c "user.name=zhangchunsheng" \
28+
-c "user.email=zhangchunsheng423@gmail.com" \
29+
\
30+
commit \
31+
-am "Deploy PHP Grpc Module v${VERSION}"
32+
33+
git push
34+
echo
35+
echo '[Publish] New code has been generated and pushed'
36+
echo
37+
38+
git tag v"$VERSION"
39+
git push origin v"$VERSION"
40+
echo
41+
echo "[Publish] New version ${VERSION} has been tagged"
42+
echo
43+
44+
git status
45+
popd

0 commit comments

Comments
 (0)