PHP code example of shahmy / laravel-ddd-toolkit

1. Go to this page and download the library: Download shahmy/laravel-ddd-toolkit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shahmy / laravel-ddd-toolkit example snippets


return [
    // Root directory for all DDD domains (relative to base_path())
    'src_directory' => env('DDD_SRC_DIR', 'src'),

    // Base PSR-4 namespace mapped to src_directory
    'base_namespace' => 'Src',

    // Name of the cross-domain shared bounded context
    'shared_domain' => 'Shared',

    // Automatically add PSR-4 entry to composer.json after domain creation
    'auto_register_namespaces' => true,

    // Automatically run composer dump-autoload after namespace registration
    'auto_dump_autoload' => true,

    // PHP testing framework for generated test stubs
    'test_framework' => env('DDD_TEST_FRAMEWORK', 'pest'), // 'pest' or 'phpunit'

    // Layer structure created for every new domain
    'layers' => [
        'Application'                            => ['Actions', 'Commands', 'DTOs', 'Events', 'Exceptions', 'Interfaces', 'Jobs', 'Listeners', 'Queries', 'Services', 'UseCases'],
        'Domain'                                 => ['Entities', 'Enums', 'Events', 'Exceptions', 'Repositories', 'Services', 'Specifications', 'Traits', 'ValueObjects'],
        'Infrastructure'                         => ['Cache', 'Factories', 'Mappers', 'Providers', 'Services'],
        'Infrastructure/Persistence'             => ['Eloquent', 'Migrations', 'Repositories', 'Seeders'],
        'Presentation/API'                       => ['Controllers', 'Middleware', 'Requests', 'Resources', 'Routes'],
        'Presentation/CLI'                       => [],
        'Presentation/WEB'                       => [],
        'Tests'                                  => ['Feature', 'Unit'],
    ],
];
bash
php artisan vendor:publish --tag=ddd-config
bash
php artisan ddd:init
bash
php artisan ddd:domain Merchant
php artisan ddd:domain Merchant --dry-run    # preview without creating files
php artisan ddd:domain Merchant --force      # overwrite if already exists
bash
php artisan ddd:<type> <Domain> <ClassName> [--force] [--dry-run]
bash
php artisan ddd:entity Merchant Product
php artisan ddd:repository Merchant ProductRepository
php artisan ddd:service Merchant PricingService
php artisan ddd:dto Merchant CreateProductDTO
php artisan ddd:action Merchant CreateProductAction
php artisan ddd:usecase Merchant CreateProductUseCase
php artisan ddd:event Merchant ProductCreated
php artisan ddd:value-object Merchant Money
php artisan ddd:enum Merchant ProductStatus
php artisan ddd:policy Merchant OrderPolicy
php artisan ddd:resource Merchant ProductResource
php artisan ddd:request Merchant StoreProductRequest
php artisan ddd:test Merchant ProductTest --unit
bash
php artisan vendor:publish --tag=ddd-stubs

src/
├── Commands/           # 15 Artisan commands (DddDomainCommand, DddEntityCommand, …)
├── Generators/
│   ├── DomainGenerator.php   # Atomic directory tree scaffolding
│   └── ClassGenerator.php    # Stub-based class file generation
├── Support/
│   ├── AtomicFilesystem.php  # Transactional filesystem (begin/stage/commit/rollback)
│   ├── ComposerUpdater.php   # PSR-4 namespace registration + dump-autoload
│   ├── StubEngine.php        # Stub resolution and placeholder replacement
│   └── NamespaceGenerator.php
└── DDDServiceProvider.php