germania-kg / tracking
Requires
- php: ^7.4|^8.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpspec/prophecy: ^1.16
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-09-04 11:13:16 UTC
README
处理运输跟踪信息的类、接口和特性
使用 Composer 安装
$ composer require germania-kg/tracking
用法
接口和特性
TrackingInfoInterface
TrackingInfoInterface 提供了两个方法,getTrackingID 和 getTrackingLink。
TrackingInfoProviderInterface
TrackingInfoProviderInterface 提供一个 getTrackingInfo 方法,返回 TrackingInfoInterface 或 null。
TrackingInfoProviderTrait
TrackingInfoProviderTrait 引入了一个公共属性 $tracking_info 和一个公共方法 getTrackingInfo,该方法符合 TrackingInfoProviderInterface。
TrackingInfoAwareInterface
TrackingInfoAwareInterface 扩展了 TrackingInfoProviderInterface 并提供了一个接受 TrackingInfoInterface 的 setTrackingInfo 方法。
TrackingInfoProviderTrait
TrackingInfoProviderTrait 使用 TrackingInfoProviderTrait 并额外提供了一个符合 TrackingInfoAwareInterface 的公共 setTrackingInfo 方法。
类
TrackingInfo 类
TrackingInfo 类扩展了 TrackingInfoAbstract,实现了 TrackingInfoInterface。它还提供了设置方法 setTrackingID 和 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 也符合 TrackingInfoProviderInterface,因为其 getTrackingInfo 方法返回自身。该类还实现了 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
单元测试
可以复制 phpunit.xml.dist
到 phpunit.xml
并根据您的需求进行调整,或者保持不变。运行 PhpUnit 测试或 composer 脚本,如下所示
$ composer test # or $ vendor/bin/phpunit