| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
/** |
| 4 |
* If you want to add improvements, please create a fork in our GitHub: |
| 5 |
* https://github.com/myparcelnl |
| 6 |
* |
| 7 |
* @author Richard Perdaan <[email protected]> |
| 8 |
* @copyright 2010-2019 MyParcel |
| 9 |
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US CC BY-NC-ND 3.0 NL |
| 10 |
* @link https://github.com/myparcelnl/sdk |
| 11 |
* @since File available since Release v3.0.0 |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace MyParcelNL\Sdk\src\Factory; |
| 15 |
|
| 16 |
use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; |
| 17 |
use MyParcelNL\Sdk\src\Model\Consignment\PostNLConsignment; |
| 18 |
use MyParcelNL\Sdk\src\Model\Consignment\BpostConsignment; |
| 19 |
use MyParcelNL\Sdk\src\Model\Consignment\DPDConsignment; |
| 20 |
|
| 21 |
class ConsignmentFactory |
| 22 |
{ |
| 23 |
public static function createByCarrierId(int $carrierId): AbstractConsignment |
| 24 |
{ |
| 25 |
switch ($carrierId) { |
| 26 |
case PostNLConsignment::CARRIER_ID: |
| 27 |
return new PostNLConsignment(); |
| 28 |
case BpostConsignment::CARRIER_ID: |
| 29 |
return new BpostConsignment(); |
| 30 |
case DPDConsignment::CARRIER_ID: |
| 31 |
return new DPDConsignment(); |
| 32 |
} |
| 33 |
|
| 34 |
throw new \BadMethodCallException("Carrier id $carrierId not found"); |
| 35 |
} |
| 36 |
|
| 37 |
public static function createByCarrierName(string $carrierName): AbstractConsignment |
| 38 |
{ |
| 39 |
switch ($carrierName) { |
| 40 |
case PostNLConsignment::CARRIER_NAME: |
| 41 |
return new PostNLConsignment(); |
| 42 |
case BpostConsignment::CARRIER_NAME: |
| 43 |
return new BpostConsignment(); |
| 44 |
case DPDConsignment::CARRIER_NAME: |
| 45 |
return new DPDConsignment(); |
| 46 |
} |
| 47 |
|
| 48 |
throw new \BadMethodCallException("Carrier name $carrierName not found"); |
| 49 |
} |
| 50 |
} |
| 51 |
|