Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add php rpc #76

Merged
merged 7 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions php/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wechaty-php-grpc.*/
26 changes: 26 additions & 0 deletions php/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Makefile for PHP Wechaty
#
# GitHb: https://github.com/wechaty/php-wechaty
# Author: Chunsheng Zhang <zhangchunsheng423@gmail.com> https://git.io/JJmKd
#

.PHONY: all
all : clean lint

.PHONY: clean
clean:
rm -fr generated/*

.PHONY: test
test:
bash -x ./generate.sh
php grpc_test.php

.PHONY: generate
generate:
bash -x ./generate.sh

.PHONY: publish
publish: clean generate
./publish.sh

31 changes: 31 additions & 0 deletions php/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -eo pipefail

PROTO_BASE_DIR=../proto
PROTO_PUPPET_DIR=$PROTO_BASE_DIR/wechaty/puppet
PROTO_WECHATY_DIR=$PROTO_BASE_DIR/wechaty

OUT_WECHATY_DIR=./generated/wechaty
OUT_PUPPET_DIR=$OUT_WECHATY_DIR

if [ ! -d "$PUPPET_GEN_DIR" ]; then
mkdir -p $OUT_PUPPET_DIR
fi

protoc --version

protoc \
-I $PROTO_PUPPET_DIR \
--php_out=$OUT_PUPPET_DIR \
--grpc_out=$OUT_PUPPET_DIR \
--plugin=protoc-gen-grpc=../../grpc-demo/grpc/bins/opt/grpc_php_plugin \
$PROTO_PUPPET_DIR/*.proto

protoc \
-I $PROTO_WECHATY_DIR \
-I $PROTO_PUPPET_DIR \
--php_out=$OUT_WECHATY_DIR \
--grpc_out=$OUT_WECHATY_DIR \
--plugin=protoc-gen-grpc=../../grpc-demo/grpc/bins/opt/grpc_php_plugin \
$PROTO_WECHATY_DIR/*.proto
30 changes: 30 additions & 0 deletions php/grpc_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: peterzhang
* Date: 2020/7/10
* Time: 2:11 PM
*/

define("ROOT", __DIR__);

function autoload($clazz) {
$file = str_replace('\\', '/', $clazz);
if(is_file(ROOT . "/generated/wechaty/$file.php")) {
require ROOT . "/generated/wechaty/$file.php";
} else {
$file = str_replace('\\', '/', $clazz);
if(is_file("/usr/share/pear/$file.php")) {
require "/usr/share/pear/$file.php";
}
}
}

spl_autoload_register("autoload");

$client = new \Wechaty\PuppetClient("localhost:8788", [
'credentials' => Grpc\ChannelCredentials::createInsecure()
]);
$request = new \Wechaty\Puppet\DingRequest();
list($response, $status) = $client->Ding($request)->wait();
echo sprintf("code: %s, msg: %s \n", $status->code, $status->details);
45 changes: 45 additions & 0 deletions php/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -eo pipefail

GENERATED_DIR="$(pwd)/generated"

VERSION=$(jq -r .version ../package.json)
DEPLOY_DIR="wechaty-php-grpc.$$"

mkdir "$DEPLOY_DIR"
pushd "$DEPLOY_DIR"
# trap "rm -rfv $(pwd)/$DEPLOY_DIR" EXIT

git clone git@github.com:wechaty/php-grpc.git
cd php-grpc
cp -Rav "$GENERATED_DIR"/wechaty .
echo "$VERSION" > VERSION

if [ -z "$(git status --porcelain)" ]; then
echo
echo "[Publish] There's no new generated code found"
echo
exit 0
fi

git \
-c "user.name=zhangchunsheng" \
-c "user.email=zhangchunsheng423@gmail.com" \
\
commit \
-am "Deploy PHP Grpc Module v${VERSION}"

git push
echo
echo '[Publish] New code has been generated and pushed'
echo

git tag v"$VERSION"
git push origin v"$VERSION"
echo
echo "[Publish] New version ${VERSION} has been tagged"
echo

git status
popd