google / gtfs-realtime-bindings
此包已被废弃,不再维护。未建议替代包。
由 GTFS-realtime 协议缓冲区规范生成的 PHP 类。
0.0.2
2015-02-27 05:57 UTC
Requires
- php: >=5.3.0
- centraldesktop/protobuf-php: 0.5.*
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2019-06-19 19:02:47 UTC
README
提供由 GTFS-realtime 协议缓冲区规范生成的 PHP 类。这些类将允许您将二进制协议缓冲区 GTFS-realtime 数据源解析为 PHP 对象。
有关其他语言的绑定,请参阅 gtfs-realtime-bindings 项目。
添加依赖
要在自己的项目中使用 gtfs-realtime-bindings-php
类,您需要首先安装 Packagist Composer 包。为此,在您的 composer.json
文件中添加依赖项
"require": {
"google/gtfs-realtime-bindings": "x.y.z"
}
其中 x.y.z
是最新发布版本
然后更新您的 Composer 依赖项
composer update
示例代码
以下代码片段演示了从特定 URL 下载 GTFS-realtime 数据源,将其解析为 FeedMessage(GTFS-realtime 模式的根类型),并遍历结果。
require_once 'vendor/autoload.php'; use transit_realtime\FeedMessage; $data = file_get_contents("URL OF YOUR GTFS-REALTIME SOURCE GOES HERE"); $feed = new FeedMessage(); $feed->parse($data); foreach ($feed->getEntityList() as $entity) { if ($entity->hasTripUpdate()) { error_log("trip: " . $entity->getId()); } }
有关从 gtfs-realtime.proto 生成的 PHP 类的命名约定更多详细信息,请查看 gtfs-realtime.php 源文件。