skip to Main Content

I’m working on Symfony 6 PHP 8 project and i’m using gedmo doctrine extension .

I can’t find a full documentation about converting gedmo annotation to PHP 8 Attributes.

I’m tring to convert like this :

/**
 * @ORMColumn(type="string", length=255)
 * @GedmoSlug(fields={"title"})
 */
private $slug;

#[GedmoSlug(fields: title)]

but it doesn’t work !

How can i use gedmo with PHP 8 Attributes ?

2

Answers


  1. you’ll have to do the whole class property with attributes.
    the fields property at slug needs to be an array.

    #[GedmoMappingAnnotationSlug(fields: ['name'])]
    #[DoctrineORMMappingColumn(
        type: 'string',
        length: 255,     
    )]
    
    Login or Signup to reply.
  2. Rector supports this. The rule comes from rector-doctrine, which is included with the standard install method.

    Follow the rector install guide and edit the rector.php config to add the required rules.

    Rector also has rule sets for updating Symfony to see rector-symfony.

    Example of converting the Doctrine and Gedmo annotation to PHP 8 attributes.

    <?php
    
    declare(strict_types=1);
    
    use RectorConfigRectorConfig;
    use RectorDoctrineSetDoctrineSetList;
    
    return static function (RectorConfig $rectorConfig): void {
    
        $rectorConfig->sets([
            DoctrineSetList::DOCTRINE_CODE_QUALITY,
            DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
            DoctrineSetList::GEDMO_ANNOTATIONS_TO_ATTRIBUTES,
        
        ]);
    };
    

    e.g. converts this

    /**
     * @GedmoSlug(fields={"title"})
     * @ORMColumn(length=128, unique=true)
     */
    private $slug;
    

    to

    #[ORMColumn(length: 128, unique: true)]
    #[GedmoSlug(fields: ['title'])]
    private $slug;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search