wip: transportation services

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent a019c7dae0
commit 81b8237570
18 changed files with 1113 additions and 59 deletions
+1
View File
@@ -15,6 +15,7 @@ final class Constants
public const TOKEN_ADDITIONAL = 'SON';
public const TOKEN_BOARD = 'VPF';
public const TOKEN_RENTALS = ['VER', 'VE2', 'VE3', 'VE4', 'VE5', 'VE6', 'VE7', 'VE8'];
public const TOKEN_PARKING = 'PAR';
public const STATUS_AVAILABLE = 'Frei';
public const STATUS_BLOCKED = 'Buchungsstop';
+85 -1
View File
@@ -5,12 +5,16 @@ declare(strict_types=1);
namespace App\BusProNet\Utility;
/**
* Handles direction mapping between BusProNet's inconsistent direction codes.
* Handles direction and transportation type mapping for BusProNet inconsistencies.
*
* BusProNet uses different direction codes in different contexts:
* - Travel data: 'HIN' (outbound), 'RUECK' (inbound)
* - Booking data: 'H' (outbound), 'R' (inbound)
*
* BusProNet also uses German abbreviations for transportation sub-types:
* - API format: 'PKW' (car), 'BUS' (bus)
* - Internal format: 'CAR' (car), 'BUS' (bus)
*
* This utility provides consistent mapping between formats and enables
* clean English naming for internal application use.
*/
@@ -24,6 +28,14 @@ final class DirectionMapper
public const OUTBOUND_BOOKING = 'H';
public const INBOUND_BOOKING = 'R';
// Transportation service sub-types (API format - German abbreviations)
public const SUBTYPE_BUS_API = 'BUS';
public const SUBTYPE_CAR_API = 'PKW';
// Transportation service sub-types (internal format - English)
public const SUBTYPE_BUS = 'BUS';
public const SUBTYPE_CAR = 'CAR';
/**
* Maps travel direction code to booking direction code.
*
@@ -115,4 +127,76 @@ final class DirectionMapper
{
return self::isOutbound($direction) || self::isInbound($direction);
}
/**
* Maps API transportation sub-type to internal sub-type.
*
* @param string $apiSubType The API transportation sub-type ('BUS' or 'PKW')
*
* @return string The internal transportation sub-type ('BUS' or 'CAR')
*
* @throws \InvalidArgumentException When sub-type is not recognized
*/
public static function apiToInternal(string $apiSubType): string
{
return match ($apiSubType) {
self::SUBTYPE_BUS_API => self::SUBTYPE_BUS,
self::SUBTYPE_CAR_API => self::SUBTYPE_CAR,
default => throw new \InvalidArgumentException("Unknown API sub-type: $apiSubType"),
};
}
/**
* Maps internal transportation sub-type to API sub-type.
*
* @param string $internalSubType The internal transportation sub-type ('BUS' or 'CAR')
*
* @return string The API transportation sub-type ('BUS' or 'PKW')
*
* @throws \InvalidArgumentException When sub-type is not recognized
*/
public static function internalToApi(string $internalSubType): string
{
return match ($internalSubType) {
self::SUBTYPE_BUS => self::SUBTYPE_BUS_API,
self::SUBTYPE_CAR => self::SUBTYPE_CAR_API,
default => throw new \InvalidArgumentException("Unknown internal sub-type: $internalSubType"),
};
}
/**
* Checks if a sub-type is a bus service.
*
* @param string $subType The sub-type to check (API or internal format)
*
* @return bool True if the sub-type is a bus service, false otherwise
*/
public static function isBus(string $subType): bool
{
return in_array($subType, [self::SUBTYPE_BUS, self::SUBTYPE_BUS_API], true);
}
/**
* Checks if a sub-type is a car service.
*
* @param string $subType The sub-type to check (API or internal format)
*
* @return bool True if the sub-type is a car service, false otherwise
*/
public static function isCar(string $subType): bool
{
return in_array($subType, [self::SUBTYPE_CAR, self::SUBTYPE_CAR_API], true);
}
/**
* Validates that a transportation sub-type is recognized.
*
* @param string $subType The sub-type to validate
*
* @return bool True if the sub-type is valid, false otherwise
*/
public static function isValidSubType(string $subType): bool
{
return self::isBus($subType) || self::isCar($subType);
}
}