mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Add documentation on how to use PHP attributes #6830
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @andreas-aeschlimann on GitHub (Sep 17, 2021).
Being new to Doctrine, I followed the guides and successfully integrated Doctrine into our project. As suggested in the docs, we used PHPDoc Annotation Metadata as follows:
As PHP 8 is out now for a while, I decided that I would like to switch to PHP Attributes instead such that we may use:
After doing that, it did not work out of the box as inferred on the website – all PHP Attributes were completely ignored. I also did not find any information on how to make it properly work. Only after adding
$config->setMetadataDriverImpl(new AttributeDriver([]));to theEntityManagerconfig, PHP Attributes seemed to work.I do not know if this is the correct way to enable attributes, but it would be nice if it were documented on the website.
@derrabus commented on GitHub (Sep 18, 2021):
Do you want to submit a pull request with the documentation that would've helped you?
@andreas-aeschlimann commented on GitHub (Sep 21, 2021):
I could do that, but I am probably not "good" enough yet to write about best practices in Doctrine. Did I even enable attributes in the appropriate way? Or are there other, maybe better ways?
@derrabus commented on GitHub (Sep 22, 2021):
No worries, you're not alone in this. Someone will review your PR.
Yes. 🙂
@ThomasLandauer commented on GitHub (Oct 30, 2021):
I'm currently overhauling the "Events" page, and I could add some attributes examples. But before, somebody needs to configure the RST parser to allow a new type of
.. code-block::(If you tell me in which file this is happening, I could even try myself.)
It's probably best to follow what Symfony did, see e.g. https://symfony.com/doc/current/doctrine/associations.html#mapping-the-manytoone-relationship
Four tabs above the code block:
Annotations | Attributes | YAML | XML
(I personally would even list Attributes (=future) first, and YAML (=past) last, but that's not so important right now)
Symfony's RST syntax:
Doctrine's:
Is there a way to setup
.. code-block:: phpas alias for the (new).. code-block:: php-annotations? Or do some automatic search and replace throughout the entire docs?@SenseException commented on GitHub (Oct 30, 2021):
There's an
attributehighlighter that's a copy of the PHP one... code-block:: attributeshould work.https://github.com/doctrine/doctrine-website/pull/409
@ThomasLandauer commented on GitHub (Oct 30, 2021):
Oddly enough, I have a faint memory that I've already used this - but can't find any PR ;-) Never mind.
attributetophp-attributes, for consistency with Symfony? Since there are not many usages of this in Doctrine's documentation yet (couldn't find a single one), it's either now or never ;-)