Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
66f0f4f
Update composer.json
fuhry Apr 16, 2014
3a8578e
Fix composer.json I think
fuhry Apr 16, 2014
c8c9f84
Added stub generation to PHP generator
murgatroid99 Aug 21, 2014
1642568
Merge remote-tracking branch 'murgatroid99/master'
stanley-cheung Jun 8, 2015
c9b4787
codegen: have each generated client class extends Grpc\BaseStub class…
stanley-cheung Aug 20, 2015
8d1e2f6
Merge pull request #1 from stanley-cheung/codegen_extends_grpc_basestub
stanley-cheung Aug 20, 2015
d49fbd3
codegen: add options param
stanley-cheung Aug 25, 2015
c3831c8
Merge pull request #2 from stanley-cheung/codegen_add_options_param
stanley-cheung Sep 2, 2015
b96f149
make sure call options are passed to all types of calls
stanley-cheung Dec 10, 2015
b0a40f3
Merge pull request #3 from stanley-cheung/add_call_options_to_all_calls
stanley-cheung Dec 10, 2015
dbbe084
Add optional channel param to Grpc BaseStub constructor, and fix gene…
stanley-cheung May 18, 2016
c5ffcf0
Update package name and homepage
jdpedrie Jul 6, 2016
02e2c2a
Merge pull request #5 from jdpedrie/master
stanley-cheung Jul 13, 2016
4d1af20
Rename conflicting function signature
stanley-cheung Jul 22, 2016
e5d3b55
Merge pull request #7 from stanley-cheung/php7-fix
stanley-cheung Jul 22, 2016
aa651f1
update installation instruction
stanley-cheung Jul 25, 2016
e15c884
Merge pull request #8 from stanley-cheung/update-readme
stanley-cheung Jul 25, 2016
7a02786
Use absolute namespaces in phpdoc blocks for service methods. Add app…
Sep 23, 2016
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ $data = $book->serialize($codec);

Install with Pear

pear channel-discover pear.pollinimini.net
pear install drslump/Protobuf-beta
rake pear:package version=1.0
[sudo] pear install Protobuf-1.0.tgz

You can also get the latest version by checking out a copy of the
repository in your computer.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "DrSlump/Protobuf-PHP",
"name": "stanley-cheung/protobuf-php",
"description": "PHP implementation of Google's Protocol Buffers",
"keywords": ["protobuf", "protocol buffer", "serializing"],
"homepage": "https://github.com/drslump/Protobuf-PHP",
"homepage": "https://github.com/stanley-cheung/Protobuf-PHP",
"type": "library",
"license": "MIT",
"authors": [
Expand All @@ -21,7 +21,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0"
"dev-master": "1.0-dev"
}
}
}
1 change: 0 additions & 1 deletion library/DrSlump/Protobuf/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,3 @@ public function getComment($ident, $prefix = '')
return $comment;
}
}

6 changes: 3 additions & 3 deletions library/DrSlump/Protobuf/Compiler/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public static function run($pluginExecutable)
// We have data from stdin so compile it
try {
// Create a compiler interface
$comp = new Protobuf\Compiler();
$comp = new Protobuf\Compiler(true);
echo $comp->compile($stdin);
exit(0);
} catch(\Exception $e) {
fputs(STDERR, 'ERROR: ' . $e->getMessage());
fputs(STDERR, $e->getTraceAsString());
fputs(STDERR, 'ERROR: ' . $e->getMessage() . PHP_EOL);
fputs(STDERR, $e->getTraceAsString() . PHP_EOL);
exit(255);
}
}
Expand Down
90 changes: 90 additions & 0 deletions library/DrSlump/Protobuf/Compiler/PhpGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public function generate(proto\FileDescriptorProto $proto)
$this->addComponent($namespace, $service->getName(), $src);
}
endif;
foreach($proto->getServiceList() as $service) {
$src = $this->compileStub($service, $namespace);
$this->addComponent($namespace, $service->getName() . 'Client', $src);
}

// Collect extensions
if ($proto->hasExtension()) {
Expand Down Expand Up @@ -409,6 +413,92 @@ protected function compileService(proto\ServiceDescriptorProto $service, $ns)
return implode(PHP_EOL, $s) . PHP_EOL;
}

protected function compileStub(proto\ServiceDescriptorProto $service, $ns){
$s = array();
$s[] = 'namespace ' . $this->normalizeNS($ns) . ' {';
$s[] = '';
$s[]= " // @@protoc_insertion_point(scope_namespace)";
$s[]= " // @@protoc_insertion_point(namespace_$ns)";
$s[]= '';

$cmt = $this->compiler->getComment($ns . '.' . $service->getName(), ' * ');
if($cmt){
$s[]= " /**";
$s[]= $cmt;
$s[]= " */";
}
$s[] = ' class ' . $service->getName() . 'Client extends \Grpc\BaseStub {';
$s[] = '';
$s[] = ' public function __construct($hostname, $opts, $channel = null) {';
$s[] = ' parent::__construct($hostname, $opts, $channel);';
$s[] = ' }';

foreach ($service->getMethodList() as $method){
$ns_input = $this->normalizeNS($method->getInputType());
$ns_output = $this->normalizeNS($method->getOutputType());
$s[]= ' /**';

$cmt = $this->compiler->getComment($ns . '.' . $service->getName() . '.' . $method->getName(), ' * ');
if ($cmt){
$s[]= $cmt;
$s[]= ' * ';
}

$server_stream = $method->getServerStreaming();
$client_stream = $method->getClientStreaming();

// Attach appropriate param/return types
if (! $client_stream) {
$s[]= ' * @param \\' . $ns_input . ' $argument';
}

if ($client_stream || $server_stream) {
$s[]= ' * @param array $metadata';
$s[]= ' * @param array $options';
}

if ($client_stream) {
if ($server_stream) {
$s[]= ' * @return \Grpc\BidiStreamingCall' ;
} else {
$s[]= ' * @return \Grpc\ClientStreamingCall' ;
}
} else {
if ($server_stream) {
$s[]= ' * @return \Grpc\ServerStreamingCall' ;
} else {
$s[]= ' * @return \\' . $ns_output;
}
}

$s[]= ' */';

$service_fqn = $ns . '.' . $service->getName();
if($client_stream){
if($server_stream){
$s[]= ' public function ' . $method->getName() . '($metadata = array(), $options = array()) {';
$s[]= ' return $this->_bidiRequest(\'/' . $service_fqn . '/' . $method->getName() . '\', \'\\' . $ns_output . '::deserialize\', $metadata, $options);';
} else {
$s[]= ' public function ' . $method->getName() . '($metadata = array(), $options = array()) {';
$s[]= ' return $this->_clientStreamRequest(\'/' . $service_fqn . '/' . $method->getName() . '\', \'\\' . $ns_output . '::deserialize\', $metadata, $options);';
}
} else {
if($server_stream){
$s[]= ' public function ' . $method->getName() . '($argument, $metadata = array(), $options = array()) {';
$s[]= ' return $this->_serverStreamRequest(\'/' . $service_fqn . '/' . $method->getName() . '\', $argument, \'\\' . $ns_output . '::deserialize\', $metadata, $options);';
} else {
$s[]= ' public function ' . $method->getName() . '(\\' . $ns_input . ' $argument, $metadata = array(), $options = array()) {';
$s[]= ' return $this->_simpleRequest(\'/' . $service_fqn . '/' . $method->getName() . '\', $argument, \'\\' . $ns_output . '::deserialize\', $metadata, $options);';
}
}
$s[]= ' }';
}
$s[]= ' }';
$s[]= '}';

return implode(PHP_EOL, $s) . PHP_EOL;
}

protected function generatePublicField(proto\FieldDescriptorProto $field, $ns, $indent)
{
$cmt = $this->compiler->getComment($ns . '.' . $field->getNumber(), "$indent * ");
Expand Down
Loading