Classes, interfaces and traits for dealing with shipment tracking information
$ composer require germania-kg/tracking
The TrackingInfoInterface provides two methods, getTrackingID and getTrackingLink.
The TrackingInfoProviderInterface provides a getTrackingInfo method which returns TrackingInfoInterface or null.
The TrackingInfoProviderTrait introduces a public property $tracking_info and a public method getTrackingInfo which fulfills the TrackingInfoProviderInterface.
The TrackingInfoAwareInterface extends TrackingInfoProviderInterface and provides a setTrackingInfo method which accepts TrackingInfoInterface.
The TrackingInfoProviderTrait uses TrackingInfoProviderTrait and additionally provides setTrackingInfo a public setTrackingInfo method which fulfills the TrackingInfoAwareInterface.
The TrackingInfo class extends TrackingInfoAbstract which implements TrackingInfoInterface. It additionally provides setter methods setTrackingID and setTrackingLink:
<?php
use Germania\Tracking\TrackingInfo;
$ti = new TrackingInfo;
$ti->setTrackingID( "123456" );
$ti->setTrackingLink( "https://parcels.test.com?id=123456" );
echo $ti->getTrackingID(); // "123456"
echo $ti->getTrackingLink(); // "https://parcels.test.com?id=123456"
TrackingInfo fulfills also TrackingInfoProviderInterface, since its getTrackingInfo method returns itself. The class also implements JsonSerializable:
$ti = new TrackingInfo;
$ti->setTrackingID( "123456" );
$ti->setTrackingLink( "https://parcels.test.com?id=123456" );
// As array:
$array = $ti->jsonSerialize();
echo $array['id']; // "123456"
echo $array['href']; // "https://parcels.test.com?id=123456"
// StdClass:
$encoded = json_encode( $ti );
$decoded = json_decode( $encoded );
echo $decoded->id; // "123456"
echo $decoded->href; // "https://parcels.test.com?id=123456"
$ git clone https://github.com/GermaniaKG/Tracking.git
$ cd Tracking
$ composer install
Either copy phpunit.xml.dist
to phpunit.xml
and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
$ composer test
# or
$ vendor/bin/phpunit