2017 © Pedro Peláez
 

library navitia

Navitia Component

image

canaltp/navitia

Navitia Component

  • Tuesday, May 30, 2017
  • by packagistctp
  • Repository
  • 37 Watchers
  • 4 Stars
  • 3,668 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 13 Forks
  • 0 Open issues
  • 47 Versions
  • 9 % Grown

The README.md

Navitia Component

Navitia Component is a PHP library to query Navitia Api (https://api.navitia.io), and controls query parameters., (*1)

Requirements

  • PHP: >=7.4
  • a Navitia token

Note: If you don't have a Navitia token yet, you have to register here: https://navitia.io/register, (*2)

Choose your version

  • NavitiaComponent v1.x.x used by legacy projects in production (example NMM Realtime), (*3)

  • NavitiaComponent v2.x.x compatible with frameworks like Symfony4, (*4)

  • NavitiaComponent v3.0.0 compatible with modern frameworks like Symfony5.4, with old firm name CanalTP, (*5)

  • NavitiaComponent v3.1.x compatible with modern frameworks like Symfony5.4, with present firm name Hove, (*6)

Installation

Using composer:, (*7)

composer require "hove/navitia":"^3.1"

example for previous versions (before v3.1.x, deprecated), (*8)

composer require "canaltp/navitia":"~2.0"

How to use NavitiaComponent ?

By autowire

In services.yaml file of your app, add this : ``` yaml navitia_component: class: Navitia\Component\Service\ServiceFacade factory: [Navitia\Component\Service\ServiceFacade, getInstance] calls: - [ setCache, ["@cache.app.taggable"]] - [ setConfiguration, ["%navitia_config%"]], (*9)


And then add `@navitia_component` to the service that used NavitiaComponent like this : ``` yaml App\Service\Navitia: class: App\Service\Navitia arguments: ['@navitia_component']

Set configuration:, (*10)

You can pass an array of config with the setConfiguration function., (*11)

``` php namespace App\Service;, (*12)

use Navitia\Component\Service\ServiceFacade;, (*13)

class Navitia { private ServiceFacade $navitiacomponent;, (*14)

function __construct(ServiceFacade $navitiacomponent)
{
    $this->navitiacomponent = $navitiacomponent;
    // Configuration
    $config = array(
        'url' => 'api.navitia.io',
        'token' => '3b036afe-4242-abcd-4242-99718476c2e0', // Example of token
    );
    $this->navitiacomponent->setConfiguration($config);
}

}, (*15)


| Name | Type | Description | Accepted values | Default value | | :------------------ | :--------- |:----------------------: | :----------------: | ------------: | | `url` (required) | `string` | Base url of Navitia | | | | `token` (required) | `string` | Your token | | | | `timeout` | `int` | Navitia timeout (in ms) | | `6000` | | `version` | `string` | Api version | `v1` | `v1` | | `format` | `string` | Wanted output format | `json`, `object` | `object` | Query example: ``` php $query = array( 'api' => 'journeys', 'parameters' => array( 'from' => '2.3749036;48.8467927', 'to' => '2.2922926;48.8583736', ), ); $result = $this->navitiacomponent->call($query); // Returns an object with Api result

Config parameters:, (*16)

Uses cases

Navitia component supports these apis:, (*17)

  • Journeys
  • Coverage
  • Departures

Journeys

Example of an itinerary:, (*18)

``` php $query = array( 'api' => 'journeys', 'parameters' => array( 'from' => '2.3749036;48.8467927', 'to' => '2.2922926;48.8583736', ), );, (*19)

$result = $this->navitiacomponent->call($query);, (*20)


See also: http://doc.navitia.io/#journeys #### Coverage Example, retrieve metadata about a coverage: ``` php $query = array( 'api' => 'coverage', 'parameters' => array( 'region' => 'sandbox', ), ); $result = $this->navitiacomponent->call($query);

See also: http://doc.navitia.io/#coverage, (*21)

Departures

Example, get all next departures of a line and at a datetime:, (*22)

``` php $query = array( 'api' => 'departures', 'parameters' => array( 'region' => 'sandbox', 'path_filter' => '/lines/line:RAT:M1/departures?from_datetime=20160615T1337' ), );, (*23)

$result = $this->navitiacomponent->call($query);, (*24)


See also: http://doc.navitia.io/#departures ### Calling any other Api To query Navitia with any other url using this component and the config you have provided, this pattern do the trick: ``` php $query = array( 'api' => 'coverage', 'parameters' => array( 'region' => 'sandbox', // Coverage name 'path_filter' => 'stop_areas?variable=value', // Url to call ), ); $result = $this->navitiacomponent->call($query); // Will call http://api.navitia.io/v1/coverage/sandbox/stop_areas?variable=value

Using query builder

You can use a query builder:, (*25)

``` php use Navitia\Component\Request\JourneysRequest; use Navitia\Component\Request\Parameters\JourneysParameters;, (*26)

$query = new JourneysRequest();, (*27)

$actionParameters = new JourneysParameters();, (*28)

$actionParameters ->setFrom('2.3749036;48.8467927') ->setTo('2.2922926;48.8583736') ->setDatetime('20160819T153000') ;, (*29)

$query->setParameters($actionParameters);, (*30)

$result = $this->navitiacomponent->call($query);, (*31)


Using query builder to get all next departures: ``` php use Navitia\Component\Request\Parameters\CoverageDeparturesParameters; use Navitia\Component\Request\DeparturesRequest; $query = new DeparturesRequest(); $query->setRegion('sandbox')->setPathFilter('lines/line:RAT:M1'); $actionParameters = new CoverageDeparturesParameters(); $actionParameters->setDuration(1); $actionParameters->setFromDatetime('20160615T1337'); $actionParameters->setForbiddenUris(['lines', 'modes']); $actionParameters->setDataFreshness('realtime'); $query->setParameters($actionParameters); $result = $this->navitiacomponent->call($query);

Running Tests

For this part, you should use docker (need install) and launch it with :, (*32)

make all_tests_dev

License

The library is under MIT., (*33)

The Versions

30/05 2017

dev-master

9999999-dev

Navitia Component

  Sources   Download

MIT

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

30/05 2017

v1.3.6

1.3.6.0

Navitia Component

  Sources   Download

MIT

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

12/01 2017

v1.3.5

1.3.5.0

Navitia Component

  Sources   Download

MIT

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

21/12 2016

v1.3.4

1.3.4.0

Navitia Component

  Sources   Download

MIT

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

03/11 2016

v1.3.3

1.3.3.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

10/10 2016

v1.3.2

1.3.2.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

27/07 2016

v1.3.1

1.3.1.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

23/06 2016

v1.3.0

1.3.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

03/06 2016

v1.2.1

1.2.1.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

02/06 2016

v1.2.0

1.2.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

17/05 2016

v1.1.7

1.1.7.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

15/02 2016

v1.1.6

1.1.6.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

21/08 2015

v1.1.5

1.1.5.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

20/05 2015

v1.1.4

1.1.4.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

02/04 2015

v1.1.3

1.1.3.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

19/03 2015

v1.1.2

1.1.2.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

05/03 2015

v1.1.1

1.1.1.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

10/02 2015

v1.1.0

1.1.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

04/11 2014

v1.0.0

1.0.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

13/10 2014

v0.38.1

0.38.1.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

13/10 2014

v0.38.2

0.38.2.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

28/08 2014

v0.34.3

0.34.3.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

28/08 2014

v0.35.2

0.35.2.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

28/08 2014

v0.36.0

0.36.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

28/08 2014

v0.37.1

0.37.1.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

28/07 2014

v0.32.0

0.32.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

24/07 2014

v0.31.3

0.31.3.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

23/07 2014

v0.31.2

0.31.2.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

05/07 2014

v0.30.3

0.30.3.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

19/06 2014

v0.29.3

0.29.3.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

16/06 2014

v0.29.2

0.29.2.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

29/04 2014

v0.26.0

0.26.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

18/04 2014

v0.25.1

0.25.1.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

16/04 2014

v0.25.0

0.25.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

26/03 2014

v0.23.3

0.23.3.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

18/03 2014

v0.23.0

0.23.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

04/03 2014

v0.22.0

0.22.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

11/02 2014

v0.20.2

0.20.2.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

31/01 2014

v0.20.0

0.20.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

12/12 2013

v0.17.0

0.17.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

06/12 2013

v0.16

0.16.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

08/11 2013

v0.14.2

0.14.2.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

25/10 2013

v0.13

0.13.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

11/10 2013

v0.12

0.12.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

25/09 2013

v0.11

0.11.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

30/08 2013

v0.9

0.9.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye

29/08 2013

v0.8

0.8.0.0

Navitia Component

  Sources   Download

proprietary

The Requires

 

by Johan Rouve
by Ramatoulaye Ndiaye