{"id":28397913,"url":"https://github.com/weble/ptv-php","last_synced_at":"2025-06-28T12:31:43.134Z","repository":{"id":241283942,"uuid":"800944260","full_name":"Weble/ptv-php","owner":"Weble","description":"PHP SDK for PTV API","archived":false,"fork":false,"pushed_at":"2025-05-27T12:31:34.000Z","size":2692,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-08T03:31:37.294Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Weble.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-15T09:50:18.000Z","updated_at":"2025-05-27T12:31:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"43d9b354-6b6a-4dab-b71a-a2e0a0d5da7a","html_url":"https://github.com/Weble/ptv-php","commit_stats":null,"previous_names":["weble/ptv-php"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Weble/ptv-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Weble%2Fptv-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Weble%2Fptv-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Weble%2Fptv-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Weble%2Fptv-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Weble","download_url":"https://codeload.github.com/Weble/ptv-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Weble%2Fptv-php/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262431109,"owners_count":23309975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-01T03:07:04.085Z","updated_at":"2025-06-28T12:31:43.129Z","avatar_url":"https://github.com/Weble.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP SDK for the PTV APIs\n\n[![Latest Version](https://img.shields.io/github/release/weble/ptv-php.svg?style=flat-square)](https://github.com/weble/ptv-php/releases)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![run-tests](https://img.shields.io/github/actions/workflow/status/weble/ptv-php/test.yml?label=tests\u0026style=flat-square)](https://github.com/weble/ptv-php/actions)\n[![Total Downloads](https://img.shields.io/packagist/dt/weble/ptv-php.svg?style=flat-square)](https://packagist.org/packages/weble/ptv-php)\n\nThis is an SDK for the [PTV API](https://developer.myptv.com/en).\n\nIt 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).\n\nUnder the hood it uses [Saloon](https://docs.saloon.dev/) to handle the requests.\n\nIt features only 2 dependencies:\n- `saloonphp/saloon` to handle the requests and the SDK building in general\n- `moneyphp/money` to represent the prices and currencies\n\nEvery parameter and response object is carefully mapped with a dedicated **DTO** class and **Enum**\n\n## Installation\n\n`composer require weble/ptv-php`\n\n## Basic Usage\n\nJust create the client and interact with each of the apis.\n\n```php\nuse PTV\\PTV;\n\n$ptv = new PTV('[YOUR-API-KEY]');\n\n$profiles = $ptv-\u003edata()-\u003evehicleProfiles()-\u003eall();\n$route $ptv-\u003erouting()-\u003eroute()-\u003ecalculate(['lat,lng', 'lat2,lng2']);\n```\n\n### Setting a language\n\n```php\nuse PTV\\PTV;\n\n$ptv = new PTV('[YOUR-API-KEY]', 'it');\n```\n\n## Data Api\n\nOnly 3 endpoints are implemented as of today:\n\n### 1. `vehicleProfiles`\n\n```php\nuse PTV\\PTV;\n\n$ptv = new PTV('[YOUR-API-KEY]');\n$profiles = $ptv-\u003edata()-\u003evehicleProfiles()-\u003eall();\n```\n### 2. `vehicleModels`\n\n```php\nuse PTV\\Data\\Enums\\VehicleType;\nuse PTV\\PTV;\n\n$ptv = new PTV('[YOUR-API-KEY]');\n\n$profiles = $ptv-\u003edata()-\u003evehicleModels()-\u003eall();\n$profiles = $ptv-\u003edata()-\u003evehicleModels()-\u003eall([\n    VehicleType::TRAILER,\n    VehicleType::SEMI_TRAILER,\n]);\n```\n\n### 3. `mapInformation`\n\n```php\nuse PTV\\Data\\Enums\\VehicleType;\nuse PTV\\PTV;\n\n$ptv = new PTV('[YOUR-API-KEY]');\n\n$mapInfo = $ptv-\u003edata()-\u003emapInformation()-\u003eall();\n```\n\n## Routing Api\n\nCurrently only 3 endpoints are supported:\n\n### 1. `calculate`\n\nThis is by far the most complete one and the most likely used.\nYou can calculate a route by chaining parameters within the call.\n\nEach parameter is typed for full IDE autocompletion and ease of use.\n\n```php\nuse Money\\Currency;\nuse PTV\\Data\\Enums\\EngineType;\nuse PTV\\Data\\Enums\\FuelType;\nuse PTV\\PTV;\nuse PTV\\Routing\\DTO\\MonetaryCostOptions;\nuse PTV\\Routing\\DTO\\Options;\nuse PTV\\Routing\\DTO\\Vehicle;\nuse PTV\\Routing\\Enums\\ResultType;\nuse PTV\\Routing\\Enums\\TrafficMode;\n\n$ptv = new PTV('[YOUR-API-KEY]');\n$route = $ptv\n    -\u003erouting()\n    -\u003eroute()\n    -\u003ereturn([\n        ResultType::MONETARY_COSTS,\n            ResultType::POLYLINE,\n            ResultType::LEGS,\n            ResultType::LEGS_POLYLINE,\n            ResultType::ROUTE_ID,\n            ResultType::TOLL_COSTS,\n            ResultType::TOLL_SYSTEMS,\n            ResultType::TOLL_SECTIONS,\n            ResultType::TOLL_EVENTS,\n            ResultType::ALTERNATIVE_ROUTES,\n            ResultType::GUIDED_NAVIGATION,\n    ])\n    -\u003eforVehicle(\n         new Vehicle(\n            engineType: EngineType::COMBUSTION,\n            fuelType: FuelType::DIESEL,\n            numberOfAxles: 2,\n            totalPermittedWeight: 75000,\n         )\n    )\n    -\u003ewithCostOptions(\n        new MonetaryCostOptions(\n             costPerKilometer: 1.2\n        )\n    )\n    -\u003ewithOptions(\n        new Options(\n            startTime: DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2025-01-01 09:00:00'),\n            trafficMode: TrafficMode::AVERAGE,\n            currency: new Currency('EUR'),\n        )\n    )\n    -\u003ecalculate([\n        \"45.5422993,11.5220921\",\n        \"53.5418064,9.9991367\"\n])\n```\n### 2. `recalculate`\n\nUses a previously returned Route Id to recalculate parts of the route results\n\n```php\nuse Money\\Currency;\nuse PTV\\Data\\Enums\\EngineType;\nuse PTV\\Data\\Enums\\FuelType;\nuse PTV\\PTV;\nuse PTV\\Routing\\DTO\\MonetaryCostOptions;\nuse PTV\\Routing\\DTO\\Options;\nuse PTV\\Routing\\DTO\\Vehicle;\nuse PTV\\Routing\\Enums\\ResultType;\nuse PTV\\Routing\\Enums\\TrafficMode;\n\n$ptv = new PTV('[YOUR-API-KEY]');\n$route = $ptv\n    -\u003erouting()\n    -\u003eroute()\n    -\u003ereturn([\n        ResultType::MONETARY_COSTS,\n    ])\n    -\u003ewithCostOptions(\n        new MonetaryCostOptions(\n             costPerKilometer: 1.2\n        )\n    )\n    -\u003ewithOptions(\n        new Options(\n            startTime: DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2025-01-01 09:00:00'),\n            trafficMode: TrafficMode::AVERAGE,\n            currency: new Currency('EUR'),\n        )\n    )\n    -\u003erecalculate('[your-route-id]');\n```\n\n### Get Route\n\nGet previously calculated route details, or even an alternative route detail.\n\n```php\nuse Money\\Currency;\nuse PTV\\Data\\Enums\\EngineType;\nuse PTV\\Data\\Enums\\FuelType;\nuse PTV\\PTV;\nuse PTV\\Routing\\DTO\\MonetaryCostOptions;\nuse PTV\\Routing\\DTO\\Options;\nuse PTV\\Routing\\DTO\\Vehicle;\nuse PTV\\Routing\\Enums\\ResultType;\nuse PTV\\Routing\\Enums\\TrafficMode;\n\n$ptv = new PTV('[YOUR-API-KEY]');\n$route = $ptv\n    -\u003erouting()\n    -\u003eroute()\n    -\u003eget('[your-route-id]');\n```\n\n### The route object\n\nThe `Route` object is a fully typed DTO to ease reading the results of the APIs\n\n```php\nuse PTV\\Routing\\DTO\\Route;\n/** @var Route  $route **/\n\n$route-\u003ealternativeRoutes;\n$route-\u003emonetaryCosts-\u003edistanceCost;\n$route-\u003etoll-\u003ecosts;\n\n// ...\n```\n## Testing\n\nTo test you can just run \n\n`composer test`\n\nIt will use fixture json to test the SDK.\n\nIf you want you can also set a `.env` file with a dedicated PTV key and do some real testing with the API.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweble%2Fptv-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweble%2Fptv-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweble%2Fptv-php/lists"}