calcinai / siri
There is no license information available for the latest version (v1.0.1) of this package.
Service Interface for Real Time Information SDK
v1.0.1
2019-07-20 02:50 UTC
Requires
- goetas-webservices/xsd2php-runtime: ^0.2.10
Requires (Dev)
- goetas-webservices/xsd2php: ^0.3.8
This package is auto-updated.
Last update: 2024-12-20 15:12:33 UTC
README
This project is almost entirely generated from the Siri xsd shchemas found here
The generated XML can then be posted using a HTTP client (like Guzzle)
Instalation
With composer:
composer require calcinai/siri
Example
Serialization
use Calcinai\Siri\Objects\Siri; use Calcinai\Siri\Objects\ServiceRequest; use Calcinai\Siri\Objects\VehicleMonitoringRequest; use Calcinai\Siri\Serializer $requestTimestamp = new DateTime(); $siri = new Siri(); $request = new ServiceRequest(); $vmRequest = new VehicleMonitoringRequest(); $siri->setVersion(1.3) ->setServiceRequest($request); $vmRequest->setVersion(1.3) ->setVehicleRef('3706') ->setRequestTimestamp($requestTimestamp); $request->setVehicleMonitoringRequest($vmRequest) ->setRequestTimestamp($requestTimestamp) ->setRequestorRef('Requestor'); $serializer = new Serializer(); $xml = $serializer->serialize($siri); echo $xml;
Will produce XML like
<?xml version="1.0" encoding="UTF-8"?> <Siri xmlns="http://www.siri.org.uk/siri" version="1.3"> <ServiceRequest> <RequestTimestamp>2019-07-18T23:08:07+00:00</RequestTimestamp> <RequestorRef>Requestor</RequestorRef> <VehicleMonitoringRequest version="1.3"> <RequestTimestamp>2019-07-18T23:08:07+00:00</RequestTimestamp> <VehicleRef>3706</VehicleRef> </VehicleMonitoringRequest> </ServiceRequest> </Siri>
Deserialization
The xml above can be deserialized to recreate the object structure
$siri = $serializer->deserialize($xml); print_r($siri); //The root siri object
Acknowlegments
This code is almost completely generated from xsd2php, thanks @goetas-webservices!