Skip to content

Commit

Permalink
Merge pull request #44 from lunarstorm/42-implement-hasdomainfactory-…
Browse files Browse the repository at this point in the history
…trait

HasDomainFactory trait implementation.
  • Loading branch information
jaspertey authored Mar 23, 2024
2 parents 051e631 + c62d580 commit e171efb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ All notable changes to `laravel-ddd` will be documented in this file.

## [Unversioned]
### Added
- Config keys `ddd.domain_path` and `ddd.domain_namespace` added to specify path to the domain folder and root domain namespace. This allows a custom domain namespace if it differs from the basename of the domain path. e.g., `src/Domains` domain folder, but with `Domain` namespace.
- Add `ddd.domain_path` and `ddd.domain_namespace` to config, to specify the path to the domain layer and root domain namespace more explicitly (replaces the previous `ddd.paths.domains` config).
- Implement `Lunarstorm\LaravelDDD\Factories\HasDomainFactory` trait which can be used on domain models that are unable to extend the base domain model.

### Changed
- Default `base-model.php.stub` now utilizes the `HasDomainFactory` trait.

### Deprecated
- Config `ddd.paths.domains` deprecated in favour of `ddd.domain_path` and `ddd.domain_namespace`.
- Config `ddd.paths.domains` deprecated in favour of `ddd.domain_path` and `ddd.domain_namespace`. Existing config files published prior to this release should remove `ddd.paths.domains` and add `ddd.domain_path` and `ddd.domain_namespace` accordingly.

## [0.9.0] - 2024-03-11
### Changed
Expand Down
15 changes: 15 additions & 0 deletions src/Factories/HasDomainFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Lunarstorm\LaravelDDD\Factories;

use Illuminate\Database\Eloquent\Factories\HasFactory;

trait HasDomainFactory
{
use HasFactory;

protected static function newFactory()
{
return DomainFactory::factoryForModel(get_called_class());
}
}
10 changes: 2 additions & 8 deletions src/Models/DomainModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

namespace Lunarstorm\LaravelDDD\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Lunarstorm\LaravelDDD\Factories\DomainFactory;
use Lunarstorm\LaravelDDD\Factories\HasDomainFactory;

abstract class DomainModel extends Model
{
use HasFactory;
use HasDomainFactory;

protected $guarded = [];

protected static function newFactory()
{
return DomainFactory::factoryForModel(get_called_class());
}
}
4 changes: 2 additions & 2 deletions src/Support/DomainResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class DomainResolver
{
public static function getConfiguredDomainPath(): string
public static function getConfiguredDomainPath(): ?string
{
if (Config::has('ddd.paths.domains')) {
// Deprecated
Expand All @@ -17,7 +17,7 @@ public static function getConfiguredDomainPath(): string
return config('ddd.domain_path');
}

public static function getConfiguredDomainNamespace(): string
public static function getConfiguredDomainNamespace(): ?string
{
if (Config::has('ddd.paths.domains')) {
// Deprecated
Expand Down
10 changes: 2 additions & 8 deletions stubs/base-model.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

namespace {{ namespace }};

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Lunarstorm\LaravelDDD\Factories\DomainFactory;
use Lunarstorm\LaravelDDD\Factories\HasDomainFactory;
use Illuminate\Database\Eloquent\Model;

abstract class {{ class }} extends Model
{
use HasFactory;
use HasDomainFactory;

protected $guarded = [];

protected static function newFactory()
{
return DomainFactory::factoryForModel(get_called_class());
}
}

0 comments on commit e171efb

Please sign in to comment.