Giter Site home page Giter Site logo

gtfs-realtime-bindings-php's Introduction

PHP GTFS-realtime Language Bindings

PHP version

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:

PHP 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.

gtfs-realtime-bindings-php's People

Contributors

bdferris avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.