PHP code example of webit / gls-bundle

1. Go to this page and download the library: Download webit/gls-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webit / gls-bundle example snippets


// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Webit\Bundle\SoapApiBundle\WebitSoapApiBundle(),
    new Webit\Bundle\GlsBundle\WebitGlsBundle(),
    // ...
);


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
    }
}