-
-
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.
Merge pull request #17 from gacela-project/feature/create-command-arg…
…uments-parser Decouple the "maker templates" from the domain
- Loading branch information
Showing
17 changed files
with
192 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
/.idea/ | ||
/.vscode/ | ||
/vendor/ | ||
/TestModule/ | ||
.phpunit.* | ||
.php_cs.cache | ||
.php_cs.cache |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gacela\CodeGenerator; | ||
|
||
use Gacela\Framework\AbstractConfig; | ||
|
||
final class CodeGeneratorConfig extends AbstractConfig | ||
{ | ||
public function getFacadeMakerTemplate(): string | ||
{ | ||
return $this->getCommandTemplateContent('facade-maker.txt'); | ||
} | ||
|
||
public function getFactoryMakerTemplate(): string | ||
{ | ||
return $this->getCommandTemplateContent('factory-maker.txt'); | ||
} | ||
|
||
public function getConfigMakerTemplate(): string | ||
{ | ||
return $this->getCommandTemplateContent('config-maker.txt'); | ||
} | ||
|
||
public function getDependencyProviderMakerTemplate(): string | ||
{ | ||
return $this->getCommandTemplateContent('dependency-provider-maker.txt'); | ||
} | ||
|
||
private function getCommandTemplateContent(string $filename): string | ||
{ | ||
return file_get_contents(__DIR__ . '/Infrastructure/Template/Command/' . $filename); | ||
} | ||
} |
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
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gacela\CodeGenerator\Domain\Io; | ||
|
||
use Gacela\CodeGenerator\Domain\ReadModel\CommandArguments; | ||
use InvalidArgumentException; | ||
|
||
final class CommandArgumentsParser | ||
{ | ||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function parse(array $arguments): CommandArguments | ||
{ | ||
[$rootNamespace, $targetDirectory] = array_pad($arguments, 2, null); | ||
|
||
if ($rootNamespace === null) { | ||
throw new InvalidArgumentException('Expected 1st argument to be root-namespace of the project'); | ||
} | ||
|
||
if ($targetDirectory === null) { | ||
throw new InvalidArgumentException('Expected 2nd argument to be target-directory inside the project'); | ||
} | ||
|
||
return new CommandArguments($rootNamespace, $targetDirectory); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gacela\CodeGenerator\Domain\ReadModel; | ||
|
||
final class CommandArguments | ||
{ | ||
private string $rootNamespace; | ||
private string $targetDirectory; | ||
|
||
public function __construct(string $rootNamespace, string $targetDirectory) | ||
{ | ||
$this->rootNamespace = $rootNamespace; | ||
$this->targetDirectory = $targetDirectory; | ||
} | ||
|
||
public function rootNamespace(): string | ||
{ | ||
return $this->rootNamespace; | ||
} | ||
|
||
public function targetDirectory(): string | ||
{ | ||
return $this->targetDirectory; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/CodeGenerator/Infrastructure/Template/Command/config-maker.txt
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace $NAMESPACE$; | ||
|
||
use Gacela\Framework\AbstractConfig; | ||
|
||
final class $CLASS_NAME$ extends AbstractConfig | ||
{ | ||
} |
Oops, something went wrong.