wip: major refactoring

This commit is contained in:
Björn Fromme
2026-03-16 11:59:09 +01:00
parent d719b17aec
commit 11825191cf
32 changed files with 692 additions and 466 deletions
+89 -9
View File
@@ -4,14 +4,29 @@ This system provides a flexible architecture for implementing conditional field
## Architecture Overview
The system consists of several key components:
The system consists of several key components organized in a clean namespace structure:
1. **FieldConditionInterface** - Defines the contract for condition evaluation
2. **Concrete Conditions** - Implement specific business logic (age ranges, field values, etc.)
3. **CompositeCondition** - Combines conditions with AND/OR/NOT logic
4. **FieldStateProviderInterface** - Manages field state calculation
5. **ParticipantFieldOptionsProvider** - Enhanced to support state conditions
6. **Form Integration** - Applied in BookingCreateParticipantType
### Core Interfaces (`src/Form/Service/Contract/`)
1. **FieldStateProviderInterface** - Defines the contract for field state management
2. **FieldOptionsProviderInterface** - Defines the contract for field option generation
### Abstract Base Classes (`src/Form/Service/Abstract/`)
3. **AbstractFieldStateProvider** - Common field state functionality
4. **AbstractFieldOptionsProvider** - Common field option functionality
### Concrete Implementations (`src/Form/Service/`)
5. **CreateFieldStateProvider** - Field states for booking creation workflow
6. **EditFieldStateProvider** - Field states for booking edit workflow
7. **ParticipantFieldOptionsProvider** - Dynamic field option generation
### Condition System (`src/Form/Service/Condition/`)
8. **FieldConditionInterface** - Defines the contract for condition evaluation
9. **Concrete Conditions** - Implement specific business logic (age ranges, field values, etc.)
10. **CompositeCondition** - Combines conditions with AND/OR/NOT logic
### Form Integration
11. **BookingCreateParticipantType** - Uses CreateFieldStateProvider
12. **BookingEditParticipantType** - Uses EditFieldStateProvider
## Usage Examples
@@ -87,10 +102,12 @@ $this->fieldStateConditions['specialServices'] = [
## Adding New Conditions
To register field state conditions, add them to the `registerFieldStateConditions()` method in `ParticipantFieldOptionsProvider`:
### For Create Workflow
To register field state conditions for the booking creation workflow, add them to the `registerFieldStateConditions()` method in `CreateFieldStateProvider`:
```php
private function registerFieldStateConditions(): void
// src/Form/Service/CreateFieldStateProvider.php
protected function registerFieldStateConditions(): void
{
// Age-based readonly state
$this->fieldStateConditions['assignedRoomId'] = [
@@ -113,6 +130,40 @@ private function registerFieldStateConditions(): void
}
```
### For Edit Workflow
To register field state conditions for the booking edit workflow, add them to the `registerFieldStateConditions()` method in `EditFieldStateProvider`:
```php
// src/Form/Service/EditFieldStateProvider.php
protected function registerFieldStateConditions(): void
{
// Make personal data readonly for applicants or non-mutable fields
$personalDataFields = ['firstName', 'lastName', 'dateOfBirth', 'gender', 'nationality', 'email', 'mobile'];
foreach ($personalDataFields as $field) {
$this->fieldStateConditions[$field] = [
'readonly' => CompositeCondition::or(
new ApplicantCondition(),
new MutabilityCondition()
),
];
}
}
```
### Adding Field Options
To register dynamic field options, add them to the `registerFieldOptionProviders()` method in `ParticipantFieldOptionsProvider`:
```php
// src/Form/Service/ParticipantFieldOptionsProvider.php
protected function registerFieldOptionProviders(): void
{
$this->fieldOptionProviders['newField'] = fn(BookingDtoInterface $bookingDto, int $participantIndex) => [
'label' => 'New Field Label',
'choices' => $this->generateChoicesFor($bookingDto, $participantIndex),
];
}
```
## Performance Considerations
- Conditions use lazy evaluation and short-circuit logic
@@ -136,6 +187,9 @@ The system supports real-time field state updates:
Create new condition classes implementing `FieldConditionInterface`:
```php
// src/Form/Service/Condition/CustomBusinessRuleCondition.php
use App\Form\Service\Contract\FieldConditionInterface;
class CustomBusinessRuleCondition implements FieldConditionInterface
{
public function evaluate(BookingCreateDto $bookingDto, int $participantIndex, array $formData): bool
@@ -156,4 +210,30 @@ class CustomBusinessRuleCondition implements FieldConditionInterface
}
```
### Custom Field Options Providers
To create more complex field option logic, extend `AbstractFieldOptionsProvider`:
```php
// src/Form/Service/CustomFieldOptionsProvider.php
use App\Form\Service\Abstract\AbstractFieldOptionsProvider;
class CustomFieldOptionsProvider extends AbstractFieldOptionsProvider
{
protected function registerFieldOptionProviders(): void
{
$this->fieldOptionProviders['customField'] = fn(BookingDtoInterface $bookingDto, int $participantIndex) => [
'label' => 'Custom Field',
'choices' => $this->generateCustomChoices($bookingDto, $participantIndex),
];
}
private function generateCustomChoices(BookingDtoInterface $bookingDto, int $participantIndex): array
{
// Custom choice generation logic
return [];
}
}
```
This system provides a powerful, maintainable foundation for complex conditional field behavior while maintaining clean separation of concerns and extensibility.