Protobuf PHP:无法成功执行protoc gen PHP


Protobuf-PHP: Cannot Successfully Execute protoc-gen-php

我克隆了Protobuf PHP存储库:https://github.com/drslump/Protobuf-PHP.git我在https://github.com/drslump/Protobuf-PHP,我已经处理了大约12个小时的安装和配置问题,试图让protoc-gen.php将proto文件转换为php类。

我正在运行PHP 5.3.2版本,下面是我所做的:

  1. 已安装PEAR v1.9.4
  2. 安装Console_CommandLine,并运行PEAR_ENV.reg来设置PEAR环境变量
  3. 我已经尝试了我能想到的每一种排列,试图让这个插件生成一个PHP类文件,但每一次尝试都失败了

我有一个proto文件,我们正在根文件夹中与C#项目一起使用,我在那里签出了proto-gen-php项目(见下文)。

    message AuditLogEntry {
        required int64 ID = 1;
        required int64 Date = 2;
        required string Message = 3;
        optional int32 User_ID = 4;
        optional string User_Username = 5;
        optional int32 ImpUser_ID = 6;
        optional string ImpUser_Username = 7;
        optional string RemoteIP = 8;
    }

    message AuditLogQuery {
        optional int64 DateRangeStart = 1;
        optional int64 DateRangeEnd = 2;
        optional string Search = 3;
        optional int32 UserID = 4;
        optional int32 Limit = 5;
        optional int32 Offset = 6;
    }
    message AuditLogResult {
        repeated AuditLogEntry LogEntries = 1;
        optional int32 TotalResults = 2;
    }

以下是我遇到的几个问题:

  1. 当我尝试执行最基本的实现时:

    protoc-gen-php.bat AuditLog.proto
    

    我得到这个错误:

    无法打开输入文件:@bin_dir@''protoco-gen-php文件名、目录名或卷标语法不正确。

    我在网上找不到有关此错误的任何信息。我正在使用的某个软件包的安装是否存在配置问题?有什么想法吗?

  2. 由于上面的错误,我在protoc gen php批处理文件中更改了这一行:

    "%PHPBIN%" -d display_errors=stderr -d log_errors=On -d error_log=Off "@bin_dir@'protoc-gen-php" %*
    

    "%PHPBIN%" -d display_errors=stderr -d log_errors=On -d error_log=Off "protoc-gen-php.php" %*
    

现在,当我运行问题1中给出的相同命令时,我得到以下输出:

The filename, directory name, or volume label syntax is incorrect.
Protobuf-PHP @package_version@ by Ivan -DrSlump- Montes
C:'Development'SkedFlex'php-proto-buffers'AuditLog.proto: File does not reside within any path specified using --proto_path (or -I).  You must specify a --proto_path which encompasses this file.  Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
ERROR: protoc exited with an error (1) when executed with:
  protoc '
    --plugin=protoc-gen-php="C:'Development'SkedFlex'php-proto-buffers'protoc-gen-php.php.bat" '
    --proto_path="C:'Development'SkedFlex'php-proto-buffers'library'DrSlump'Protobuf'Compiler'protos" '
    --php_out=":./" '
    "C:'Development'SkedFlex'php-proto-buffers'AuditLog.proto"

我按照手册中的规定,使用-I、-o尝试了许多命令变体:http://drslump.github.com/Protobuf-PHP/protoc-gen-php.1.html,但似乎无法在这方面取得进展。。。

最后,我尝试直接执行协议:

protoc --plugin=protoc-gen-php --php_out=./build AuditLog.proto

这就是错误:

--php_out: protoc-gen-php: The system cannot find the file specified.

我陷入了困境。有没有人有protoc gen php的经验,可以帮助我解决我遇到的问题?

.bat文件从存储库签出后不能直接使用,它在创建Pear包时会被修改。因此,除非您想以某种方式修改库的源代码,否则您应该使用Pear安装Protobuf PHP。

pear channel-discover pear.pollinimini.net
pear install drslump/Protobuf-beta

如果你不想从Pear安装,你必须手动修改protoc-gen-php.bat文件,将最后一行替换为类似的内容:

C:'path'to'php.exe -d display_errors=stderr -d log_errors=On -d error_log=Off c:'path'to'protobuf-php'protoc-gen-php %*

为了修复"文件不位于指定的任何路径内…"错误,您必须确保作为参数给定的任何原型文件都位于定义的包含路径内。谷歌的protoc编译器不试图猜测包含路径是什么,所以我们需要在所有情况下手动提供它们。

protoc-gen-php.bat -i . AuditLog.proto

这应该允许您为原型消息生成PHP文件,尽管该脚本在Windows系统中的测试不如在Linux和OSX系统中。如果你发现任何问题,如果你愿意,你可以直接在项目现场报告。