问题
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?
回答1:
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 the composer.json
{
"autoload": {
"psr-4": {
"Application\\": "src/Application/"
}
},
"require": {
"doctrine/orm": "^2.5"
}
}
All Application
module source code will be put on src/Application
not src/
anymore. So, when doctrine cli
create directory Application/Entity
in src
, it will match with yor psr-4
Autoloader.
来源:https://stackoverflow.com/questions/44504058/how-to-generate-doctrine-entities-from-database-and-use-psr-4-autoloading