Skip to content

Commit 09e13ec

Browse files
committed
WIP
Signed-off-by: alexmerlin <alex.merlin.1985@gmail.com>
1 parent 09fbee3 commit 09e13ec

14 files changed

Lines changed: 206 additions & 148 deletions

bin/dot-maker

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,4 @@ if (file_exists($autoload)) {
1313
exit(1);
1414
}
1515

16-
(new Maker(
17-
sprintf('%s/composer.json', getcwd()),
18-
sprintf('%s/config/autoload/maker.php', getcwd()),
19-
))($argv);
16+
(new Maker(getcwd()))($argv);

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"Dot\\Maker\\": "src/"
1515
}
1616
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"DotTest\\Maker\\": "test/"
20+
}
21+
},
1722
"bin": [
1823
"bin/dot-maker"
1924
],

src/Component/Import.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Dot\Maker\Component;
66

7-
use Dot\Maker\ContextInterface;
7+
use Dot\Maker\Context;
88

99
use function sprintf;
1010

@@ -72,7 +72,7 @@ class Import
7272
public const THROWABLE = 'Throwable';
7373

7474
public function __construct(
75-
private ContextInterface $context,
75+
private Context $context,
7676
) {
7777
}
7878

@@ -86,7 +86,7 @@ public function getAbstractInputFilterFqcn(): string
8686
$format = self::ROOT_APP_INPUTFILTER_ABSTRACTINPUTFILTER;
8787

8888
if ($this->context->hasCore()) {
89-
return sprintf($format, ContextInterface::NAMESPACE_CORE);
89+
return sprintf($format, Context::NAMESPACE_CORE);
9090
}
9191

9292
return sprintf($format, $this->context->getRootNamespace());
@@ -102,7 +102,7 @@ public function getAbstractRepositoryFqcn(): string
102102
$format = self::ROOT_APP_REPOSITORY_ABSTRACTREPOSITORY;
103103

104104
if ($this->context->hasCore()) {
105-
return sprintf($format, ContextInterface::NAMESPACE_CORE);
105+
return sprintf($format, Context::NAMESPACE_CORE);
106106
}
107107

108108
return sprintf($format, $this->context->getRootNamespace());
@@ -113,7 +113,7 @@ public function getAppHelperPaginatorFqcn(): string
113113
$format = self::ROOT_APP_HELPER_PAGINATOR;
114114

115115
if ($this->context->hasCore()) {
116-
return sprintf($format, ContextInterface::NAMESPACE_CORE);
116+
return sprintf($format, Context::NAMESPACE_CORE);
117117
}
118118

119119
return sprintf($format, $this->context->getRootNamespace());
@@ -124,7 +124,7 @@ public function getAppMessageFqcn(): string
124124
$format = self::ROOT_APP_MESSAGE;
125125

126126
if ($this->context->hasCore()) {
127-
return sprintf($format, ContextInterface::NAMESPACE_CORE);
127+
return sprintf($format, Context::NAMESPACE_CORE);
128128
}
129129

130130
return sprintf($format, $this->context->getRootNamespace());
@@ -138,7 +138,7 @@ public function getBadRequestExceptionFqcn(): string
138138
public function getConfigProviderFqcn(bool $core = false): string
139139
{
140140
if ($core && $this->context->hasCore()) {
141-
$rootNamespace = ContextInterface::NAMESPACE_CORE;
141+
$rootNamespace = Context::NAMESPACE_CORE;
142142
} else {
143143
$rootNamespace = $this->context->getRootNamespace();
144144
}

src/Config.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,35 @@
44

55
namespace Dot\Maker;
66

7-
use Dot\Maker\IO\Output;
7+
use RuntimeException;
88

99
use function array_key_exists;
1010
use function file_exists;
1111
use function sprintf;
1212

1313
class Config
1414
{
15+
public const CONFIG_FILE = 'config/autoload/maker.local.php';
16+
17+
/**
18+
* @throws RuntimeException
19+
*/
1520
public function __construct(
16-
string $configPath,
21+
private readonly string $projectPath,
1722
) {
23+
$configPath = $this->getConfigPath();
1824
if (! file_exists($configPath)) {
1925
return;
2026
}
2127

2228
$config = require $configPath;
2329
if (! array_key_exists(Maker::class, $config)) {
24-
Output::error(sprintf('%s: key "Maker::class" not found', $configPath), true);
30+
throw new RuntimeException(sprintf('%s: key "Maker::class" not found', $configPath));
2531
}
2632
}
33+
34+
public function getConfigPath(): string
35+
{
36+
return sprintf('%s/%s', $this->projectPath, self::CONFIG_FILE);
37+
}
2738
}

src/Context.php

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Dot\Maker;
66

7-
use Dot\Maker\IO\Output;
7+
use RuntimeException;
88

99
use function array_key_exists;
1010
use function explode;
@@ -14,24 +14,39 @@
1414
use function sprintf;
1515
use function str_starts_with;
1616

17-
class Context implements ContextInterface
17+
class Context
1818
{
19+
public const NAMESPACE_ADMIN = 'Admin';
20+
public const NAMESPACE_API = 'Api';
21+
public const NAMESPACE_CORE = 'Core';
22+
public const NAMESPACE_FRONTEND = 'Frontend';
23+
public const NAMESPACE_LIGHT = 'Light';
24+
public const NAMESPACE_QUEUE = 'Queue';
25+
1926
private bool $hasCore = false;
2027
private ?string $projectType = null;
2128
private ?string $rootNamespace = null;
2229

23-
public function __construct(string $composerPath)
24-
{
30+
/**
31+
* @throws RuntimeException
32+
*/
33+
public function __construct(
34+
private readonly string $projectPath,
35+
) {
36+
$composerPath = sprintf('%s/composer.json', $this->projectPath);
2537
if (! file_exists($composerPath)) {
26-
Output::error(sprintf('composer.json not found at "%s"', $composerPath), true);
38+
throw new RuntimeException(sprintf('%s: not found', $composerPath));
2739
}
2840

2941
$composer = json_decode(file_get_contents($composerPath), true);
42+
if ($composer === null) {
43+
throw new RuntimeException(sprintf('%s: invalid JSON', $composerPath));
44+
}
3045
if (! array_key_exists('autoload', $composer)) {
31-
Output::error('composer.json: key "autoload" not found', true);
46+
throw new RuntimeException(sprintf('%s: key "autoload" not found', $composerPath));
3247
}
3348
if (! array_key_exists('psr-4', $composer['autoload'])) {
34-
Output::error('composer.json: key "psr-4" not found in "autoload"', true);
49+
throw new RuntimeException(sprintf('%s: key "autoload"."psr-4" not found', $composerPath));
3550
}
3651

3752
$coreNamespace = sprintf('%s\\', self::NAMESPACE_CORE);
@@ -48,7 +63,12 @@ public function __construct(string $composerPath)
4863
}
4964
}
5065

51-
public function getProjectType(): string
66+
public function getProjectPath(): string
67+
{
68+
return $this->projectPath;
69+
}
70+
71+
public function getProjectType(): ?string
5272
{
5373
return $this->projectType;
5474
}
@@ -63,8 +83,28 @@ public function hasCore(): bool
6383
return $this->hasCore;
6484
}
6585

86+
public function isAdmin(): bool
87+
{
88+
return $this->projectType === self::NAMESPACE_ADMIN;
89+
}
90+
6691
public function isApi(): bool
6792
{
6893
return $this->projectType === self::NAMESPACE_API;
6994
}
95+
96+
public function isFrontend(): bool
97+
{
98+
return $this->projectType === self::NAMESPACE_FRONTEND;
99+
}
100+
101+
public function isLight(): bool
102+
{
103+
return $this->projectType === self::NAMESPACE_LIGHT;
104+
}
105+
106+
public function isQueue(): bool
107+
{
108+
return $this->projectType === self::NAMESPACE_QUEUE;
109+
}
70110
}

src/ContextInterface.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)