chore: cleanup
This commit is contained in:
@@ -33,8 +33,6 @@ class AcceptedVouchersDto
|
||||
|
||||
/**
|
||||
* @return array<AcceptedVoucherDto>
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getPromotionalVouchers(): array
|
||||
{
|
||||
@@ -43,8 +41,6 @@ class AcceptedVouchersDto
|
||||
|
||||
/**
|
||||
* @return array<AcceptedVoucherDto>
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getPurchaseVouchers(): array
|
||||
{
|
||||
@@ -53,8 +49,6 @@ class AcceptedVouchersDto
|
||||
|
||||
/**
|
||||
* @return array<AcceptedVoucherDto>
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getGoodwillVouchers(): array
|
||||
{
|
||||
@@ -71,9 +65,6 @@ class AcceptedVouchersDto
|
||||
return count($this->vouchers) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated No known usages
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->vouchers);
|
||||
|
||||
@@ -44,34 +44,4 @@ class BankAccountDto
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IBAN formatted with spaces for display (e.g., DE12 3456 7890 1234 5678 90).
|
||||
*
|
||||
* @deprecated No known usages
|
||||
*/
|
||||
public function getFormattedIban(): ?string
|
||||
{
|
||||
if (null === $this->iban) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cleanIban = $this->getIbanWithoutSpaces();
|
||||
|
||||
return chunk_split($cleanIban, 4, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IBAN without spaces for storage and API submission.
|
||||
*
|
||||
* @deprecated Only used by getFormattedIban() which is also deprecated
|
||||
*/
|
||||
public function getIbanWithoutSpaces(): ?string
|
||||
{
|
||||
if (null === $this->iban) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) preg_replace('/\s+/', '', $this->iban);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,14 +155,6 @@ class BookingDto
|
||||
return $this->participants;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use getParticipant() and check for null instead
|
||||
*/
|
||||
public function hasParticipant(int $index): bool
|
||||
{
|
||||
return isset($this->participants[$index]);
|
||||
}
|
||||
|
||||
public function getParticipant(int $index): ?ParticipantDto
|
||||
{
|
||||
return $this->participants[$index] ?? null;
|
||||
@@ -199,48 +191,6 @@ class BookingDto
|
||||
return ($adults >= 1 && $adults <= 2) && ($children >= 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use ParticipantDto::isCanceled() instead
|
||||
*/
|
||||
public function isCanceled(): bool
|
||||
{
|
||||
return null !== $this->booking && 'S' === $this->booking->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use ParticipantDto::isOption() instead
|
||||
*/
|
||||
public function isOption(): bool
|
||||
{
|
||||
return null !== $this->booking && 'O' === $this->booking->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the label of the single selected room type.
|
||||
*
|
||||
* Returns the room label when exactly one room type is selected (auto-assignment scenario).
|
||||
* Used by templates to display the room assignment when the dropdown is hidden.
|
||||
*
|
||||
* @return string|null The room label or null if not a single room type scenario
|
||||
*
|
||||
* @deprecated No known usages
|
||||
*/
|
||||
public function getSingleRoomLabel(): ?string
|
||||
{
|
||||
$selectedRooms = $this->getSelectedRooms();
|
||||
|
||||
// Only return label when exactly one room type selected
|
||||
if (1 !== count($selectedRooms)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$roomSelection = reset($selectedRooms);
|
||||
$availableRooms = $this->travel->getAvailableRooms();
|
||||
$room = $availableRooms[$roomSelection->roomId] ?? null;
|
||||
|
||||
return $room?->label;
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function validateBankAccount(ExecutionContextInterface $context): void
|
||||
{
|
||||
@@ -285,27 +235,6 @@ class BookingDto
|
||||
return 'A' === $this->bookingStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any participants have entered voucher codes.
|
||||
*
|
||||
* @return bool True if any promotional, purchase, or goodwill vouchers are present
|
||||
*
|
||||
* @deprecated Use AcceptedVouchersDto::hasVouchers() instead
|
||||
*/
|
||||
public function hasVouchers(): bool
|
||||
{
|
||||
foreach ($this->participants as $participant) {
|
||||
if (null !== $participant->promoVoucherCode && '' !== trim($participant->promoVoucherCode)) {
|
||||
return true;
|
||||
}
|
||||
if (null !== $participant->purchaseVoucherCode && '' !== trim($participant->purchaseVoucherCode)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any participants have entered goodwill vouchers.
|
||||
*
|
||||
|
||||
@@ -208,7 +208,7 @@ class ParticipantDto
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated No known usages
|
||||
* Checks if participant status is 'Option' (O).
|
||||
*/
|
||||
public function isOption(): bool
|
||||
{
|
||||
@@ -238,10 +238,6 @@ class ParticipantDto
|
||||
|
||||
/**
|
||||
* Checks if the participant has selected an insurance.
|
||||
*
|
||||
* @return bool True if an insurance is selected
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function hasInsuranceSelected(): bool
|
||||
{
|
||||
@@ -250,10 +246,6 @@ class ParticipantDto
|
||||
|
||||
/**
|
||||
* Gets the insurance label for display purposes.
|
||||
*
|
||||
* @return string|null The insurance label or null if no insurance selected
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getInsuranceLabel(): ?string
|
||||
{
|
||||
@@ -262,10 +254,6 @@ class ParticipantDto
|
||||
|
||||
/**
|
||||
* Gets the insurance price for pricing calculations.
|
||||
*
|
||||
* @return float The insurance price (0.0 if no insurance selected)
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getInsurancePrice(): float
|
||||
{
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Htmx;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class HxRedirectResponse extends Response
|
||||
{
|
||||
/**
|
||||
* Creates an HTMX redirect response.
|
||||
*
|
||||
* Constructs a response that instructs the HTMX client to navigate to the
|
||||
* specified URL. The response includes the HX-Redirect header with the target
|
||||
* URL. Optionally includes HX-Retarget header if a different target element
|
||||
* is specified for the response content.
|
||||
*
|
||||
* @param string $url The URL to redirect to
|
||||
* @param string|null $retarget Optional CSS selector for the target element
|
||||
*/
|
||||
public function __construct(string $url, ?string $retarget = null)
|
||||
{
|
||||
$headers = [
|
||||
'HX-Redirect' => $url,
|
||||
];
|
||||
|
||||
if (null !== $retarget) {
|
||||
$headers['HX-Retarget'] = $retarget;
|
||||
}
|
||||
|
||||
return parent::__construct(null, Response::HTTP_OK, $headers);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Htmx;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class HxRefreshResponse extends Response
|
||||
{
|
||||
/**
|
||||
* Creates an HTMX refresh response.
|
||||
*
|
||||
* Constructs a response that instructs the HTMX client to perform a full page
|
||||
* refresh. The response includes the HX-Refresh header set to 'true', which
|
||||
* signals the HTMX client to reload the entire page. This response typically
|
||||
* contains no content since the page will be completely reloaded.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
return parent::__construct(null, Response::HTTP_OK, ['HX-Refresh' => 'true']);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Htmx;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class HxStopPollingResponse extends Response
|
||||
{
|
||||
/**
|
||||
* Creates an HTMX stop polling response.
|
||||
*
|
||||
* Constructs a response that instructs the HTMX client to stop polling. The response
|
||||
* includes the specified content and uses HTTP status code 286, which is recognized
|
||||
* by HTMX as a signal to terminate polling. This allows the server to control
|
||||
* client-side polling behavior and prevent unnecessary network requests.
|
||||
*
|
||||
* @param string $content The response content to send to the client
|
||||
*/
|
||||
public function __construct(string $content)
|
||||
{
|
||||
return parent::__construct($content, 286);
|
||||
}
|
||||
}
|
||||
+3
-102
@@ -1,115 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Htmx;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Trait providing HTMX-specific functionality for controllers.
|
||||
*
|
||||
* This trait provides methods to handle HTMX requests and responses, including
|
||||
* conditional rendering based on HTMX headers, HTMX-specific redirects, and
|
||||
* multi-block rendering capabilities. It simplifies the integration of HTMX
|
||||
* functionality into Symfony controllers by providing common patterns for
|
||||
* detecting HTMX requests and generating appropriate responses.
|
||||
* Trait providing HTMX Out-of-Band swap functionality for controllers.
|
||||
*/
|
||||
trait HxTrait
|
||||
{
|
||||
/**
|
||||
* Determines if the current request is an HTMX request.
|
||||
*
|
||||
* Checks the HX-Request header to identify if the request was made via HTMX.
|
||||
* This allows controllers to provide different responses for HTMX vs regular
|
||||
* HTTP requests, enabling progressive enhancement patterns.
|
||||
*
|
||||
* @param Request $request The current HTTP request
|
||||
*
|
||||
* @return bool True if the request is an HTMX request, false otherwise
|
||||
*/
|
||||
public function isHxRequest(Request $request): bool
|
||||
{
|
||||
return 'true' === $request->headers->get('HX-Request');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a template with HTMX-aware block selection.
|
||||
*
|
||||
* Renders either a specific template block or the full template based on
|
||||
* whether the request is an HTMX request. When an HTMX request is detected
|
||||
* and a block is specified, only that block is rendered. Otherwise, the
|
||||
* full template is rendered. This enables efficient partial page updates
|
||||
* for HTMX requests while maintaining full page rendering for regular requests.
|
||||
*
|
||||
* @param Request $request The current HTTP request
|
||||
* @param string $template The template name to render
|
||||
* @param array $parameters Template parameters to pass to the view
|
||||
* @param string|null $block The specific block to render for HTMX requests
|
||||
*
|
||||
* @return Response The rendered response
|
||||
*/
|
||||
public function hxRender(
|
||||
Request $request,
|
||||
string $template,
|
||||
array $parameters = [],
|
||||
?string $block = null,
|
||||
): Response {
|
||||
if (null !== $block && true === $this->isHxRequest($request)) {
|
||||
return $this->renderBlock($template, $block, $parameters);
|
||||
}
|
||||
|
||||
return $this->render($template, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an HTMX-aware redirect.
|
||||
*
|
||||
* Returns an HTMX-specific redirect response when the request is an HTMX
|
||||
* request, or a standard redirect response for regular HTTP requests.
|
||||
* HTMX redirects are handled differently by the client, allowing for
|
||||
* smoother user experiences in single-page application contexts.
|
||||
*
|
||||
* @param Request $request The current HTTP request
|
||||
* @param string $url The URL to redirect to
|
||||
*
|
||||
* @return Response Either an HxRedirectResponse or RedirectResponse
|
||||
*/
|
||||
public function hxRedirect(Request $request, string $url): Response
|
||||
{
|
||||
if (true === $this->isHxRequest($request)) {
|
||||
return new HxRedirectResponse($url);
|
||||
}
|
||||
|
||||
return new RedirectResponse($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders multiple template blocks in a single response.
|
||||
*
|
||||
* Combines multiple template blocks into a single response content. This is
|
||||
* useful for HTMX requests that need to update multiple parts of the page
|
||||
* simultaneously. Each block in the array should contain 'template', 'block',
|
||||
* and 'parameters' keys to define what to render.
|
||||
*
|
||||
* @param array $blocks Array of block definitions, each containing:
|
||||
* - 'template': The template name
|
||||
* - 'block': The block name to render
|
||||
* - 'parameters': Template parameters
|
||||
*
|
||||
* @return Response Response containing all rendered blocks concatenated
|
||||
*/
|
||||
public function hxRenderBlocks(array $blocks): Response
|
||||
{
|
||||
$content = '';
|
||||
|
||||
foreach ($blocks as $block) {
|
||||
$content .= $this->renderBlockView($block['template'], $block['block'], $block['parameters']);
|
||||
}
|
||||
|
||||
return new Response($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders multiple Twig blocks for an HTMX Out-of-Band swap response.
|
||||
*
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Htmx;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class HxTriggerResponse extends Response
|
||||
{
|
||||
/**
|
||||
* Creates an HTMX trigger response with custom event triggering capabilities.
|
||||
*
|
||||
* Constructs a response that will trigger a custom JavaScript event on the client
|
||||
* when the HTMX request completes. The trigger can be a simple event name or a
|
||||
* JSON object for more complex event data. Optionally disables content swapping
|
||||
* to prevent the response content from being inserted into the DOM.
|
||||
*
|
||||
* @param string $content The response content (typically empty for trigger-only responses)
|
||||
* @param string $trigger The event name or JSON object to trigger on the client
|
||||
* @param bool $disableSwap Whether to disable HTMX content swapping (default: true)
|
||||
*/
|
||||
public function __construct(string $content, string $trigger, bool $disableSwap = true)
|
||||
{
|
||||
$headers = ['HX-Trigger' => $trigger];
|
||||
|
||||
if (true === $disableSwap) {
|
||||
$headers['HX-Reswap'] = 'none';
|
||||
}
|
||||
|
||||
return parent::__construct($content, Response::HTTP_OK, $headers);
|
||||
}
|
||||
}
|
||||
@@ -340,7 +340,7 @@ class BookingDataProcessorTest extends TestCase
|
||||
$formData = $this->createCompleteFormData();
|
||||
|
||||
$participant = $formData->participants[0];
|
||||
$participant->status = 'C'; // Inactive status
|
||||
$participant->status = 'S'; // Canceled status
|
||||
$participant->firstName = 'Updated';
|
||||
$participant->lastName = 'Participant';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user