| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class OptionPrefixer |
| 4 |
* |
| 5 |
* @package Packetery |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace Packetery\Module\Carrier; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class OptionPrefixer |
| 14 |
* |
| 15 |
* @package Packetery |
| 16 |
*/ |
| 17 |
class OptionPrefixer { |
| 18 |
|
| 19 |
public const CARRIER_OPTION_PREFIX = 'packetery_carrier_'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Prepares carrier option id. |
| 23 |
* |
| 24 |
* @param string $carrierId Carrier id. |
| 25 |
* |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
public static function getOptionId( string $carrierId ): string { |
| 29 |
return self::CARRIER_OPTION_PREFIX . $carrierId; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Checks if is packetery shipping option id. |
| 34 |
* |
| 35 |
* @param string $optionId Option id. |
| 36 |
* |
| 37 |
* @return bool |
| 38 |
*/ |
| 39 |
public static function isOptionId( string $optionId ): bool { |
| 40 |
return ( strpos( $optionId, self::CARRIER_OPTION_PREFIX ) === 0 ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Removes prefix from packetery shipping option id. |
| 45 |
* |
| 46 |
* @param string $optionId Option id. |
| 47 |
* |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
public static function removePrefix( string $optionId ): string { |
| 51 |
return str_replace( self::CARRIER_OPTION_PREFIX, '', $optionId ); |
| 52 |
} |
| 53 |
} |
| 54 |
|