-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor YamlToAttributeDoctrineMappingRector to use attributes as more reliable #289
Conversation
87c9462
to
cc968b2
Compare
f6e964e
to
bf48021
Compare
Hi, should this update be included in a new repo version ? I am trying to migrate my old Doctrine YAML files to attributes (Symfony 6.3 project) without success, I have found no example or doc about this |
Hi, try We're still testing it, before putting to the docs. But you can figure out the configuration from |
OK, thanks. Using
|
You can use the rule itself and provide paths to load yaml mapping (maybe that could be automated too 🤔 ): return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withConfiguredRule(YamlToAttributeDoctrineMappingRector::class, [
__DIR__ . '/Resources/config/doctrine/',
]); |
Thanks. I tried this, but it does nothing :/
After executing, Rector displays "[OK] Rector is done!" but no file is modified and no progress bar is shown. What is wrong ? |
We'll need a reproducer repository, to see where the issue is. |
I have a Symfony (now 6.4) project, with code cut into "bundles". Here a example with one entity in one of my home-made-bundle. Properties are declarated in /config/doctrine/Alert/Alerte.orm.yml : App\Alert\Entity\Alerte:
type: entity
table: alerte_alerte
repositoryClass: App\Alert\Repository\AlerteRepository
fields:
id:
type: integer
id: true
generator:
strategy: IDENTITY The equivalent entity is defined with the other PHP code, in src/Alert/Entity/Alerte.php : namespace App\Alert\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Alerte
{
/**
* @var int
*/
private $id;
(...) getters/setters
} And Doctrine configuration, in config/packages/doctrine.yaml : doctrine:
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
validate_xml_mapping: true
auto_mapping: true
mappings:
Alert:
is_bundle: false
type: yml
dir: '%kernel.project_dir%/config/doctrine/Alert'
prefix: 'App\Alert\Entity'
My rector.php : declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Doctrine\CodeQuality\Rector\Class_\YamlToAttributeDoctrineMappingRector;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src/Alert/Entity/',
])
->withConfiguredRule(YamlToAttributeDoctrineMappingRector::class, [
__DIR__ . '/config/doctrine/Alert/',
])
; I have tried multiple times, with multiple folders, nothing happens :/ |
The old annotations required many extra checks, and were causing troubles on nested annotations.
Instead of doing this 2-step jump, we can use native attributes instead 👍
Upgrade to PHP 8.1, then use this rule to handle your yaml configs 💪