Framework Integration Overview
Overview of framework integrations for Laravel, Symfony, Doctrine, and Plain PHP.
Introduction
Section titled “Introduction”Data Helpers works with any PHP 8.2+ project and provides optional framework integrations:
- Laravel 9+ - Automatic service provider, controller injection, Eloquent integration
- Symfony 6+ - Bundle registration, value resolvers, Doctrine integration
- Doctrine 2+ - Entity mapping, collection support
- Plain PHP - Works out of the box with arrays, objects, JSON
Zero Configuration
Section titled “Zero Configuration”All framework integrations are automatically detected at runtime:
// Laravel Detectionif (class_exists(\Illuminate\Support\Collection::class)) { // Enable Laravel Collection support}
// Symfony Detectionif (class_exists(\Symfony\Component\HttpFoundation\Request::class)) { // Enable Symfony Request support}Installation
Section titled “Installation”composer require event4u/data-helpersThat’s it! Data Helpers automatically detects your framework.
Framework Support
Section titled “Framework Support”Laravel 9+
Section titled “Laravel 9+”Features:
- ✅ Service Provider auto-registration
- ✅ Controller dependency injection
- ✅ Eloquent Model integration
- ✅ Artisan commands (make:dto, dto:typescript)
- ✅ Laravel-specific attributes (WhenAuth, WhenCan, WhenRole)
Symfony 6+
Section titled “Symfony 6+”Features:
- ✅ Bundle auto-registration (with Flex)
- ✅ Value Resolver for controllers
- ✅ Doctrine Entity integration
- ✅ Console commands (make:dto, dto:typescript)
- ✅ Symfony-specific attributes (WhenGranted, WhenSymfonyRole)
Doctrine 2+
Section titled “Doctrine 2+”Features:
- ✅ Entity mapping (fromEntity, toEntity)
- ✅ Collection support
- ✅ Lazy loading
Plain PHP
Section titled “Plain PHP”Features:
- ✅ Arrays, Objects, JSON, XML
- ✅ No dependencies required
Quick Start
Section titled “Quick Start”Laravel
Section titled “Laravel”class UserDTO extends SimpleDTO{ public function __construct( #[Required, Email] public readonly string $email, ) {}}
// In controllerpublic function store(UserDTO $dto) { // Automatic validation & injection}Symfony
Section titled “Symfony”#[Route('/users', methods: ['POST'])]public function create(UserDTO $dto): JsonResponse { // Automatic validation & injection}Plain PHP
Section titled “Plain PHP”$dto = UserDTO::fromArray($_POST);$dto->validate();Next Steps
Section titled “Next Steps”- Laravel Integration - Detailed Laravel guide
- Symfony Integration - Detailed Symfony guide
- Doctrine Integration - Doctrine entity mapping
- Plain PHP Usage - Standalone usage