Skip to content

Commit e283150

Browse files
committed
WIP
Signed-off-by: alexmerlin <alex.merlin.1985@gmail.com>
1 parent 91fa041 commit e283150

File tree

18 files changed

+121
-45
lines changed

18 files changed

+121
-45
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
11
# Create Collection
22

33
> Collections can be created only in APIs.
4+
5+
To create a collection, use either of the following commands:
6+
7+
```shell
8+
composer make collection
9+
```
10+
11+
OR
12+
13+
```shell
14+
./vendor/bin/dot-maker collection
15+
```
16+
17+
The command must identify in which module you want to create the new collection.
18+
To determine this, it will prompt you to enter the name of an existing module:
19+
20+
> Existing module name:
21+
22+
If you input a module name which does not exist (like, "NonExistentModule"), the command throws an error:
23+
24+
> Module "NonExistentModule" not found
25+
26+
and will keep prompting for a valid module name until you provide one.
27+
28+
---
29+
30+
Once the target module has been identified, the command will prompt you to input a name for the collection:
31+
32+
> Collection name:
33+
34+
**The name must contain only letters and numbers.**
35+
36+
If you leave the name blank, the command will exit.
37+
38+
If you input an invalid name (like, "."), the command throws an error:
39+
40+
> Invalid Collection name: "."
41+
42+
If you input the name of an existing collection (like, "ExistingCollection"), the command throws an error:
43+
44+
> Class "ExistingCollection" already exists at /path/to/project/src/ExistingModule/src/Collection/ExistingCollection.php
45+
46+
If you input a valid name, the command will create the collection and output a success message:
47+
48+
> Created Collection: /path/to/project/src/ExistingModule/src/Collection/NewCollection.php
49+
50+
To allow the creation of multiple collections, the command will loop until you leave the name blank.

docs/book/v1/component/handler.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Create Handler

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ nav:
1717
- Create Command: v1/component/command.md
1818
- Create Entity: v1/component/entity.md
1919
- Create Form: v1/component/form.md
20+
- Create Handler: v1/component/handler.md
2021
- Create Input: v1/component/input.md
2122
- Create InputFilter: v1/component/input-filter.md
2223
- Create Middleware: v1/component/middleware.md

src/IO/Output.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public static function warning(string $message, bool $exit = false): void
4949
$exit && exit(self::SUCCESS);
5050
}
5151

52-
public static function write(string $message, bool $exit = false): void
52+
public static function write(string $message = '', bool $exit = false): void
5353
{
5454
fwrite(STDOUT, $message);
5555
$exit && exit(self::SUCCESS);
5656
}
5757

58-
public static function writeLine(string $message, bool $exit = false): void
58+
public static function writeLine(string $message = '', bool $exit = false): void
5959
{
6060
fwrite(STDOUT, $message . PHP_EOL);
6161
$exit && exit(self::SUCCESS);

src/Type/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __invoke(): void
2727
}
2828

2929
while (true) {
30-
$name = ucfirst(Input::prompt('Enter new Collection name: '));
30+
$name = ucfirst(Input::prompt('Collection name: '));
3131
if ($name === '') {
3232
return;
3333
}

src/Type/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Command extends AbstractType implements FileInterface
3131
public function __invoke(): void
3232
{
3333
while (true) {
34-
$name = ucfirst(Input::prompt('Enter new Command name: '));
34+
$name = ucfirst(Input::prompt('Command name: '));
3535
if ($name === '') {
3636
return;
3737
}

src/Type/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Entity extends AbstractType implements FileInterface
2828
public function __invoke(): void
2929
{
3030
while (true) {
31-
$name = ucfirst(Input::prompt('Enter new Entity name: '));
31+
$name = ucfirst(Input::prompt('Entity name: '));
3232
if ($name === '') {
3333
return;
3434
}

src/Type/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __invoke(): void
2323
return;
2424
}
2525

26-
$name = ucfirst(Input::prompt('Enter new Form name: '));
26+
$name = ucfirst(Input::prompt('Form name: '));
2727
if ($name === '') {
2828
return;
2929
}

src/Type/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Handler extends AbstractType implements FileInterface
1919
public function __invoke(): void
2020
{
2121
while (true) {
22-
$name = ucfirst(Input::prompt('Enter new Handler name: '));
22+
$name = ucfirst(Input::prompt('Handler name: '));
2323
if ($name === '') {
2424
break;
2525
}

src/Type/Help.php

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

55
namespace Dot\Maker\Type;
66

7+
use Dot\Maker\ColorEnum;
78
use Dot\Maker\IO\Output;
9+
use Dot\Maker\Message;
810

911
class Help extends AbstractType
1012
{
1113
public function __invoke(): void
1214
{
1315
Output::info('dot-maker');
14-
Output::writeLine(<<<HELP
15-
16-
Usage: ./vendor/bin/dot-maker <component>
17-
18-
Where <component> must be replaced with one of the following strings:
19-
— collection
20-
— command
21-
— command
22-
— entity
23-
— form
24-
— handler
25-
— input
26-
— input-filter
27-
— middleware
28-
— module
29-
— repository
30-
— service
31-
HELP);
16+
Output::writeLine();
17+
Output::writeLine(
18+
(string) (new Message('Usage: '))
19+
->appendLine(
20+
ColorEnum::colorize('./vendor/bin/dot-maker', ColorEnum::ForegroundBrightWhite)
21+
)
22+
->append(' ')
23+
->append(
24+
ColorEnum::colorize('<component>', ColorEnum::ForegroundBrightYellow)
25+
)
26+
);
27+
Output::writeLine('OR');
28+
Output::writeLine(
29+
(string) (new Message())
30+
->append(
31+
ColorEnum::colorize('composer make', ColorEnum::ForegroundBrightWhite)
32+
)
33+
->append(' ')
34+
->append(
35+
ColorEnum::colorize('<component>', ColorEnum::ForegroundBrightYellow)
36+
)
37+
);
38+
Output::writeLine();
39+
Output::writeLine(
40+
(string) (new Message('Where '))
41+
->append(
42+
ColorEnum::colorize('<component>', ColorEnum::ForegroundBrightYellow)
43+
)
44+
->append(' must be replaced with one of the following strings:')
45+
);
46+
Output::writeLine('— collection');
47+
Output::writeLine('— command');
48+
Output::writeLine('— entity');
49+
Output::writeLine('— form');
50+
Output::writeLine('— handler');
51+
Output::writeLine('— input');
52+
Output::writeLine('— input-filter');
53+
Output::writeLine('— middleware');
54+
Output::writeLine('— module');
55+
Output::writeLine('— repository');
56+
Output::writeLine('— service');
57+
Output::writeLine('— service-interface');
3258
}
3359
}

0 commit comments

Comments
 (0)