Skip to content

Commit 11dc50b

Browse files
committed
WIP
Signed-off-by: alexmerlin <alex.merlin.1985@gmail.com>
1 parent 2c245aa commit 11dc50b

File tree

10 files changed

+255
-12
lines changed

10 files changed

+255
-12
lines changed

src/Message.php

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Dot\Maker;
6+
7+
use function sprintf;
8+
9+
use const PHP_EOL;
10+
11+
class Message
12+
{
13+
public const ADD_CONFIG_PROVIDER_TO_CONFIG = 1;
14+
public const ADD_CORE_CONFIG_PROVIDER_TO_CONFIG = 2;
15+
public const ADD_MODULE_TO_COMPOSER = 3;
16+
public const ADD_CORE_MODULE_TO_COMPOSER = 4;
17+
public const ADD_COMMAND_TO_CONFIG = 5;
18+
public const ADD_MIDDLEWARE_TO_PIPELINE = 6;
19+
public const DUMP_COMPOSER_AUTOLOADER = 7;
20+
public const GENERATE_MIGRATION = 8;
21+
22+
public function __construct(
23+
private string $message = '',
24+
private int $priority = 10,
25+
) {
26+
}
27+
28+
public function __toString(): string
29+
{
30+
return $this->message;
31+
}
32+
33+
public function append(string $message): self
34+
{
35+
$this->message .= $message;
36+
37+
return $this;
38+
}
39+
40+
public function appendLine(string $message): self
41+
{
42+
$this->message .= PHP_EOL . $message;
43+
44+
return $this;
45+
}
46+
47+
public static function addCommandToConfig(string $fqcn): self
48+
{
49+
return (new self('add to ', self::ADD_COMMAND_TO_CONFIG))
50+
->append(
51+
ColorEnum::colorize('config/autoload/cli.global.php', ColorEnum::ForegroundBrightWhite)
52+
)
53+
->append(' under ')
54+
->append(
55+
ColorEnum::colorize('dot_cli', ColorEnum::ForegroundBrightWhite)
56+
)
57+
->append('.')
58+
->append(
59+
ColorEnum::colorize('commands', ColorEnum::ForegroundBrightWhite)
60+
)
61+
->append(':')
62+
->appendLine(
63+
ColorEnum::colorize(
64+
sprintf(' %s::getDefaultName() => %s::class,', $fqcn, $fqcn),
65+
ColorEnum::ForegroundBrightYellow
66+
)
67+
);
68+
}
69+
70+
public static function addConfigProviderToConfig(string $fqcn): self
71+
{
72+
return (new self('add to ', self::ADD_CONFIG_PROVIDER_TO_CONFIG))
73+
->append(
74+
ColorEnum::colorize('config/config.php', ColorEnum::ForegroundBrightWhite)
75+
)
76+
->append(':')
77+
->appendLine(
78+
ColorEnum::colorize(sprintf(' %s,', $fqcn), ColorEnum::ForegroundBrightYellow)
79+
);
80+
}
81+
82+
public static function addCoreConfigProviderToConfig(string $fqcn): self
83+
{
84+
return self::addConfigProviderToConfig($fqcn)->setPriority(self::ADD_CORE_CONFIG_PROVIDER_TO_CONFIG);
85+
}
86+
87+
public static function addModuleToComposer(string $rootNamespace, string $moduleName): self
88+
{
89+
return (new self('add to ', self::ADD_MODULE_TO_COMPOSER))
90+
->append(
91+
ColorEnum::colorize('composer.json', ColorEnum::ForegroundBrightWhite)
92+
)
93+
->append(' under ')
94+
->append(
95+
ColorEnum::colorize('autoload', ColorEnum::ForegroundBrightWhite)
96+
)
97+
->append('.')
98+
->append(
99+
ColorEnum::colorize('psr-4', ColorEnum::ForegroundBrightWhite)
100+
)
101+
->append(':')
102+
->appendLine(
103+
ColorEnum::colorize(
104+
sprintf(' "%s\\\\%s\\\\": "src/%s/src/"', $rootNamespace, $moduleName, $moduleName),
105+
ColorEnum::ForegroundBrightYellow
106+
)
107+
);
108+
}
109+
110+
public static function addCoreModuleToComposer(string $moduleName): self
111+
{
112+
return (new self('add to ', self::ADD_CORE_MODULE_TO_COMPOSER))
113+
->append(
114+
ColorEnum::colorize('composer.json', ColorEnum::ForegroundBrightWhite)
115+
)
116+
->append(' under ')
117+
->append(
118+
ColorEnum::colorize('autoload', ColorEnum::ForegroundBrightWhite)
119+
)
120+
->append('.')
121+
->append(
122+
ColorEnum::colorize('psr-4', ColorEnum::ForegroundBrightWhite)
123+
)
124+
->append(':')
125+
->appendLine(
126+
ColorEnum::colorize(
127+
sprintf(
128+
' "%s\\\\%s\\\\": "src/%s/src/%s/src/"',
129+
ContextInterface::NAMESPACE_CORE,
130+
$moduleName,
131+
ContextInterface::NAMESPACE_CORE,
132+
$moduleName
133+
),
134+
ColorEnum::ForegroundBrightYellow
135+
)
136+
);
137+
}
138+
139+
public static function addMiddlewareToPipeline(string $fqcn): self
140+
{
141+
return (new self('add to ', self::ADD_MIDDLEWARE_TO_PIPELINE))
142+
->append(
143+
ColorEnum::colorize('config/pipeline.php', ColorEnum::ForegroundBrightWhite)
144+
)
145+
->append(':')
146+
->appendLine(
147+
ColorEnum::colorize(sprintf(' $app->pipe(%s);', $fqcn), ColorEnum::ForegroundBrightYellow)
148+
);
149+
}
150+
151+
public static function dumpComposerAutoloader(): self
152+
{
153+
return (new self('dump Composer autoloader by executing this command:'))
154+
->setPriority(self::DUMP_COMPOSER_AUTOLOADER)
155+
->appendLine(ColorEnum::colorize(' composer dump', ColorEnum::ForegroundBrightYellow));
156+
}
157+
158+
public static function generateMigration(): self
159+
{
160+
return (new self('generate Doctrine migration:'))
161+
->setPriority(self::GENERATE_MIGRATION)
162+
->appendLine(
163+
ColorEnum::colorize(' php ./vendor/bin/doctrine-migrations diff', ColorEnum::ForegroundBrightYellow)
164+
);
165+
}
166+
167+
public function getPriority(): int
168+
{
169+
return $this->priority;
170+
}
171+
172+
public function setPriority(int $priority): self
173+
{
174+
$this->priority = $priority;
175+
176+
return $this;
177+
}
178+
}

src/Type/AbstractType.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Dot\Maker\Config;
99
use Dot\Maker\ContextInterface;
1010
use Dot\Maker\FileSystem;
11+
use Dot\Maker\Message;
1112

1213
use function preg_match;
1314
use function sprintf;
@@ -25,6 +26,13 @@ public function __construct(
2526
$this->import = new Import($context);
2627
}
2728

29+
public function addMessage(Message $message): static
30+
{
31+
$this->module->addMessage($message);
32+
33+
return $this;
34+
}
35+
2836
public function getConfig(): Config
2937
{
3038
return $this->config;
@@ -70,7 +78,7 @@ public function isValid(string $name): bool
7078
return (bool) preg_match('/^[a-z0-9]+$/i', $name);
7179
}
7280

73-
public function setModule(?ModuleInterface $module): self
81+
public function setModule(?ModuleInterface $module): static
7482
{
7583
$this->module = $module;
7684

src/Type/Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Dot\Maker\FileSystem\File;
1919
use Dot\Maker\IO\Input;
2020
use Dot\Maker\IO\Output;
21+
use Dot\Maker\Message;
2122
use Dot\Maker\VisibilityEnum;
2223
use Throwable;
2324

@@ -70,6 +71,8 @@ public function create(string $name): File
7071

7172
$command->create($content);
7273

74+
$this->addMessage(Message::addCommandToConfig($command->getComponent()->getFqcn()));
75+
7376
Output::success(sprintf('Created Command "%s"', $command->getPath()));
7477

7578
return $command;

src/Type/ConfigProvider.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Dot\Maker\Exception\RuntimeException;
1313
use Dot\Maker\FileSystem\File;
1414
use Dot\Maker\IO\Output;
15+
use Dot\Maker\Message;
1516
use Dot\Maker\VisibilityEnum;
1617
use Throwable;
1718

@@ -87,6 +88,12 @@ public function create(string $name): File
8788

8889
$configProvider->create($content);
8990

91+
$this
92+
->addMessage(Message::addConfigProviderToConfig($configProvider->getComponent()->getFqcn()))
93+
->addMessage(
94+
Message::addModuleToComposer($this->context->getRootNamespace(), $this->fileSystem->getModuleName())
95+
);
96+
9097
Output::success(sprintf('Created ConfigProvider "%s"', $configProvider->getPath()));
9198

9299
return $configProvider;
@@ -277,6 +284,7 @@ public function renderApi(
277284
): string {
278285
$class = (new ClassFile($configProvider->getNamespace(), $configProvider->getClassName()))
279286
->useClass($this->import->getConfigProviderFqcn(), 'AppConfigProvider')
287+
->useClass(Import::MEZZIO_APPLICATION)
280288
->useClass(Import::MEZZIO_HAL_METADATA_METADATAMAP)
281289
->setComment(<<<COMM
282290
/**
@@ -316,13 +324,8 @@ public function renderApi(
316324
*/
317325
COMM)
318326
->appendBody('return [')
319-
->appendBody('\'delegators\' => [', 12);
320-
321-
if ($routesDelegator->exists()) {
322-
$class->useClass(Import::MEZZIO_APPLICATION);
323-
324-
$getDependencies->appendBody('Application::class => [RoutesDelegator::class],', 16);
325-
}
327+
->appendBody('\'delegators\' => [', 12)
328+
->appendBody('Application::class => [RoutesDelegator::class],', 16);
326329

327330
if (count($handlers) > 0) {
328331
foreach ($handlers as $handler) {

src/Type/CoreConfigProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Dot\Maker\Exception\RuntimeException;
1313
use Dot\Maker\FileSystem\File;
1414
use Dot\Maker\IO\Output;
15+
use Dot\Maker\Message;
1516
use Dot\Maker\VisibilityEnum;
1617
use Throwable;
1718

@@ -47,6 +48,10 @@ public function create(string $name): File
4748

4849
$configProvider->create($content);
4950

51+
$this
52+
->addMessage(Message::addCoreConfigProviderToConfig($configProvider->getComponent()->getFqcn()))
53+
->addMessage(Message::addCoreModuleToComposer($this->fileSystem->getModuleName()));
54+
5055
Output::success(sprintf('Created Core ConfigProvider "%s"', $configProvider->getPath()));
5156

5257
return $configProvider;

src/Type/Entity.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Dot\Maker\FileSystem\File;
1818
use Dot\Maker\IO\Input;
1919
use Dot\Maker\IO\Output;
20+
use Dot\Maker\Message;
2021
use Throwable;
2122

2223
use function sprintf;
@@ -64,6 +65,8 @@ public function create(string $name): File
6465

6566
$entity->create($content);
6667

68+
$this->addMessage(Message::generateMigration());
69+
6770
Output::success(sprintf('Created Entity "%s"', $entity->getPath()));
6871

6972
return $entity;

src/Type/Middleware.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Dot\Maker\FileSystem\File;
1818
use Dot\Maker\IO\Input;
1919
use Dot\Maker\IO\Output;
20+
use Dot\Maker\Message;
2021
use Throwable;
2122

2223
use function sprintf;
@@ -63,6 +64,8 @@ public function create(string $name): File
6364

6465
$middleware->create($content);
6566

67+
$this->addMessage(Message::addMiddlewareToPipeline($middleware->getComponent()->getFqcn()));
68+
6669
Output::success(sprintf('Created Middleware "%s"', $middleware->getPath()));
6770

6871
return $middleware;

0 commit comments

Comments
 (0)