jkapron / gtfs-realtime-bindings
PHP classes generated from the GTFS-realtime protocol buffer specification.
Requires
- php: >=5.3.0
- centraldesktop/protobuf-php: ^1.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-11-05 04:52:11 UTC
README
Provides PHP classes generated from the GTFS-realtime Protocol Buffer specification. These classes will allow you to parse a binary Protocol Buffer GTFS-realtime data feed into PHP objects.
For bindings in other languages, see the gtfs-realtime-bindings project.
Add the Dependency
To use the gtfs-realtime-bindings-php
classes in your own project, you need
to first install the Packagist Composer
package. To do
so, add a dependency in your composer.json
file:
"require": {
"google/gtfs-realtime-bindings": "x.y.z"
}
Where x.y.z
is the latest release version:
Then update your Composer dependencies:
composer update
Example Code
The following code snippet demonstrates downloading a GTFS-realtime data feed from a particular URL, parsing it as a FeedMessage (the root type of the GTFS-realtime schema), and iterating over the results.
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()); } }
For more details on the naming conventions for the PHP classes generated from the gtfs-realtime.proto, check out the the gtfs-realtime.php source file.