Using Doctrine 2.5
with PSR-4 autoloading and converting an already designed database schema to entity classes (annotations). The problem is getting the exported files in the correct directory structure.
composer.json
{
"autoload": {
"psr-4": {
"Application\\": "src/"
}
},
"require": {
"doctrine/orm": "^2.5"
}
}
orm:convert-mapping
vendor/bin/doctrine orm:convert-mapping \
--namespace='Application\Entity\' \
--force \
--from-database \
annotation \
src/
Running this command will add an Application
directory in src/
.
The generated class file has the correct namespace but in the wrong directory for PSR-4 standard.
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity
*/
class User
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
}
Is there a way to solve this without a secondary command?
I don't see any option from
doctrine cli
for this needed. I just see the solution to modify the directory structure from your Application module. Here I modify thecomposer.json
All
Application
module source code will be put onsrc/Application
notsrc/
anymore. So, whendoctrine cli
create directoryApplication/Entity
insrc
, it will match with yorpsr-4
Autoloader.