Search by

omnisense / omnitravel

GlitchArt

Omnitravel: going from A to B under any PHP host, whoever keeps the data - a stop's or a station's next departures and arrivals in real time (delays, platforms, gates, cancellations), journeys across modes, where vehicles are, the network's stops and lines with their colours. One family for urban tr

Package info

github.com/glitchr-omnisense/omnitravel

pkg:composer/omnisense/omnitravel

Statistics

Installs: 113

Dependents: 3

Suggesters: 1

Stars: 0

Open Issues: 0

v1.0.0 2026-11-13 10:32 UTC

This package is auto-updated.

Last update: 2026-11-30 10:39:43 UTC


README

Going from A to B under any PHP host, whoever keeps the data: one family for urban transit, trains and planes, in four contracts.

Contract What it answers
TimetablesInterface a stop's or a station's next departures and arrivals, in real time where the provider knows it: the expected time and the delay, the platform or the gate, cancellations
ItinerariesInterface journeys from A to B across modes: their legs on foot and on board, the lines, the changes
TrackingInterface where vehicles are: buses and trains from a real-time feed, aircraft from a tracking network
NetworkInterface a network's places and lines: a stop, the stops near a point, a search by name, the lines with their colours, a line's stops in order, the operators
Provider Contracts Key
omnitravel/gtfs timetables, network, tracking - any network that publishes GTFS, imported into a store (SQLite or MySQL), with GTFS-Realtime none
omnitravel/transitous itineraries, timetables, network (no lines list) - the community-run MOTIS 2 server over the world's open feeds none (a User-Agent)
omnitravel/navitia timetables, itineraries, network - a Navitia coverage, SNCF's through api.sncf.com a token

Planned, named in the family's plan: opensky (aircraft positions), aviationstack or flightaware (flights at an airport), deutsche-bahn, ourairports (the airports themselves).

Install and a first call

composer require omnisense/omnitravel omnitravel/gtfs

No account and no network for this first call: a network's GTFS feed (here a one-line feed written by the script) imported into an SQLite store in memory, then a stop's next departures. A real network's feed is the zip it publishes (new Feed('/path/to/gtfs.zip')), in an SQLite file or MySQL; PHP needs pdo_sqlite (or pdo_mysql).

<?php

require __DIR__.'/vendor/autoload.php';

use Omnitravel\Gtfs\{Feed, GtfsFactory, Importer};
use Omnitravel\Model\DepartureQuery;
use Omnitravel\Registry;

$dir = sys_get_temp_dir().'/omnitravel-first-call';
@mkdir($dir);
file_put_contents("$dir/agency.txt", "agency_id,agency_name,agency_url,agency_timezone\nX,Example Transit,https://transit.example.org,Europe/Paris\n");
file_put_contents("$dir/stops.txt", "stop_id,stop_name,stop_lat,stop_lon\nGARE,Gare,47.4645,-0.5567\nRALL,Ralliement,47.4712,-0.5518\n");
file_put_contents("$dir/routes.txt", "route_id,agency_id,route_short_name,route_type\nA,X,A,0\n");
file_put_contents("$dir/trips.txt", "route_id,service_id,trip_id,trip_headsign\nA,DAILY,A-1,Ralliement\n");
file_put_contents("$dir/stop_times.txt", "trip_id,arrival_time,departure_time,stop_id,stop_sequence\nA-1,08:00:00,08:00:00,GARE,1\nA-1,08:06:00,08:06:00,RALL,2\n");
file_put_contents("$dir/calendar.txt", "service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date\nDAILY,1,1,1,1,1,1,1,20260101,20361231\n");

$gtfs = new GtfsFactory();                                   // the HTTP client reads real-time feeds only: none here
(new Importer($gtfs->store('sqlite::memory:')))->import(new Feed($dir), 'example');
$travel = new Registry([$gtfs], ['example' => ['factory' => 'gtfs', 'options' => ['feed' => 'example', 'dsn' => 'sqlite::memory:']]]);

$from = new DateTimeImmutable('tomorrow 07:30', new DateTimeZone('Europe/Paris'));
foreach ($travel->timetables('example')->departures(new DepartureQuery('GARE', $from, limit: 2)) as $departure) {
    echo $departure->time()->format('D j H:i'), ' line ', $departure->line?->name, ' to ', $departure->headsign, "\n";   // tomorrow 08:00 line A to Ralliement, then the day after
}

Keys: omnitravel/gtfs needs none (a network's real-time feed sometimes does, sent by reference); omnitravel/transitous needs none, only a User-Agent naming a contact, and its use must stay non-commercial; omnitravel/navitia needs a token (navitia.io, or SNCF's api.sncf.com).

With real networks:

use Omnitravel\Model\{Coordinates, DepartureQuery, JourneyQuery, Place};
use Omnitravel\Registry;

$travel = new Registry([new GtfsFactory($http), new TransitousFactory($http)], [
    'angers' => ['factory' => 'gtfs', 'options' => ['feed' => 'angers', 'dsn' => 'sqlite:/var/gtfs.sqlite']],
    'planner' => ['factory' => 'transitous', 'options' => ['user_agent' => 'MySite/1.0 (https://example.org; travel@example.org)']],
]);

$stop = $travel->network('angers')->nearby(new Coordinates(47.4712, -0.5518))[0];
$next = $travel->timetables('angers')->departures(new DepartureQuery($stop->id, limit: 5));
$ways = $travel->itineraries('planner')->journeys(new JourneyQuery(Place::at(47.4712, -0.5518), Place::at(47.4608, -0.5306)));

Usage policies

Each provider declares its usage policy as data (its policy.json: rate limits, rights, attribution, requirements, where and when it was read), and every call through timetables(), itineraries(), tracking() or network() is held to it: checked before, counted after, refused with UsageLimitReachedException once a limit is reached or while the provider asks to wait (a 429 and its Retry-After, a RateLimit field with nothing left). A site may tighten a policy in its configuration, never loosen it:

'planner' => [
    'factory' => 'transitous',
    'options' => ['user_agent' => 'MySite/1.0 (https://example.org; travel@example.org)'],
    'policy' => ['rateLimits' => [['max' => 600, 'window' => 'day', 'operations' => ['journeys']]]],
    'usage' => ['commercial' => false, 'open_source' => true],
],

$travel->policy('planner') gives the policy as the site runs it. Pass a shared RateLimiterInterface as the registry's third argument when the application runs in many processes. See docs/policies.md.

omnisense/omnitravel requires omnisense/contracts (the kernel every omnisense family builds on: provider, factory, registry, JSON client, usage policies, testing kit) and symfony/http-client-contracts, nothing else: no framework, no HTTP client of its own (each provider takes the application's). It runs the same in plain PHP, a worker, Laravel or Symfony.

The manual is in docs/: installation, Symfony, models, providers, usage policies, testing, the harness, errors, writing a provider.

MIT.