PHP code example of neilmcgibbon / php-open-rail-data

1. Go to this page and download the library: Download neilmcgibbon/php-open-rail-data library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neilmcgibbon / php-open-rail-data example snippets


class ExampleEventListener
{

  public function onEventReceived(RtppmEvent $event)
  {
    echo "Received event. National page late trains count: ";
    echo $event->getNationalPage()->getPerformance()->getLateCount() . PHP_EOL;
  }
}


$connection = new \OpenRailData\NetworkRail\Services\Stomp\Connection(
  "network_rail_username",
  "network_rail_password"
);

// Create the Topic.
$topic = new OpenRailData\NetworkRail\Services\Stomp\Topics\Rtppm\RtppmTopic();

// Add our event listener to the topic
$topic->addListener(new ExampleEventListener());

// Subscribe to the topic by adding the topic to the connection
$connection->addTopic($topic);

// Start listening for events, the rest is handled by our event listener :-)
$connection->listen();