-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updates: - normalize domain stub trait across all domain generators - ensure ddd:controller is able to check for base controller existence - refine ddd:model stub replacements * Introduce ddd:publish and ddd:stub commands. * Normalize the resolution of published stubs. * Ensure post-build replacements are skipped in ddd:model when using custom stubs. * Implement ddd:publish and ddd:stub commands. * Refinements to readme and stub documentation. --------- Co-authored-by: JasperTey <[email protected]>
- Loading branch information
Showing
66 changed files
with
1,216 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Lunarstorm\LaravelDDD\Commands\Concerns; | ||
|
||
use Illuminate\Support\Str; | ||
use Lunarstorm\LaravelDDD\Facades\DDD; | ||
|
||
trait HasDomainStubs | ||
{ | ||
protected static $usingPublishedStub = false; | ||
|
||
protected function usingPublishedStub($usingPublishedStub = true) | ||
{ | ||
static::$usingPublishedStub = $usingPublishedStub; | ||
|
||
return $this; | ||
} | ||
|
||
protected function isUsingPublishedStub(): bool | ||
{ | ||
return static::$usingPublishedStub; | ||
} | ||
|
||
protected function getStub() | ||
{ | ||
$stub = parent::getStub(); | ||
|
||
if ($publishedStub = $this->resolvePublishedDddStub($stub)) { | ||
$stub = $publishedStub; | ||
} | ||
|
||
$this->usingPublishedStub(str($stub)->startsWith(app()->basePath('stubs'))); | ||
|
||
return $stub; | ||
} | ||
|
||
protected function resolvePublishedDddStub($path) | ||
{ | ||
$stubFilename = str($path) | ||
->basename() | ||
->ltrim('/\\') | ||
->toString(); | ||
|
||
// Check if there is a user-published stub | ||
if (file_exists($publishedPath = app()->basePath('stubs/ddd/'.$stubFilename))) { | ||
return $publishedPath; | ||
} | ||
|
||
// Also check for legacy stub extensions | ||
if (file_exists($legacyPublishedPath = Str::replaceLast('.stub', '.php.stub', $publishedPath))) { | ||
return $legacyPublishedPath; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected function resolveDddStubPath($path) | ||
{ | ||
$path = str($path) | ||
->basename() | ||
->ltrim('/\\') | ||
->toString(); | ||
|
||
if ($publishedPath = $this->resolvePublishedDddStub($path)) { | ||
return $publishedPath; | ||
} | ||
|
||
return DDD::packagePath('stubs/'.$path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Lunarstorm\LaravelDDD\Commands\Concerns; | ||
|
||
trait InteractsWithStubs | ||
{ | ||
protected function fillPlaceholder($stub, $placeholder, $value) | ||
{ | ||
return str_replace(["{{$placeholder}}", "{{ $placeholder }}"], $value, $stub); | ||
} | ||
|
||
protected function preparePlaceholders(): array | ||
{ | ||
return []; | ||
} | ||
|
||
protected function applyPlaceholders($stub) | ||
{ | ||
$placeholders = $this->preparePlaceholders(); | ||
|
||
foreach ($placeholders as $placeholder => $value) { | ||
$stub = $this->fillPlaceholder($stub, $placeholder, $value ?? ''); | ||
} | ||
|
||
return $stub; | ||
} | ||
|
||
protected function buildClass($name) | ||
{ | ||
return $this->applyPlaceholders(parent::buildClass($name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.