Setup the connection to an existing database through the environment variable:
DATABASE_URL="mysql://root:password@mysql-identity-api-v2/identity_api?serverVersion=8.2.1&charset=utf8mb4"
Currently doctrine import databases to:
But not to php 8.2 attributes.
So for this I will use rector to move the annotation to valid php attributes automatically.
php bin/console doctrine:mapping:import App\\Entity annotation --path=src/Entity
- Install Rector:
composer require --dev rector/rector
.
- Create a file called rector.php at the root of the project with the following contents:
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
return function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/tests',
]);
$rectorConfig->sets([
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
]);
};
- Run
vendor/bin/rector process src/Entity
, which obeys the above configuration.
- Uninstall Rector:
composer remove rector/rector && rm rector.php
php bin/console make:entity --regenerate --api-resource
Reverse engineering: Generate entities from database
Setup the connection to an existing database through the environment variable:
Currently doctrine import databases to:
But not to php 8.2 attributes.
So for this I will use rector to move the annotation to valid php attributes automatically.
Generate entities from database
php bin/console doctrine:mapping:import App\\Entity annotation --path=src/Entity
Convert annotations to attributes
composer require --dev rector/rector
.vendor/bin/rector process src/Entity
, which obeys the above configuration.composer remove rector/rector && rm rector.php
Generate getters and setters for the properties