MarijnKoesenCodeGeneratorBundle
The MarijnKoesenCodeGenerator bundle allows you to generate php code for classes., (*1)
This project is based upon the php-code-generator project
and relies on the Symfony2 framework. If you don't have
Symfony2 take a look at the php-code-generator project that you can install standalone., (*2)
Installation
Include the bundle using composer:, (*3)
"require-dev": {
"marijnkoesen/code-generator-bundle": "~0.1.0",
}
Then update your composer:, (*4)
$ composer update
Register the bundle in app_kernel.php, (*5)
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new MarijnKoesen\CodeGeneratorBundle\MarijnKoesenCodeGeneratorBundle();
}
Include the routes in routing_dev.yml:, (*6)
MarijnKoesenCodeGeneratorBundle:
resource: "@MarijnKoesenCodeGeneratorBundle/Resources/config/routing.yml"
prefix: /code-generator
Install the assets:, (*7)
$ ./app/console assets:install
Open your browser and go to the http://your-project/code-generator/ URL., (*8)
Configuration
You can add your own modules, or disable the default ones with the config., (*9)
For info on how to create your own modules, see below., (*10)
marijn_koesen_code_generator:
# Add your own custom modules
modules:
My\NameSpace\CodeGenerators\MyCustomGenerator: true
# Disable a default generator
defaultModules:
codegenerator\generator\MockGenerator: false
Extending the code generator
You can easily create your own code generator if you want to generate anything else
from your class definition., (*11)
You can extend the AbstractGenerator class, and easily create your own implementation., (*12)
See below for a sample Generator:, (*13)
<?php
namespace MyNamespace;
use codegenerator\model\ClassEntity;
use codegenerator\model\ClassMember;
class MyGenerator extends AbstractGenerator
{
public function generateCode(ClassEntity $class=null)
{
return 'class ' . $class->getName() . ' {}';
}
public function getName()
{
return 'Doctrine';
}
}
Then add it to your config_dev.yml:, (*14)
marijn_koesen_code_generator:
modules:
MyNamespace\MyGenerator: true
Credits
Developed and maintained by Marijn Koesen, (*15)
License
This bundle is released under the MIT license. See the complete license in the
bundle:, (*16)
Resources/meta/LICENSE