PHPackages                             weble/ptv-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. weble/ptv-php

ActiveLibrary[API Development](/categories/api)

weble/ptv-php
=============

PTV Api PHP SDK

1.2.1(11mo ago)0873[1 PRs](https://github.com/Weble/ptv-php/pulls)MITPHPPHP ^8.2CI failing

Since May 23Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/Weble/ptv-php)[ Packagist](https://packagist.org/packages/weble/ptv-php)[ RSS](/packages/weble-ptv-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

PHP SDK for the PTV APIs
========================

[](#php-sdk-for-the-ptv-apis)

[![Latest Version](https://camo.githubusercontent.com/4342a7289c868e49724d9e022a539b92a2bc0ba023f1a64b81741845711eec53/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7765626c652f7074762d7068702e7376673f7374796c653d666c61742d737175617265)](https://github.com/weble/ptv-php/releases)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![run-tests](https://camo.githubusercontent.com/6c60ed574eff78aa21d8e479bd686b71777940dbc5502f44f53461e3e0d182c7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7765626c652f7074762d7068702f746573742e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/weble/ptv-php/actions)[![Total Downloads](https://camo.githubusercontent.com/4b39bd2463104303da21a6dbf176f869511b4a8ef2d2309717d5336baea2cad8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765626c652f7074762d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weble/ptv-php)

This is an SDK for the [PTV API](https://developer.myptv.com/en).

It currently implements partially the [Data API](https://developer.myptv.com/en/documentation/data-api/data-api-reference) and the [Routing API](https://developer.myptv.com/en/documentation/routing-api/routing-api-reference).

Under the hood it uses [Saloon](https://docs.saloon.dev/) to handle the requests.

It features only 2 dependencies:

- `saloonphp/saloon` to handle the requests and the SDK building in general
- `moneyphp/money` to represent the prices and currencies

Every parameter and response object is carefully mapped with a dedicated **DTO** class and **Enum**

Installation
------------

[](#installation)

`composer require weble/ptv-php`

Basic Usage
-----------

[](#basic-usage)

Just create the client and interact with each of the apis.

```
use PTV\PTV;

$ptv = new PTV('[YOUR-API-KEY]');

$profiles = $ptv->data()->vehicleProfiles()->all();
$route $ptv->routing()->route()->calculate(['lat,lng', 'lat2,lng2']);
```

### Setting a language

[](#setting-a-language)

```
use PTV\PTV;

$ptv = new PTV('[YOUR-API-KEY]', 'it');
```

Data Api
--------

[](#data-api)

Only 3 endpoints are implemented as of today:

### 1. `vehicleProfiles`

[](#1-vehicleprofiles)

```
use PTV\PTV;

$ptv = new PTV('[YOUR-API-KEY]');
$profiles = $ptv->data()->vehicleProfiles()->all();
```

### 2. `vehicleModels`

[](#2-vehiclemodels)

```
use PTV\Data\Enums\VehicleType;
use PTV\PTV;

$ptv = new PTV('[YOUR-API-KEY]');

$profiles = $ptv->data()->vehicleModels()->all();
$profiles = $ptv->data()->vehicleModels()->all([
    VehicleType::TRAILER,
    VehicleType::SEMI_TRAILER,
]);
```

### 3. `mapInformation`

[](#3-mapinformation)

```
use PTV\Data\Enums\VehicleType;
use PTV\PTV;

$ptv = new PTV('[YOUR-API-KEY]');

$mapInfo = $ptv->data()->mapInformation()->all();
```

Routing Api
-----------

[](#routing-api)

Currently only 3 endpoints are supported:

### 1. `calculate`

[](#1-calculate)

This is by far the most complete one and the most likely used. You can calculate a route by chaining parameters within the call.

Each parameter is typed for full IDE autocompletion and ease of use.

```
use Money\Currency;
use PTV\Data\Enums\EngineType;
use PTV\Data\Enums\FuelType;
use PTV\PTV;
use PTV\Routing\DTO\MonetaryCostOptions;
use PTV\Routing\DTO\Options;
use PTV\Routing\DTO\Vehicle;
use PTV\Routing\Enums\ResultType;
use PTV\Routing\Enums\TrafficMode;

$ptv = new PTV('[YOUR-API-KEY]');
$route = $ptv
    ->routing()
    ->route()
    ->return([
        ResultType::MONETARY_COSTS,
            ResultType::POLYLINE,
            ResultType::LEGS,
            ResultType::LEGS_POLYLINE,
            ResultType::ROUTE_ID,
            ResultType::TOLL_COSTS,
            ResultType::TOLL_SYSTEMS,
            ResultType::TOLL_SECTIONS,
            ResultType::TOLL_EVENTS,
            ResultType::ALTERNATIVE_ROUTES,
            ResultType::GUIDED_NAVIGATION,
    ])
    ->forVehicle(
         new Vehicle(
            engineType: EngineType::COMBUSTION,
            fuelType: FuelType::DIESEL,
            numberOfAxles: 2,
            totalPermittedWeight: 75000,
         )
    )
    ->withCostOptions(
        new MonetaryCostOptions(
             costPerKilometer: 1.2
        )
    )
    ->withOptions(
        new Options(
            startTime: DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2025-01-01 09:00:00'),
            trafficMode: TrafficMode::AVERAGE,
            currency: new Currency('EUR'),
        )
    )
    ->calculate([
        "45.5422993,11.5220921",
        "53.5418064,9.9991367"
])
```

### 2. `recalculate`

[](#2-recalculate)

Uses a previously returned Route Id to recalculate parts of the route results

```
use Money\Currency;
use PTV\Data\Enums\EngineType;
use PTV\Data\Enums\FuelType;
use PTV\PTV;
use PTV\Routing\DTO\MonetaryCostOptions;
use PTV\Routing\DTO\Options;
use PTV\Routing\DTO\Vehicle;
use PTV\Routing\Enums\ResultType;
use PTV\Routing\Enums\TrafficMode;

$ptv = new PTV('[YOUR-API-KEY]');
$route = $ptv
    ->routing()
    ->route()
    ->return([
        ResultType::MONETARY_COSTS,
    ])
    ->withCostOptions(
        new MonetaryCostOptions(
             costPerKilometer: 1.2
        )
    )
    ->withOptions(
        new Options(
            startTime: DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2025-01-01 09:00:00'),
            trafficMode: TrafficMode::AVERAGE,
            currency: new Currency('EUR'),
        )
    )
    ->recalculate('[your-route-id]');
```

### Get Route

[](#get-route)

Get previously calculated route details, or even an alternative route detail.

```
use Money\Currency;
use PTV\Data\Enums\EngineType;
use PTV\Data\Enums\FuelType;
use PTV\PTV;
use PTV\Routing\DTO\MonetaryCostOptions;
use PTV\Routing\DTO\Options;
use PTV\Routing\DTO\Vehicle;
use PTV\Routing\Enums\ResultType;
use PTV\Routing\Enums\TrafficMode;

$ptv = new PTV('[YOUR-API-KEY]');
$route = $ptv
    ->routing()
    ->route()
    ->get('[your-route-id]');
```

### The route object

[](#the-route-object)

The `Route` object is a fully typed DTO to ease reading the results of the APIs

```
use PTV\Routing\DTO\Route;
/** @var Route  $route **/

$route->alternativeRoutes;
$route->monetaryCosts->distanceCost;
$route->toll->costs;

// ...
```

Testing
-------

[](#testing)

To test you can just run

`composer test`

It will use fixture json to test the SDK.

If you want you can also set a `.env` file with a dedicated PTV key and do some real testing with the API.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance50

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~184 days

Total

3

Last Release

356d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2fe88932c3280467c9a30f79205c0f2c85aecd28dae3a9e8b035d773ef6218ef?d=identicon)[Skullbock](/maintainers/Skullbock)

---

Top Contributors

[![Skullbock](https://avatars.githubusercontent.com/u/1104083?v=4)](https://github.com/Skullbock "Skullbock (15 commits)")[![daveewbl](https://avatars.githubusercontent.com/u/17199874?v=4)](https://github.com/daveewbl "daveewbl (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/weble-ptv-php/health.svg)

```
[![Health](https://phpackages.com/badges/weble-ptv-php/health.svg)](https://phpackages.com/packages/weble-ptv-php)
```

###  Alternatives

[skagarwal/google-places-api

Google Places Api

1913.0M8](/packages/skagarwal-google-places-api)[saloonphp/laravel-plugin

The official Laravel plugin for Saloon

805.7M125](/packages/saloonphp-laravel-plugin)[saloonphp/rate-limit-plugin

Handle rate limits beautifully in your Saloon API integrations or SDKs

201.3M44](/packages/saloonphp-rate-limit-plugin)[myoutdeskllc/salesforce-php

salesforce library for php8+

1560.8k](/packages/myoutdeskllc-salesforce-php)[codebar-ag/laravel-docuware

DocuWare integration with Laravel

1221.1k](/packages/codebar-ag-laravel-docuware)[sandorian/moneybird-api-php

Moneybird API client for PHP

127.3k](/packages/sandorian-moneybird-api-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
