becklyn / ddd-generator-bundle
Code generator for common Domain Driven Design patterns in the Becklyn DDD framework.
Installs: 4 075
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- ext-json: *
- symfony/maker-bundle: ^1.21
- symfony/process: ^5.1|^6.0
Requires (Dev)
- php: >=8.0
- becklyn/ddd-core: ^2.0
- doctrine/orm: ^2.8
- phpspec/prophecy: ^1.12
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-master
- symfony/config: ^5.1|^6.0
- symfony/console: ^5.1|^6.0
- symfony/dependency-injection: ^5.1|^6.0
- symfony/filesystem: ^5.1|^6.0
- symfony/finder: ^5.1|^6.0
- symfony/phpunit-bridge: ^5.1|^6.0
- symfony/yaml: ^5.1|^6.0
README
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
composer require becklyn/ddd-generator-bundle --dev
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require becklyn/ddd-generator-bundle --dev
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php return [ // ... Becklyn\DddGeneratorBundle\BecklynDddGeneratorBundle::class => ['dev' => true], ];
Creating your own Generator/Maker
If you want to create your own Generator based on the DddMaker you'll need to extend either of the abstract Maker classes.
Be sure not to extend a non-abstract class unless you can ensure that their implementation will never change.
If you can't ensure that it would be a better idea to use one of the following:
-
DddMaker: The most general abstraction. In only provides functionality without having a base implementation.
-
DddEntityMaker: This is the easiest to use for implementing a generator based on some input options. In fact most generator of this bundle use the DddEntityMaker.
-
DddEntityTestMaker: A specialized DddEntityMaker for generating Test files.
-
DddEntityCommandMaker: A specialized DddEntityMaker for generating Command and CommandHandler classes.
All you need to do to generate your own Generator is to create a class,
that extends a Maker in src/Maker
and to create a template file.
The template file may be placed in res/skeleton/ddd
or
src/Resources/skeleton/ddd
and use the file extension .tpl.php
.
If you cannot place the templates there you can also override the Makers getTemplatePath()
.
Refer to the Templating section for more information about how to create templates.
Lastly you need to register your Maker as a Maker in your service configuration file.
This is done by providing the maker.command
tag to the service.
A word about i18n
If you want to use the localization feature you should provide it using the
getExtraVariables()
method and use as $extra
in the template.
Alternatively you can override the internationalize()
method, but you'll need to
provide any key the bundle defines internally to continue to use the pre-defined features.
Because these keys can change between every patch version it could be very hard for you
to ensure that no functionality breaks.
Templating
The template files itself are plain text files that get php variables injected using
<?= $variableName; ?>
.
If you're using the DddEntityMaker
or a class that extends it you can use the following variables:
-
$domain_namespace
: The Sub-Namespace of the Domain. E.g.\App\Authorization\Domain\Foo
in this NamespaceFoo
would be the Sub-Namespace. This is a can also be multi-level e.g.Foo\Bar
-
$entity
: Name of the Entity that should be generated. E.g. `User -
$domain
:Name of the Domain that everything should be created in. E.g.Authorization
-
$psr4Root
: The Name of the PSR-4 Root as defined by Composer. -
$i18n
: A array of i18n strings. The available keys are stored inside yaml files located atsrc/Resources/i18n
. This array should only be used for internal makers e.g. if you want to make a PR to this bundle. Please refer to the i18n section. -
$version
: The current date formatted asYYYY-MM-DD
. This is used to auto-generate PHP-doc comments -
$author
: The current git user formatted asUSERNAME <EMAIL>
orCode Generator <PROJECT NAME>
if the git user can not be read. -
$extra
: A array that can be used to provide any information that is needed.
NOTE: If you override getExtraVariables()
be sure to merge your array with the array of super()
to ensure that nothing breaks.