webit/gls-bundle
Composer 安装命令:
composer require webit/gls-bundle
包简介
GLS ADE and GLS Track & Trace API Symfony 2 integration
关键字:
README 文档
README
WebitGlsBundle
GLS ADE and GLS Track & Trace API Symfony 2 integration
Installation
via Composer
Add the webit/gls-bundle into composer.json
{
"require": {
"php": ">=5.3.2",
"webit/gls-bundle": "dev-master"
},
"autoload": {
"psr-0": {
"Acme": "src/"
}
}
}
Register bundle in Kernel
Add following lines:
// in AppKernel::registerBundles() $bundles = array( // ... new Webit\Bundle\SoapApiBundle\WebitSoapApiBundle(), new Webit\Bundle\GlsBundle\WebitGlsBundle(), // ... );
Configuration
You can define as much accounts as you need (ADE Accounts and Track & Trace as well)
webit_gls: ade_accounts: my-production-account: username: my-ade-username password: my-ade-password test_mode: false my-test-account: username: my-ade-test-username password: my-ade-test-password test_mode: true track_accounts: my-account: username: my-track-and-trace-username password: my-track-and-trace-password test_mode: false
Usage
To use GLS APIs you need AccountManager ('webit_gls.account_manager'), ApiProvider ('webit_gls.api_provider'), and TrackingUrlProvider ('webit_gls.tracking.url_provider'). You can get them directly from Service Container or inject them to your class.
<?php namespace Acme\Bundle\AcmeBundle\Controller; use Webit\Bundle\GlsBundle\Api\ApiProviderInterface; use Webit\Bundle\GlsBundle\Account\AccountManagerInterface; use Webit\GlsTracking\UrlProvider\TrackingUrlProvider; class MyController { /** * @var AccountManagerInterface */ private $accountManager; /** * @var ApiProviderInterface */ private $apiProvider; /** * @var TrackingUrlProvider */ private $trackingUrlProvider; public function __construct( AccountManagerInterface $accountManager, ApiProviderInterface $apiProvider, TrackingUrlProvider $trackingUrlProvider ) { $this->accountManager = $accountManager; $this->apiProvider = $apiProvider; $this->trackingUrlProvider = $trackingUrlProvider; } public function consignmentPrepareAction() { /** @var \Webit\Bundle\GlsBundle\Account\AdeAccount */ $account = $this->accountManager->getAdeAccount('my-test-account'); /** @var \Webit\GlsAde\Api\ConsignmentPrepareApi */ $consignmentPrepareApi = $this->apiProvider->getConsignmentPrepareApi($account); // do your stuff with API } public function checkParcelStatusAction() { /** @var \Webit\Bundle\GlsBundle\Account\TrackAccount */ $account = $this->accountManager->getTrackAccount('my-account'); /** @var \Webit\GlsTracking\Api\TrackingApi */ $trackingApi = $this->apiProvider->getTrackingApi($account); // do your stuff with API } public function getTrackingUrlAction($reference, $country = 'EN') { $url = $trackingUrlProvider->getStandardTrackingUrl($reference, $country); // do your stuff with URL } }
To learn how to use GLS APIs see:
- GLS-ADE: https://github.com/dbojdo/gls-ade
- GLS Track & Trace: https://github.com/dbojdo/gls-tracking
统计信息
- 总下载量: 2.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-03