I have clean project ZendSkeletonApplication with integrated Doctrine 2 module “doctrine-orm-module” etc via Composer. Doctrine CLI works from vendor/bin.
I have ‘Application’ and ‘Blog’ module, my module config:
<?php
namespace Blog;
return array(
'router' => array(
'routes' => array(
'post' => array(
'type' => 'segment',
'options' => array(
'route' => '/post[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Blog\Controller\Post',
'action' => 'index',
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'Blog\Controller\Post' => 'Blog\Controller\PostController'
),
),
'view_manager' => array(
'template_path_stack' => array(
'blog' => __DIR__ . '/../view',
),
),
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
)
)
);
How to generate Entities from YAML files each module and how to config my modules arrays to use YAML? For example I have my all .yml files in ZendSkeletonApplication/mapping/yml and few .yml files have definitions of Blog module entities and few have definitions of Application module entities.
My entities are in Blog/src/Blog/Entity folder for blog module. All I want its just by one call in Doctrine CLI generate-entities create all Entities each module from all .yml files which are placed in mapping/yml folder? Is it possible? Can anybody provide simple example with doctrine config?
The following approach quick and dirty approach works for me:
Add the following lines to …vendor\doctrine\doctrine-module\bin\doctrine-module.php:
Now you can this doctrine-module.php on command line interface to call
Be careful with namespaces. The YAML driver expects namespace.entity.dcm.yml to be the the name of the \Namespace\Entity YAML file. The Tool will create PATH_TO_YOUR_ENTITY_CLASSES\Namespace\Entity.php for you.
If you want to use this approach more regularly it might be cleaner to extend Doctrine\ORM\Tools\Console\CommandGenerateEntitiesCommand along these lines and add a new command to the cli.