Skip to content

Commit cd61d82

Browse files
janvtb00gizm
janvt
andauthored
Maker Commands (#20)
feat: add maker commands --------- Co-authored-by: Pascal Cremer <pascal.cremer@geekcell.io>
1 parent 8cade75 commit cd61d82

37 files changed

+2114
-10
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
unit-test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: php-actions/composer@v6
11+
- name: PHPUnit Tests
12+
uses: php-actions/phpunit@v9
13+
with:
14+
configuration: tests/phpunit.xml

.php-cs-fixer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
22

33
$finder = PhpCsFixer\Finder::create()
4-
->exclude(['var', 'vendor', 'migrations', 'fixtures'])
4+
->exclude([
5+
'src/Resources/skeleton',
6+
'vendor'
7+
])
58
->in(__DIR__)
69
;
710

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,99 @@ class Logger extends Facade
153153
```
154154

155155
Although facades are better testable than regular singletons, it is highly recommended to only use them sparringly and always prefer normal dependency injection when possible.
156+
157+
## Generator Commands
158+
159+
This bundle adds several [maker bundle](https://symfony.com/bundles/SymfonyMakerBundle/current/index.html) commands to generate commonly used components.
160+
161+
### Model / Repository
162+
163+
This command can be used to generate:
164+
165+
- The domain model class.
166+
- A repository class for the model.
167+
- The model's identity class as value object (optional).
168+
- A Doctrine database entity configuration, either as annotation or separate config file (optional).
169+
- A custom Doctrine type for the model's identity class (optional).
170+
171+
#### Command Output
172+
173+
```bash
174+
Description:
175+
Creates a new domain model class
176+
177+
Usage:
178+
make:ddd:model [options] [--] [<name>]
179+
180+
Arguments:
181+
name The name of the model class (e.g. Customer)
182+
183+
Options:
184+
--aggregate-root Marks the model as aggregate root
185+
--entity=ENTITY Use this model as Doctrine entity
186+
--with-identity=WITH-IDENTITY Whether an identity value object should be created
187+
--with-suffix Adds the suffix "Model" to the model class name
188+
```
189+
190+
### Query / Command
191+
192+
These commands can be used to generate:
193+
194+
- A query and query handler class.
195+
- A command and command handler class.
196+
197+
The query / command generated is just an empty class. The handler class is registered as a message handler for the configured [Symfony Messenger](https://symfony.com/doc/current/messenger.html).
198+
199+
#### Command Output
200+
201+
```bash
202+
Description:
203+
Creates a new query|command class and handler
204+
205+
Usage:
206+
make:ddd:query|command [<name>]
207+
208+
Arguments:
209+
name The name of the query|command class (e.g. Customer)
210+
```
211+
212+
### Controller
213+
214+
This command can be used to generate a controller with optional `QueryBus` and `CommandBus` dependencies.
215+
216+
#### Command Output
217+
218+
```bash
219+
Description:
220+
Creates a new controller class
221+
222+
Usage:
223+
make:ddd:controller [options] [--] [<name>]
224+
225+
Arguments:
226+
name The name of the model class (e.g. Customer)
227+
228+
Options:
229+
--include-query-bus Add a query bus dependency
230+
--include-command-bus Add a command bus dependency
231+
```
232+
233+
### Resource
234+
235+
This command can be used to generate an [Api Platform](https://api-platform.com/) resource. Minimum required version is [2.7](https://api-platform.com/docs/core/upgrade-guide/#api-platform-2730) for the PHP attributes support.
236+
237+
#### Command Output
238+
239+
```bash
240+
Description:
241+
Creates a new API Platform resource
242+
243+
Usage:
244+
make:ddd:resource [options] [--] [<name>]
245+
246+
Arguments:
247+
name The name of the model class to create the resource for (e.g. Customer). Model must exist already.
248+
249+
Options:
250+
--config Config flavor to create (attribute|xml).
251+
```

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
"phpunit/phpunit": "^9.5",
3030
"symfony/framework-bundle": "^6.0",
3131
"symfony/yaml": "^6.0",
32-
"symfony/filesystem": "^6.0"
32+
"symfony/filesystem": "^6.0",
33+
"symfony/maker-bundle": "^1.48"
3334
},
3435
"autoload": {
3536
"psr-4": {
36-
"GeekCell\\DddBundle\\": "src"
37+
"GeekCell\\DddBundle\\": "src/"
3738
}
3839
},
3940
"autoload-dev": {

composer.lock

Lines changed: 106 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/services.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,44 @@ services:
1010
arguments:
1111
- '@Symfony\Component\Messenger\MessageBusInterface'
1212
public: true
13+
14+
GeekCell\DddBundle\Maker\MakeModel:
15+
class: GeekCell\DddBundle\Maker\MakeModel
16+
arguments:
17+
- '@GeekCell\DddBundle\Maker\Doctrine\DoctrineConfigUpdater'
18+
- '@maker.file_manager'
19+
tags:
20+
- { name: maker.command }
21+
22+
GeekCell\DddBundle\Maker\MakeQuery:
23+
class: GeekCell\DddBundle\Maker\MakeQuery
24+
tags:
25+
- { name: maker.command }
26+
27+
GeekCell\DddBundle\Maker\MakeCommand:
28+
class: GeekCell\DddBundle\Maker\MakeCommand
29+
tags:
30+
- { name: maker.command }
31+
32+
GeekCell\DddBundle\Maker\MakeController:
33+
class: GeekCell\DddBundle\Maker\MakeController
34+
arguments:
35+
- '@maker.file_manager'
36+
tags:
37+
- { name: maker.command }
38+
39+
GeekCell\DddBundle\Maker\MakeResource:
40+
class: GeekCell\DddBundle\Maker\MakeResource
41+
arguments:
42+
- '@maker.file_manager'
43+
- '@GeekCell\DddBundle\Maker\Doctrine\ApiPlatformConfigUpdator'
44+
tags:
45+
- { name: maker.command }
46+
47+
GeekCell\DddBundle\Maker\Doctrine\DoctrineConfigUpdater:
48+
class: GeekCell\DddBundle\Maker\Doctrine\DoctrineConfigUpdater
49+
public: false
50+
51+
GeekCell\DddBundle\Maker\Doctrine\ApiPlatformConfigUpdator:
52+
class: GeekCell\DddBundle\Maker\ApiPlatform\ApiPlatformConfigUpdater
53+
public: false

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ parameters:
88
- src
99
- tests
1010
excludePaths:
11+
- src/Resources/skeleton
1112
- vendor/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace GeekCell\DddBundle\Maker;
6+
7+
use Assert;
8+
use Assert\AssertionFailedException;
9+
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
10+
11+
abstract class AbstractBaseConfigUpdater
12+
{
13+
private ?YamlSourceManipulator $manipulator;
14+
15+
/**
16+
* Creates a YamlSourceManipulator from a YAML source.
17+
*
18+
* @param string $yamlSource
19+
* @return array<string, string|string[]>
20+
*/
21+
protected function read(string $yamlSource): array
22+
{
23+
$this->manipulator = new YamlSourceManipulator($yamlSource);
24+
return $this->manipulator->getData();
25+
}
26+
27+
/**
28+
* Returns the updated YAML contents for the given data.
29+
*
30+
* @param array<string, string|string[]> $yamlData
31+
* @return string
32+
* @throws AssertionFailedException
33+
*/
34+
protected function write(array $yamlData): string
35+
{
36+
Assert\Assertion::notNull($this->manipulator);
37+
$this->manipulator->setData($yamlData);
38+
39+
return $this->manipulator->getContents();
40+
}
41+
}

0 commit comments

Comments
 (0)