I'm trying to set up Doctrine 2.6 in a simple REST API application using MySQL. I'm also new to Doctrine or ORM altogether, but not new to PHP.
Everything works fine out of the box, I start with a simple User
class which sits in
entities/User.php
<?php
namespace MyApp\Entities;
/**
* @Entity
* @Table(name="user")
*/
class User
{
/**
* @Id
* @GeneratedValue
* @Column(type="smallint")
*/
private $id;
}
// Setup Doctrine
$configuration = Setup::createAnnotationMetadataConfiguration(
$paths = [__DIR__ . '/entities'],
$isDevMode = true
);
To generate getters and setters, I run
php vendor/bin/doctrine orm:generate-entities ./entities/
...which generates classes as I'd expect, but they end up in entities/MyApp/Entities/User.php
.
Now I'm not sure if I should want the command to update the original file (entities/User.php
) which adds getters and setters to it and keeps annotations, or if it's preferred to keep the "source" file intact and generate a separate file to use in the application. The latter doesn't preserve the annotations and only contains phpdoc annotations.
Either way, I'd like to keep the generated file outside of the MyApp/Entities/
subfolder, either keeping it in entities/User.php
or something like generated_entities/User.php
(and use composer's autoloader to load them in the proper namespace), but the orm:generate-entities
always outputs the file deeply nested. Is there way to configure the command or doctrine to avoid it?