mbi / code-generator-bundle
This Bundle provides a generator for entity-subpackage
Requires
- php: ^7.1
- doctrine/orm: ^2.5
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: ^7.0
- psr/log: ^1.0
- sensio/framework-extra-bundle: ^3.0.13|^4.0|^5.0
- slevomat/coding-standard: ^4.7|^5.0|^6.1
- squizlabs/php_codesniffer: ^3.5
- symfony/asset: ^3.4|^4.3
- symfony/config: ^3.4|^4.0
- symfony/console: ^3.4|^4.0
- symfony/debug: ^3.4|^4.0
- symfony/dependency-injection: ^3.4|^4.0
- symfony/event-dispatcher: ^3.4|^4.0
- symfony/finder: ^3.4|^4.0
- symfony/framework-bundle: ^3.4|^4.0
- symfony/http-foundation: ^3.4|^4.0
- symfony/http-kernel: ^3.4|^4.0
- symfony/phpunit-bridge: ^4.1
- symfony/twig-bundle: ^2.8|^3.0|^4.0
- symfony/validator: ^3.4|^4.3
- symfony/yaml: ^3.4|^4.0
- twig/twig: ^2.0
This package is auto-updated.
Last update: 2024-04-29 04:27:11 UTC
README
A Symfony Bundle to create subpackages for your library. With entity (doctrine) + data-object, factory, repository and integrating service. More blueprints and stacks may follow.
Install
Require composer-package:
composer require --dev mbi/code-generator-bundle:dev-master
Register bundle in your bundles.php
:
return [
...
\Mbi\CodeGeneratorBundle\MbiCodeGeneratorBundle::class => ['dev' => true, 'test' => true],
...
];
Add to config (if you want):
mbi_code_generator:
default_class_annotations:
author: "AUTHOR NAME"
license: "LICENSE"
Create subpackage with command
php bin/console --env=test mbi:cgb:generate:package
Enter name for Entity (like Blog): Blog
Enter namespace for Subpackage (like Mbi\Application\Content\Blog): Mbi\Application\Content\Blog
Enter relative path for Subpackage (will be appended: e.g. kernel-project-dir + src/Application/Content):src/Application/Content
Create entity-property? (Y|n)Y
Enter property-name: name
Enter property-type (string,bool,int,datetime,float):
[0] string
[1] bool
[2] int
[3] datetime
[4] float
> 0
type-option nullable [/^(0|1)$/]: 0
type-option length [/^[0-9]+$/]: 255
Create entity-property? (Y|n)
Enter property-name: created
Enter property-type (string,bool,int,datetime,float):
[0] string
[1] bool
[2] int
[3] datetime
[4] float
> 3
type-option nullable [/^(0|1)$/]: 0
Create entity-property? (Y|n)n
5 classes generated
- Mbi\Application\Content\Blog\Entity\Blog
- Mbi\Application\Content\Blog\Form\BlogData
- Mbi\Application\Content\Blog\BlogFactory
- Mbi\Application\Content\Blog\BlogRepository
- Mbi\Application\Content\Blog\BlogService
Want more?
You may try to create and process your own blueprints, feel free:
Extend Mbi\CodeGeneratorBundle\Library\Blueprint\AbstractBlueprint
and use class-builder to template a class:
$this->classBuilder = $this->classBuilderFactory->createBuilder();
$this->classBuilder->initClassTemplate(
$baseClassName,
$path,
$namespace,
$parentClass
);
$this->classBuilder->useTrait(TRAIT::class);
$this->classBuilder->implementInterface(INTERFACE::class);
$property = $this->getClassBuilder()->addPropertyByInstruction(
PropertyInstruction::create('PROPERTY_NAME', DataType::INTEGER, true, false, false, true),
[
DoctrineAnnotationInstruction::createByClass(Id::class),
DoctrineAnnotationInstruction::createByClass(GeneratedValue::class, ['strategy' => 'AUTO']),
]
);
$this->getClassBuilder()->createMethod(
'METHOD_NAME',
[BaseAnnotationInstruction::createByIdentAndValue(AnnotationTemplate::IDENT_RETURN,'entity')],
[],
function () use ($entityClassName) {
return 'return new '.$entityClassName.'();';
},
MethodTemplate::VISIBILITY_PROTECTED
);
Have a look into the available blueprints (Mbi\CodeGeneratorBundle\Blueprint
) to get a clue how it works and what is possible.
Use Mbi\CodeGeneratorBundle\Library\Blueprint\BlueprintProcessor
to generate and persist class-template:
$generatedTemplate = $this->get('mbi_code_generator.blueprint_processor')->generate(
SomeBlueprint::class,
'NewEntity',
'/path/to/namespace',
'Package/Namespace',
BlueprintSettings::create(),
TemplateStack::create()
);