feat: improved error handling of xml parsers and loaders
This commit is contained in:
@@ -55,21 +55,20 @@ class BookingService
|
||||
|
||||
public function getOrCreateBookingCreateDto(Request $request): BookingCreateDto
|
||||
{
|
||||
$bookingCreateKey = self::BOOKING_CREATE_KEY;
|
||||
$bookingUuid = $request->query->get('uid');
|
||||
$bookingCreateDto = $request->getSession()->get($bookingCreateKey);
|
||||
$bookingCreateDto = $request->getSession()->get(self::BOOKING_CREATE_KEY);
|
||||
|
||||
// No UID parameter - return existing DTO from session if available
|
||||
if (null === $bookingUuid && null !== $bookingCreateDto) {
|
||||
// Return existing DTO from session if available
|
||||
if (null !== $bookingCreateDto) {
|
||||
return $bookingCreateDto;
|
||||
}
|
||||
|
||||
// Create a new DTO - we need date_id and hotel_id for this
|
||||
// Legacy support: Create a new DTO if date_id and hotel_id are provided
|
||||
// This maintains backward compatibility for existing URLs with UID parameters
|
||||
$dateId = $request->query->getInt('date_id');
|
||||
$hotelId = $request->query->getInt('hotel_id');
|
||||
|
||||
if (0 === $dateId || 0 === $hotelId) {
|
||||
throw new NotFoundHttpException('Missing date_id or hotel_id parameters');
|
||||
throw new NotFoundHttpException('No booking session found. Please start a new booking.');
|
||||
}
|
||||
|
||||
$travelData = $this->travelDataService->getTravelData($dateId, $hotelId);
|
||||
@@ -102,6 +101,55 @@ class BookingService
|
||||
$request->getSession()->set(self::BOOKING_CREATE_KEY, $bookingCreateDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all booking-related session data.
|
||||
*
|
||||
* This method removes all booking session data including the main DTO
|
||||
* and any cached snapshots to ensure a completely fresh start.
|
||||
*/
|
||||
public function clearBookingSession(Request $request): void
|
||||
{
|
||||
$session = $request->getSession();
|
||||
$session->remove(self::BOOKING_CREATE_KEY);
|
||||
$session->remove(self::BOOKING_CREATE_BASELINE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fresh booking session with the provided travel parameters.
|
||||
*
|
||||
* This method initializes a new BookingCreateDto with empty room selections
|
||||
* and saves it to the session. It's designed to be called from the clean
|
||||
* booking entry point without requiring UID parameters.
|
||||
*/
|
||||
public function startFreshBooking(Request $request, int $dateId, int $hotelId): BookingCreateDto
|
||||
{
|
||||
$travelData = $this->travelDataService->getTravelData($dateId, $hotelId);
|
||||
if (null === $travelData) {
|
||||
throw new NotFoundHttpException(sprintf('Travel data not found for date ID %d and hotel ID %d', $dateId, $hotelId));
|
||||
}
|
||||
|
||||
$availableRooms = $travelData->getAvailableRooms();
|
||||
|
||||
// Prevent booking flow entry when no rooms are available
|
||||
if (empty($availableRooms)) {
|
||||
throw new NoRoomsAvailableException($dateId, $hotelId);
|
||||
}
|
||||
|
||||
// Create room selections with zero quantities (user will set these in step 1)
|
||||
$roomSelections = array_map(
|
||||
fn (Room $room) => $this->createRoomSelection($room, []),
|
||||
$availableRooms
|
||||
);
|
||||
|
||||
$bookingCreateDto = new BookingCreateDto($travelData, $hotelId);
|
||||
$bookingCreateDto->roomSelections = $roomSelections;
|
||||
$bookingCreateDto->currentStep = 1;
|
||||
|
||||
$this->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
return $bookingCreateDto;
|
||||
}
|
||||
|
||||
private function createRoomSelection(Room $room, array $roomsIdsAndQuantities): RoomSelectionDto
|
||||
{
|
||||
$selection = new RoomSelectionDto();
|
||||
@@ -229,17 +277,6 @@ class BookingService
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the room selection has changed between two DTOs.
|
||||
*/
|
||||
public function shouldResetAssignments(BookingCreateDto $oldDto, BookingCreateDto $newDto): bool
|
||||
{
|
||||
$old = array_map(fn ($roomSelectionDto) => [$roomSelectionDto->roomId, $roomSelectionDto->quantity], $oldDto->roomSelections);
|
||||
$new = array_map(fn ($roomSelectionDto) => [$roomSelectionDto->roomId, $roomSelectionDto->quantity], $newDto->roomSelections);
|
||||
|
||||
return $old !== $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all participant room assignments in the DTO.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user