-
-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
Configure Laravel Arc to match your project structure and preferences. This guide covers all available configuration options.
Laravel Arc comes with sensible defaults that work out of the box. The configuration file is located at src/Config/dto.php in the package.
To customize Laravel Arc, publish the configuration file:
php artisan vendor:publish --provider="Grazulex\LaravelArc\LaravelArcServiceProvider" --tag="config"This creates config/dto.php in your Laravel application.
<?php
return [
/*
|--------------------------------------------------------------------------
| DTO Definition Files Path
|--------------------------------------------------------------------------
|
| This is the absolute or relative path (from base_path) where your YAML
| definition files for DTOs are located.
|
*/
'definitions_path' => base_path('database/dto_definitions'),
/*
|--------------------------------------------------------------------------
| DTO Output Path
|--------------------------------------------------------------------------
|
| The directory where the generated DTO PHP classes will be written.
| This should typically point to app/DTO or a custom directory.
|
*/
'output_path' => base_path('app/DTO'),
];// config/dto.php
return [
'definitions_path' => resource_path('arc'), // resources/arc/
'output_path' => app_path('DTOs'), // app/DTOs/
];// config/dto.php
return [
'definitions_path' => base_path('src/Definitions'), // src/Definitions/
'output_path' => base_path('src/DTOs'), // src/DTOs/
];// config/dto.php
return [
'definitions_path' => base_path('modules/definitions'), // modules/definitions/
'output_path' => base_path('modules/DTOs'), // modules/DTOs/
];With default configuration:
your-laravel-app/
βββ database/
β βββ dto_definitions/ # YAML definitions
β βββ user.yaml
β βββ product.yaml
β βββ order.yaml
βββ app/
β βββ DTO/ # Generated DTOs
β βββ UserDTO.php
β βββ ProductDTO.php
β βββ OrderDTO.php
With customized configuration:
your-laravel-app/
βββ resources/
β βββ arc/ # YAML definitions
β βββ users/
β β βββ user.yaml
β β βββ profile.yaml
β βββ catalog/
β β βββ product.yaml
β β βββ category.yaml
β βββ orders/
β βββ order.yaml
β βββ order-item.yaml
βββ app/
β βββ DTOs/ # Generated DTOs
β βββ Users/
β β βββ UserDto.php
β β βββ ProfileDto.php
β βββ Catalog/
β β βββ ProductDto.php
β β βββ CategoryDto.php
β βββ Orders/
β βββ OrderDto.php
β βββ OrderItemDto.php
// config/dto.php
return [
'definitions_path' => env('ARC_DEFINITIONS_PATH', resource_path('arc')),
'output_path' => env('ARC_OUTPUT_PATH', app_path('DTOs')),
// Development-specific options
'debug_mode' => env('APP_DEBUG', false),
'auto_generate' => env('ARC_AUTO_GENERATE', true),
];// .env
ARC_DEFINITIONS_PATH=/var/www/definitions
ARC_OUTPUT_PATH=/var/www/app/DTOs
ARC_AUTO_GENERATE=falseConfigure default namespaces for different directories:
// config/dto.php
return [
'definitions_path' => resource_path('arc'),
'output_path' => app_path('DTOs'),
'namespace_mapping' => [
'users' => 'App\\DTOs\\Users',
'catalog' => 'App\\DTOs\\Catalog',
'orders' => 'App\\DTOs\\Orders',
'default' => 'App\\DTOs',
],
];Configure which files to process:
// config/dto.php
return [
'definitions_path' => resource_path('arc'),
'output_path' => app_path('DTOs'),
'file_extensions' => ['yaml', 'yml'],
'output_extension' => 'php',
];// config/dto.php
return [
'definitions_path' => resource_path('arc'),
'output_path' => app_path('DTOs'),
'generation' => [
'strict_types' => true,
'readonly_properties' => true,
'final_classes' => true,
'add_docblocks' => true,
'format_code' => true,
],
];# docker-compose.yml
services:
app:
volumes:
- ./resources/arc:/var/www/resources/arc
- ./app/DTOs:/var/www/app/DTOs
environment:
- ARC_DEFINITIONS_PATH=/var/www/resources/arc
- ARC_OUTPUT_PATH=/var/www/app/DTOsFor teams sharing DTO definitions:
// config/dto.php
return [
// Shared definitions from version control
'definitions_path' => base_path('shared/dto-definitions'),
// Local output directory
'output_path' => app_path('DTOs'),
// Version control settings
'track_definitions' => true,
'ignore_output' => true, // Add DTOs to .gitignore
];Ensure your configured paths exist:
# Check if definitions path exists
php artisan dto:definition-list
# Test generation to verify output path
php artisan dto:generate --dry-run# Create definitions directory
mkdir -p $(php -r "echo config('dto.definitions_path');")
# Create output directory
mkdir -p $(php -r "echo config('dto.output_path');")// config/dto.php - API-focused structure
return [
'definitions_path' => resource_path('api/definitions'),
'output_path' => app_path('Http/DTOs'),
'namespace_mapping' => [
'requests' => 'App\\Http\\DTOs\\Requests',
'responses' => 'App\\Http\\DTOs\\Responses',
'default' => 'App\\Http\\DTOs',
],
];Directory structure:
resources/
βββ api/
βββ definitions/
βββ requests/
β βββ create-user-request.yaml
β βββ update-user-request.yaml
βββ responses/
βββ user-response.yaml
βββ user-list-response.yaml
// config/dto.php - Service-specific DTOs
return [
'definitions_path' => base_path('services/definitions'),
'output_path' => base_path('services/DTOs'),
'service_mapping' => [
'user-service' => 'Services\\User\\DTOs',
'order-service' => 'Services\\Order\\DTOs',
'catalog-service' => 'Services\\Catalog\\DTOs',
],
];// config/dto.php - Legacy system integration
return [
'definitions_path' => base_path('legacy/dto-specs'),
'output_path' => app_path('Legacy/DTOs'),
'legacy_support' => true,
'backward_compatibility' => true,
];# Fix permissions for definitions directory
chmod -R 755 $(php -r "echo config('dto.definitions_path');")
# Fix permissions for output directory
chmod -R 755 $(php -r "echo config('dto.output_path');")# Check resolved paths
php -r "
echo 'Definitions: ' . config('dto.definitions_path') . PHP_EOL;
echo 'Output: ' . config('dto.output_path') . PHP_EOL;
"# Dump autoloader after changing output path
composer dump-autoload// Temporary debugging in config/dto.php
return [
'definitions_path' => tap(resource_path('arc'), function($path) {
logger("DTO definitions path: {$path}");
}),
'output_path' => tap(app_path('DTOs'), function($path) {
logger("DTO output path: {$path}");
}),
];Now that you understand configuration:
- Nested DTOs - Working with complex data structures
- Artisan Commands - Using commands with your configuration
- Example API Integration - Real-world usage examples
Proper configuration ensures Laravel Arc fits perfectly into your project structure and development workflow. βοΈ
Laravel Arc - Generate Type-Safe DTOs from YAML Definitions
π Home | π Get Started | π Examples | βοΈ Config
From YAML to Type-Safe Code - Made with β€οΈ for the Laravel community
π Home
- π Understanding YAML Structure
- π·οΈ Field Types
- π Field Transformers
- π Behavioral Traits
YAML β DTO β Type-Safe Code
Laravel Arc transforms your YAML definitions into powerful PHP DTOs with automatic validation, field transformers, and behavioral traits.
- π Get Started - Create your first DTO in 5 minutes
- π All Examples - Copy-paste ready examples
- β‘ Commands - CLI reference