$submittedData The submitted participant form data * @param int $participantIndex The index of the participant being processed * * @return bool True if the handler should process this field, false otherwise */ public function shouldProcess(array $submittedData, int $participantIndex): bool { return isset($submittedData[$this->getFieldName()]); } /** * Safely retrieves a participant object from the booking DTO. * * This helper method provides safe access to participant data by checking * if the participant exists at the given index. Returns null if the * participant doesn't exist, preventing array access errors. * * @param BookingCreateDto $bookingDto The booking DTO containing participants * @param int $participantIndex The index of the participant to retrieve * * @return object|null The participant object, or null if not found */ protected function getParticipant(BookingCreateDto $bookingDto, int $participantIndex): ?object { return $bookingDto->participants[$participantIndex] ?? null; } /** * Safely extracts a field value from submitted participant data. * * This helper method provides safe access to form field values using * the null coalescing operator. Useful for extracting field values * without worrying about undefined array keys. * * @param array $submittedData The submitted participant form data * @param string $fieldName The name of the field to retrieve * @param mixed $default The default value to return if field is not set * * @return mixed The field value, or the default value if not found */ protected function getFieldValue(array $submittedData, string $fieldName, mixed $default = null): mixed { return $submittedData[$fieldName] ?? $default; } /** * Normalizes empty string values to null. * * Form inputs often submit empty strings for unselected/empty fields. * This helper converts those empty strings to null values, which is * typically more appropriate for database storage and business logic. * * @param mixed $value The value to normalize * * @return mixed The normalized value (null if empty, original value otherwise) */ protected function normalizeEmptyValue(mixed $value): mixed { return empty($value) ? null : $value; } /** * Converts and normalizes string values to integers. * * Form inputs submit all values as strings. This helper safely converts * string values to integers while handling empty strings and non-numeric * values gracefully by returning null. * * @param mixed $value The value to convert to integer * * @return int|null The integer value, or null if empty/non-numeric */ protected function normalizeIntValue(mixed $value): ?int { if (empty($value)) { return null; } return is_numeric($value) ? (int) $value : null; } /** * Returns field state modifications that should be applied after processing. * * Default implementation returns no state modifications. Override this method * in concrete handlers that need to modify field states based on their * processing results. * * @param array $submittedData The submitted participant form data * @param BookingCreateDto $bookingDto The booking DTO (potentially modified by processing) * @param int $participantIndex The participant index being processed * * @return array> Empty array (no state modifications by default) */ public function getFieldStateModifications(array $submittedData, BookingCreateDto $bookingDto, int $participantIndex): array { return []; } /** * Returns field names whose state is affected by this handler's processing. * * Default implementation returns an empty array, meaning this handler doesn't * affect the state of any fields. Override this method in concrete handlers * that modify field states. * * @return string[] Empty array (no affected fields by default) */ public function getAffectedFieldNames(): array { return []; } }