Skip to content
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

PHP 8+: Support for attributes #2235

Closed
makraz opened this issue Jun 21, 2021 · 9 comments
Closed

PHP 8+: Support for attributes #2235

makraz opened this issue Jun 21, 2021 · 9 comments

Comments

@makraz
Copy link

makraz commented Jun 21, 2021

What are your plans for PHP 8+?
Is there any WIP about mapping attributes so we could use #[ORM\Column] instead of /** @var ORM\Column */?
If not, I'll like to work on this.

@ndench
Copy link

ndench commented Jul 1, 2021

I'd love to see this. I currently can't migrate to #[ORM\Column] because the extensions won't detect the properties anymore. Let me know if there's anything I can do to help.

@fridde
Copy link

fridde commented Jul 6, 2021

@makraz You might want to edit your title to "PHP 8+: Support for attributes" since I initially thought you were missing some special attribute when in fact you wish for attributes to be supported at all.

Good initiative!

@makraz makraz changed the title PHP 8+: Support for an Attribute PHP 8+: Support for attributes Jul 6, 2021
@makraz
Copy link
Author

makraz commented Jul 6, 2021

Thanks @fridde for the feedback

@bpolaszek
Copy link

bpolaszek commented Aug 23, 2021

I'd love to see this. I currently can't migrate to #[ORM\Column] because the extensions won't detect the properties anymore. Let me know if there's anything I can do to help.

/**
 * @Gedmo\Timestampable(on="create")
 */
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
public \DateTimeImmutable $createdAt;

Not elegant, but works on my side.

@fridde
Copy link

fridde commented Aug 23, 2021

@bpolaszek Woah, for some reason I didn't realize that we could mix annotations and attributes. I thought that Gedmo would use the system I declared in doctrine.yaml with the setting for doctrine.orm.mappings.App.type (which I set to "attribute").

Thanks for pointing out this workaround. This will be useful during the transition.

@ndench
Copy link

ndench commented Sep 8, 2021

That's a good workaround @bpolaszek. Unfortunately it doesn't work for blameable because the BlameableListener uses doctrine annotations to determine if the property is an association.

if ($meta->hasAssociation($field)) {

@scroach
Copy link

scroach commented Oct 5, 2021

That's a good workaround @bpolaszek. Unfortunately it doesn't work for blameable because the BlameableListener uses doctrine annotations to determine if the property is an association.

if ($meta->hasAssociation($field)) {

Why shouldn't this work? The BlameableListener works on the ClassMetadata provided by doctrine so it should not matter how you mapped your fields.

Anyway I would definitely favor having attributes, I try to prevent mixing annotations and attributes.

@knojector
Copy link

knojector commented Nov 2, 2021

I'd love to see this. I currently can't migrate to #[ORM\Column] because the extensions won't detect the properties anymore. Let me know if there's anything I can do to help.

/**
 * @Gedmo\Timestampable(on="create")
 */
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
public \DateTimeImmutable $createdAt;

Not elegant, but works on my side.

Hi @bpolaszek,
I ran into the same issue but unfortunately the date fields are always populated with null. Do I need to adjust my doctrine.yml in order to mix attributes and annotations? This is my current mapping configuration:

mappings:
    App:
        type: attribute
        dir: '%kernel.project_dir%/src/Entity/'
        prefix: 'App\Entity\'

Edit:
Could figure it out... I switched from the stof/doctrine-extensions-bundle to this bundle and just missed to register the timestampable service manually in my services.yml.

gedmo.listener.timestampable:
    class: Gedmo\Timestampable\TimestampableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ "@annotation_reader" ] ]

robertfausk added a commit to knutschsoft/swapp that referenced this issue Nov 5, 2021
Workaround for TimestampableEntity and BlameableEntity can be removed after doctrine-extensions/DoctrineExtensions#2235 and related PRs are solved
@franmomu
Copy link
Collaborator

franmomu commented Dec 6, 2021

Support for ORM attribute mapping was added in 3.2, I'm closing this one in favor of #2363 where we can keep track of the needed work, any help is welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants