-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/next' into layers
- Loading branch information
Showing
69 changed files
with
1,365 additions
and
231 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
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
Oops, something went wrong.