【发布时间】:2012-08-23 18:48:09
【问题描述】:
我克隆了我在https://github.com/drslump/Protobuf-PHP 找到的 Protobuf-PHP 存储库:https://github.com/drslump/Protobuf-PHP.git,我已经在安装和配置问题上工作了大约 12 个小时,试图让 protoc-gen-php 将 proto 文件转换为一个 PHP 类。
我正在运行 PHP 版本 5.3.2,这就是我所做的:
- 已安装 PEAR v1.9.4
- 安装 Console_CommandLine,运行 PEAR_ENV.reg 设置 PEAR 环境变量。
- 我已经尝试了所有我能想到的排列来尝试让这个插件生成一个 PHP 类文件,但每次尝试都失败了。
我在根文件夹中有一个用于 C# 项目的 proto 文件,我在其中签出了 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;
}
这里只是我遇到的几个问题:
-
当我尝试执行最基本的实现时:
protoc-gen-php.bat AuditLog.proto我收到此错误:
无法打开输入文件:@bin_dir@\protoc-gen-php 文件名、目录名或卷标语法不正确。
我在网上找不到有关此错误的任何信息。安装我正在使用的软件包之一是否存在配置问题?有什么想法吗?
-
由于上面的错误,我在 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:
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 经验可以帮助我解决我遇到的问题?
【问题讨论】:
标签: php protocol-buffers