Download the PHP package lunarstorm/laravel-ddd without Composer
On this page you can find all versions of the php package lunarstorm/laravel-ddd. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lunarstorm/laravel-ddd
More information about lunarstorm/laravel-ddd
Files in lunarstorm/laravel-ddd
Package laravel-ddd
Short Description A Laravel toolkit for Domain Driven Design patterns
License MIT
Homepage https://github.com/lunarstorm/laravel-ddd
Informations about the package laravel-ddd
Domain Driven Design toolkit for Laravel
Laravel-DDD is a toolkit to support domain driven design (DDD) in Laravel applications. One of the pain points when adopting DDD is the inability to use Laravel's native make
commands to generate domain objects since they are typically stored outside the App\*
namespace. This package aims to fill the gaps by providing equivalent commands such as ddd:model
, ddd:dto
, ddd:view-model
and many more.
Installation
You can install the package via composer:
You may initialize the package using the ddd:install
artisan command. This will publish the config file, register the domain path in your project's composer.json psr-4 autoload configuration on your behalf, and allow you to publish generator stubs for customization if needed.
Deployment
In production, run ddd:cache
during the deployment process to optimize autoloading.
Version Compatibility
Laravel | LaravelDDD | |
---|---|---|
9.x - 10.24.x | 0.x | 0.x README |
10.25.x | 1.x | |
11.x | 1.x |
See UPGRADING for more details about upgrading from 0.x.
Usage
Syntax
All domain generator commands use the following syntax:
Available Commands
Generators
The following generators are currently available, shown using short-hand syntax:
Generated objects will be placed in the appropriate domain namespace as specified by ddd.namespaces.*
in the config file.
Other Commands
Advanced Usage
Nested Objects
For any ddd:*
generator command, nested objects can be specified with forward slashes.
This is essential for objects without a fixed namespace such as class
, interface
, trait
,
each of which have a blank namespace by default. In other words, these objects originate
from the root of the domain.
Overriding Configured Namespaces at Runtime
If for some reason you need to generate a domain object under a namespace different to what is configured in ddd.namespaces.*
,
you may do so using an absolute name starting with /
. This will generate the object from the root of the domain.
Subdomains (nested domains)
Subdomains can be specified with dot notation wherever a domain option is accepted.
Customization
This package ships with opinionated (but sensible) configuration defaults. You may customize by publishing the config file and generator stubs as needed:
Note that the extended commands do not publish ddd-specific stubs, and inherit the respective application-level stubs published by Laravel.
Domain Autoloading and Discovery
Autoloading behaviour can be configured with the ddd.autoload
configuration option. By default, domain providers, commands, policies, and factories are auto-discovered and registered.
Service Providers
When ddd.autoload.providers
is enabled, any class within the domain layer extending Illuminate\Support\ServiceProvider
will be auto-registered as a service provider.
Console Commands
When ddd.autoload.commands
is enabled, any class within the domain layer extending Illuminate\Console\Command
will be auto-registered as a command when running in console.
Policies
When ddd.autoload.policies
is enabled, the package will register a custom policy discovery callback to resolve policy names for domain models, and fallback to Laravel's default for all other cases. If your application implements its own policy discovery using Gate::guessPolicyNamesUsing()
, you should set ddd.autoload.policies
to false
to ensure it is not overridden.
Factories
When ddd.autoload.factories
is enabled, the package will register a custom factory discovery callback to resolve factory names for domain models, and fallback to Laravel's default for all other cases. Note that this does not affect domain models using the Lunarstorm\LaravelDDD\Factories\HasDomainFactory
trait. Where this is useful is with regular models in the domain layer that use the standard Illuminate\Database\Eloquent\Factories\HasFactory
trait.
If your application implements its own factory discovery using Factory::guessFactoryNamesUsing()
, you should set ddd.autoload.factories
to false
to ensure it is not overridden.
Ignoring Paths During Autoloading
To specify folders or paths that should be skipped during autoloading discovery, add them to the ddd.autoload_ignore
configuration option. By default, the Tests
and Migrations
folders are ignored.
Paths specified here are relative to the root of each domain. e.g., src/Domain/Invoicing/{path-to-ignore}
. If more advanced filtering is needed, a callback can be registered using DDD::filterAutoloadPathsUsing(callback $filter)
in your AppServiceProvider's boot method:
The filter callback is based on Symfony's Finder Component.
Disabling Autoloading
You may disable autoloading by setting the respective autoload options to false
in the configuration file as needed, or by commenting out the autoload configuration entirely.
Autoloading in Production
In production, you should cache the autoload manifests using the ddd:cache
command as part of your application's deployment process. This will speed up the auto-discovery and registration of domain providers and commands. The ddd:clear
command may be used to clear the cache if needed.
Configuration File
This is the content of the published config file (ddd.php
):
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Jasper Tey
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-ddd with dependencies
illuminate/contracts Version ^10.25|^11.0
laravel/pint Version ^1.18
laravel/prompts Version ^0.1.16|^0.2|^0.3.1
lorisleiva/lody Version ^0.5.0
spatie/laravel-package-tools Version ^1.13.0
symfony/var-exporter Version ^6|^7.1