Full support for Doctrine including entity classes and migrations is supported if that's your preferred way of managing the database. Below explains all you need to know in order to utilize Doctrine within Apex.


To use Doctrine during a request, you must run the App::bootDoctrine method, which returns an instance of Doctrine's EntityManager class. For example, when you need a copy of EntityManager simply run:

$manager = $app->bootDoctrine();

Entity Directories

If you create all entity classes via the apex CLI tool (see below), then when Doctrine is booted the EntityManager will be instantiated with all necessry entity directories with no additional work required on your end.

If you notice the EntityManager not being created with the necessary directories, simply run the command:

apex scan-classes

The above command will go through all files within the /src/ directory and compile a list of all entity directories among other things. This will resolve the issue of missing entity directories.

Entity Classes

Assuming you already have your SQL database tables created, you can easily generate Doctrine entiy classes for them by simply including the --doctrine flag within the CLI command, for example:

apex opus model MyPackage/Models/Order --dbtable orders --doctrine

With the --doctrine flag present, a DOctrine entity class will be generated instead of an Apex model class. As per-usual, it will also take into account column type, primary key, unique, nullable, forieng key constraints, et al.


Much the same as models, you can also create Doctrine migrations by simply includng the --doctring flag within the standard CLI command, for example:

apex migration create demo --doctrine