Skip to content

Maker Commands #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
0c7f247
feat: Add initial domain model maker
b00gizm Jan 21, 2023
3a9c485
feat: Add entity mapping capabilities to the model maker.
b00gizm Jan 21, 2023
e0f72fa
fix: Use `attribute` instead of `annotation`.
b00gizm Jan 21, 2023
94ffb49
fix: Add missing import for identity type class.
b00gizm Jan 21, 2023
cdb533a
chore: Exclude `src/Resources/skeleton` from linters.
b00gizm Jan 21, 2023
766cd0f
Merge branch 'main' into feat/domain-model-maker
b00gizm Jan 21, 2023
6b44378
fix hard-coded 'identity' attribute name
janvt Mar 6, 2023
0060e39
move Doctrine config check to interact step
janvt Mar 6, 2023
2bbafd2
fix test class name
janvt Mar 7, 2023
4505860
add unit tests to github action
janvt Mar 7, 2023
acfd030
fix phpunit version
janvt Mar 7, 2023
e059bd1
fix phpunit version, again
janvt Mar 7, 2023
fc9607d
fix phpunit config
janvt Mar 7, 2023
25fca64
remove invalid version parameter
janvt Mar 7, 2023
cf8cb72
fix path to phpunit config
janvt Mar 7, 2023
f4898c3
add php version
janvt Mar 7, 2023
9f60b5c
why is there a 'g' there?
janvt Mar 7, 2023
856cb00
remove php_version
janvt Mar 7, 2023
7fec342
add integration test
janvt Mar 8, 2023
108535e
generate Repository along with entity
janvt Mar 9, 2023
fc83b60
remove non-functioning integration test
janvt Mar 9, 2023
d743d66
add docs
janvt Mar 9, 2023
ddceaea
query maker command
janvt Mar 9, 2023
3c3fb35
change repository example
janvt Mar 10, 2023
6dc37a9
Merge branch 'feat/maker-commands' into feat/maker-query
janvt Mar 10, 2023
4bf8e6e
minor template improvements
janvt Mar 10, 2023
425a9c1
add docs
janvt Mar 10, 2023
5d78130
add maker command for command entity / handler
janvt Mar 10, 2023
bb4c467
Merge pull request #19 from geekcell/feat/maker-query
Mar 10, 2023
6f2e293
change command return type to void
janvt Mar 10, 2023
aaecb4f
add maker command for controller
janvt Mar 10, 2023
3e52790
add docs
janvt Mar 10, 2023
679e03a
add command for creating API Platform resource
janvt Mar 13, 2023
883316e
check for API Platform
janvt Mar 13, 2023
4c79cf0
generate optional XML config instead of PHP attributes
janvt Mar 14, 2023
8c653f0
adjust Api Platform version check to check for >2.7
janvt Mar 14, 2023
870a036
add docs
janvt Mar 14, 2023
9dd1210
Merge pull request #21 from geekcell/feat/maker-command
Mar 15, 2023
3a3da45
Merge pull request #22 from geekcell/feat/maker-controller
Mar 15, 2023
c618af6
Merge pull request #25 from geekcell/feat/maker-resource
Mar 15, 2023
16edbce
Merge branch 'main' into feat/maker-commands
janvt Mar 15, 2023
05ba746
use String component for snake casing
janvt Mar 16, 2023
826ea99
adjust repository generation
janvt Mar 17, 2023
e8a51e8
add QueryBuilder dependency to use classes
janvt Mar 17, 2023
ebd9100
add resource identifier
janvt Mar 20, 2023
eb695d5
fix xml config generation
janvt Mar 21, 2023
35b5ceb
rename base CQRS command
janvt Mar 21, 2023
35c17b8
fix: Remove unused character.
b00gizm Mar 21, 2023
5c5e38c
chore: Add small changes to generated code.
b00gizm Mar 21, 2023
09a5436
fix command option defaults
janvt Mar 27, 2023
6c6c3c8
pass back test kernel in integration test
janvt Mar 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Tests

on: [push]

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- name: PHPUnit Tests
uses: php-actions/phpunit@v9
with:
configuration: tests/phpunit.xml
5 changes: 4 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude(['var', 'vendor', 'migrations', 'fixtures'])
->exclude([
'src/Resources/skeleton',
'vendor'
])
->in(__DIR__)
;

Expand Down
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,99 @@ class Logger extends Facade
```

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.

## Generator Commands

This bundle adds several [maker bundle](https://symfony.com/bundles/SymfonyMakerBundle/current/index.html) commands to generate commonly used components.

### Model / Repository

This command can be used to generate:

- The domain model class.
- A repository class for the model.
- The model's identity class as value object (optional).
- A Doctrine database entity configuration, either as annotation or separate config file (optional).
- A custom Doctrine type for the model's identity class (optional).

#### Command Output

```bash
Description:
Creates a new domain model class

Usage:
make:ddd:model [options] [--] [<name>]

Arguments:
name The name of the model class (e.g. Customer)

Options:
--aggregate-root Marks the model as aggregate root
--entity=ENTITY Use this model as Doctrine entity
--with-identity=WITH-IDENTITY Whether an identity value object should be created
--with-suffix Adds the suffix "Model" to the model class name
```

### Query / Command

These commands can be used to generate:

- A query and query handler class.
- A command and command handler class.

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).

#### Command Output

```bash
Description:
Creates a new query|command class and handler

Usage:
make:ddd:query|command [<name>]

Arguments:
name The name of the query|command class (e.g. Customer)
```

### Controller

This command can be used to generate a controller with optional `QueryBus` and `CommandBus` dependencies.

#### Command Output

```bash
Description:
Creates a new controller class

Usage:
make:ddd:controller [options] [--] [<name>]

Arguments:
name The name of the model class (e.g. Customer)

Options:
--include-query-bus Add a query bus dependency
--include-command-bus Add a command bus dependency
```

### Resource

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.

#### Command Output

```bash
Description:
Creates a new API Platform resource

Usage:
make:ddd:resource [options] [--] [<name>]

Arguments:
name The name of the model class to create the resource for (e.g. Customer). Model must exist already.

Options:
--config Config flavor to create (attribute|xml).
```
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
"phpunit/phpunit": "^9.5",
"symfony/framework-bundle": "^6.0",
"symfony/yaml": "^6.0",
"symfony/filesystem": "^6.0"
"symfony/filesystem": "^6.0",
"symfony/maker-bundle": "^1.48"
},
"autoload": {
"psr-4": {
"GeekCell\\DddBundle\\": "src"
"GeekCell\\DddBundle\\": "src/"
}
},
"autoload-dev": {
Expand Down
113 changes: 106 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,44 @@ services:
arguments:
- '@Symfony\Component\Messenger\MessageBusInterface'
public: true

GeekCell\DddBundle\Maker\MakeModel:
class: GeekCell\DddBundle\Maker\MakeModel
arguments:
- '@GeekCell\DddBundle\Maker\Doctrine\DoctrineConfigUpdater'
- '@maker.file_manager'
tags:
- { name: maker.command }

GeekCell\DddBundle\Maker\MakeQuery:
class: GeekCell\DddBundle\Maker\MakeQuery
tags:
- { name: maker.command }

GeekCell\DddBundle\Maker\MakeCommand:
class: GeekCell\DddBundle\Maker\MakeCommand
tags:
- { name: maker.command }

GeekCell\DddBundle\Maker\MakeController:
class: GeekCell\DddBundle\Maker\MakeController
arguments:
- '@maker.file_manager'
tags:
- { name: maker.command }

GeekCell\DddBundle\Maker\MakeResource:
class: GeekCell\DddBundle\Maker\MakeResource
arguments:
- '@maker.file_manager'
- '@GeekCell\DddBundle\Maker\Doctrine\ApiPlatformConfigUpdator'
tags:
- { name: maker.command }

GeekCell\DddBundle\Maker\Doctrine\DoctrineConfigUpdater:
class: GeekCell\DddBundle\Maker\Doctrine\DoctrineConfigUpdater
public: false

GeekCell\DddBundle\Maker\Doctrine\ApiPlatformConfigUpdator:
class: GeekCell\DddBundle\Maker\ApiPlatform\ApiPlatformConfigUpdater
public: false
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ parameters:
- src
- tests
excludePaths:
- src/Resources/skeleton
- vendor/
41 changes: 41 additions & 0 deletions src/Maker/AbstractBaseConfigUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace GeekCell\DddBundle\Maker;

use Assert;
use Assert\AssertionFailedException;
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;

abstract class AbstractBaseConfigUpdater
{
private ?YamlSourceManipulator $manipulator;

/**
* Creates a YamlSourceManipulator from a YAML source.
*
* @param string $yamlSource
* @return array<string, string|string[]>
*/
protected function read(string $yamlSource): array
{
$this->manipulator = new YamlSourceManipulator($yamlSource);
return $this->manipulator->getData();
}

/**
* Returns the updated YAML contents for the given data.
*
* @param array<string, string|string[]> $yamlData
* @return string
* @throws AssertionFailedException
*/
protected function write(array $yamlData): string
{
Assert\Assertion::notNull($this->manipulator);
$this->manipulator->setData($yamlData);

return $this->manipulator->getContents();
}
}
Loading