-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMessage.php
More file actions
201 lines (177 loc) · 6.46 KB
/
Copy pathMessage.php
File metadata and controls
201 lines (177 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
declare(strict_types=1);
namespace Dot\Maker;
use function sprintf;
use const PHP_EOL;
class Message
{
public const ADD_CONFIG_PROVIDER_TO_CONFIG = 1;
public const ADD_CORE_CONFIG_PROVIDER_TO_CONFIG = 2;
public const ADD_COMMAND_TO_CONFIG = 3;
public const ADD_MIDDLEWARE_TO_PIPELINE = 4;
public const ADD_ROUTES_TO_AUTH_CONFIG = 5;
public const ADD_MODULE_TO_COMPOSER = 6;
public const ADD_CORE_MODULE_TO_COMPOSER = 7;
public const DUMP_COMPOSER_AUTOLOADER = 8;
public const GENERATE_MIGRATION = 9;
public const CHECK_FILES = 10;
public function __construct(
private string $message,
private int $priority = 0,
) {
}
public function __toString(): string
{
return $this->message;
}
public function append(string $message): self
{
$this->message .= $message;
return $this;
}
public function appendLine(string $message): self
{
$this->message .= PHP_EOL . $message;
return $this;
}
public static function addCommandToConfig(string $fqcn): self
{
return (new self('add to ', self::ADD_COMMAND_TO_CONFIG))
->append(
ColorEnum::colorize('config/autoload/cli.global.php', ColorEnum::ForegroundBrightWhite)
)
->append(' under ')
->append(
ColorEnum::colorize('dot_cli', ColorEnum::ForegroundBrightWhite)
)
->append('.')
->append(
ColorEnum::colorize('commands', ColorEnum::ForegroundBrightWhite)
)
->append(':')
->appendLine(
ColorEnum::colorize(
sprintf(' %s::getDefaultName() => %s::class,', $fqcn, $fqcn),
ColorEnum::ForegroundBrightYellow
)
);
}
public static function addConfigProviderToConfig(string $fqcn): self
{
return (new self('add to ', self::ADD_CONFIG_PROVIDER_TO_CONFIG))
->append(
ColorEnum::colorize('config/config.php', ColorEnum::ForegroundBrightWhite)
)
->append(':')
->appendLine(
ColorEnum::colorize(sprintf(' %s::class,', $fqcn), ColorEnum::ForegroundBrightYellow)
);
}
public static function addCoreConfigProviderToConfig(string $fqcn): self
{
return self::addConfigProviderToConfig($fqcn)->setPriority(self::ADD_CORE_CONFIG_PROVIDER_TO_CONFIG);
}
public static function addModuleToComposer(string $rootNamespace, string $moduleName): self
{
return (new self('add to ', self::ADD_MODULE_TO_COMPOSER))
->append(
ColorEnum::colorize('composer.json', ColorEnum::ForegroundBrightWhite)
)
->append(' under ')
->append(
ColorEnum::colorize('autoload', ColorEnum::ForegroundBrightWhite)
)
->append('.')
->append(
ColorEnum::colorize('psr-4', ColorEnum::ForegroundBrightWhite)
)
->append(':')
->appendLine(
ColorEnum::colorize(
sprintf(' "%s\\\\%s\\\\": "src/%s/src/"', $rootNamespace, $moduleName, $moduleName),
ColorEnum::ForegroundBrightYellow
)
);
}
public static function addCoreModuleToComposer(string $moduleName): self
{
return (new self('add to ', self::ADD_CORE_MODULE_TO_COMPOSER))
->append(
ColorEnum::colorize('composer.json', ColorEnum::ForegroundBrightWhite)
)
->append(' under ')
->append(
ColorEnum::colorize('autoload', ColorEnum::ForegroundBrightWhite)
)
->append('.')
->append(
ColorEnum::colorize('psr-4', ColorEnum::ForegroundBrightWhite)
)
->append(':')
->appendLine(
ColorEnum::colorize(
sprintf(
' "%s\\\\%s\\\\": "src/%s/src/%s/src/"',
Context::NAMESPACE_CORE,
$moduleName,
Context::NAMESPACE_CORE,
$moduleName
),
ColorEnum::ForegroundBrightYellow
)
);
}
public static function addMiddlewareToPipeline(string $fqcn): self
{
return (new self('add to ', self::ADD_MIDDLEWARE_TO_PIPELINE))
->append(
ColorEnum::colorize('config/pipeline.php', ColorEnum::ForegroundBrightWhite)
)
->append(':')
->appendLine(
ColorEnum::colorize(sprintf(' $app->pipe(%s::class);', $fqcn), ColorEnum::ForegroundBrightYellow)
);
}
public static function addRoutesToAuthConfig(string $config, string $routesDelegator): self
{
return (new self('add to ', self::ADD_ROUTES_TO_AUTH_CONFIG))
->append(
ColorEnum::colorize($config, ColorEnum::ForegroundBrightWhite)
)
->appendLine(' the routes registered in ')
->append(
ColorEnum::colorize($routesDelegator, ColorEnum::ForegroundBrightWhite)
);
}
public static function checkFiles(): self
{
return new self(
ColorEnum::colorize(
'Review each new file, verify their contents and start adding logic to them.',
ColorEnum::ForegroundBrightRed
),
self::CHECK_FILES
);
}
public static function dumpComposerAutoloader(): self
{
return (new self('dump Composer autoloader by executing this command:', self::DUMP_COMPOSER_AUTOLOADER))
->appendLine(ColorEnum::colorize(' composer dump', ColorEnum::ForegroundBrightYellow));
}
public static function generateMigration(): self
{
return (new self('generate Doctrine migration:', self::GENERATE_MIGRATION))
->appendLine(
ColorEnum::colorize(' php ./vendor/bin/doctrine-migrations diff', ColorEnum::ForegroundBrightYellow)
);
}
public function getPriority(): int
{
return $this->priority;
}
public function setPriority(int $priority): self
{
$this->priority = $priority;
return $this;
}
}