Skip to content

Commit 50ddf57

Browse files
authored
Add ORM PHP 8 attributes (#2251)
1 parent ea29f16 commit 50ddf57

File tree

14 files changed

+78
-6
lines changed

14 files changed

+78
-6
lines changed

doc/symfony4.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ doctrine:
5454
# only these lines are added additionally
5555
mappings:
5656
translatable:
57-
type: annotation
57+
type: annotation # or attribute
5858
alias: Gedmo
5959
prefix: Gedmo\Translatable\Entity
6060
# make sure vendor library location is correct
@@ -79,7 +79,7 @@ to you also. To skip mapping of these entities, you can map **only superclasses*
7979
```yaml
8080
mappings:
8181
translatable:
82-
type: annotation
82+
type: annotation # or attribute
8383
alias: Gedmo
8484
prefix: Gedmo\Translatable\Entity
8585
# make sure vendor library location is correct
@@ -106,18 +106,18 @@ orm:
106106
# only these lines are added additionally
107107
mappings:
108108
translatable:
109-
type: annotation
109+
type: annotation # or attribute
110110
alias: Gedmo
111111
prefix: Gedmo\Translatable\Entity
112112
# make sure vendor library location is correct
113113
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/src/Translatable/Entity"
114114
loggable:
115-
type: annotation
115+
type: annotation # or attribute
116116
alias: Gedmo
117117
prefix: Gedmo\Loggable\Entity
118118
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/src/Loggable/Entity"
119119
tree:
120-
type: annotation
120+
type: annotation # or attribute
121121
alias: Gedmo
122122
prefix: Gedmo\Tree\Entity
123123
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/src/Tree/Entity"
@@ -446,7 +446,7 @@ doctrine_mongodb:
446446
auto_mapping: true
447447
mappings:
448448
translatable:
449-
type: annotation
449+
type: annotation # or attribute
450450
alias: GedmoDocument
451451
prefix: Gedmo\Translatable\Document
452452
# make sure vendor library location is correct

src/Blameable/Traits/BlameableEntity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ trait BlameableEntity
1818
* @Gedmo\Blameable(on="create")
1919
* @ORM\Column(nullable=true)
2020
*/
21+
#[ORM\Column(nullable: true)]
2122
protected $createdBy;
2223

2324
/**
2425
* @var string
2526
* @Gedmo\Blameable(on="update")
2627
* @ORM\Column(nullable=true)
2728
*/
29+
#[ORM\Column(nullable: true)]
2830
protected $updatedBy;
2931

3032
/**

src/IpTraceable/Traits/IpTraceableEntity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ trait IpTraceableEntity
1818
* @Gedmo\IpTraceable(on="create")
1919
* @ORM\Column(length=45, nullable=true)
2020
*/
21+
#[ORM\Column(length: 45, nullable: true)]
2122
protected $createdFromIp;
2223

2324
/**
2425
* @var string
2526
* @Gedmo\IpTraceable(on="update")
2627
* @ORM\Column(length=45, nullable=true)
2728
*/
29+
#[ORM\Column(length: 45, nullable: true)]
2830
protected $updatedFromIp;
2931

3032
/**

src/Loggable/Entity/LogEntry.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Gedmo\Loggable\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
6+
use Gedmo\Loggable\Entity\Repository\LogEntryRepository;
67

78
/**
89
* Gedmo\Loggable\Entity\LogEntry
@@ -19,6 +20,12 @@
1920
* )
2021
* @ORM\Entity(repositoryClass="Gedmo\Loggable\Entity\Repository\LogEntryRepository")
2122
*/
23+
#[ORM\Entity(repositoryClass: LogEntryRepository::class)]
24+
#[ORM\Table(name: 'ext_log_entries', options: ['row_format' => 'DYNAMIC'])]
25+
#[ORM\Index(name: 'log_class_lookup_idx', columns: ['object_class'])]
26+
#[ORM\Index(name: 'log_date_lookup_idx', columns: ['logged_at'])]
27+
#[ORM\Index(name: 'log_user_lookup_idx', columns: ['username'])]
28+
#[ORM\Index(name: 'log_version_lookup_idx', columns: ['object_id', 'object_class', 'version'])]
2229
class LogEntry extends MappedSuperclass\AbstractLogEntry
2330
{
2431
/*

src/Loggable/Entity/MappedSuperclass/AbstractLogEntry.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace Gedmo\Loggable\Entity\MappedSuperclass;
44

5+
use Doctrine\DBAL\Types\Types;
56
use Doctrine\ORM\Mapping as ORM;
67

78
/**
89
* Gedmo\Loggable\Entity\AbstractLog
910
*
1011
* @ORM\MappedSuperclass
1112
*/
13+
#[ORM\MappedSuperclass]
1214
abstract class AbstractLogEntry
1315
{
1416
/**
@@ -18,55 +20,65 @@ abstract class AbstractLogEntry
1820
* @ORM\Id
1921
* @ORM\GeneratedValue
2022
*/
23+
#[ORM\Column(type: Types::INTEGER)]
24+
#[ORM\Id]
25+
#[ORM\GeneratedValue]
2126
protected $id;
2227

2328
/**
2429
* @var string
2530
*
2631
* @ORM\Column(type="string", length=8)
2732
*/
33+
#[ORM\Column(type: Types::STRING, length: 8)]
2834
protected $action;
2935

3036
/**
3137
* @var \DateTime
3238
*
3339
* @ORM\Column(name="logged_at", type="datetime")
3440
*/
41+
#[ORM\Column(name: 'logged_at', type: Types::DATETIME_MUTABLE)]
3542
protected $loggedAt;
3643

3744
/**
3845
* @var string
3946
*
4047
* @ORM\Column(name="object_id", length=64, nullable=true)
4148
*/
49+
#[ORM\Column(name: 'object_id', length: 64, nullable: true)]
4250
protected $objectId;
4351

4452
/**
4553
* @var string
4654
*
4755
* @ORM\Column(name="object_class", type="string", length=191)
4856
*/
57+
#[ORM\Column(name: 'object_class', type: Types::STRING, length: 191)]
4958
protected $objectClass;
5059

5160
/**
5261
* @var int
5362
*
5463
* @ORM\Column(type="integer")
5564
*/
65+
#[ORM\Column(type: Types::INTEGER)]
5666
protected $version;
5767

5868
/**
5969
* @var array
6070
*
6171
* @ORM\Column(type="array", nullable=true)
6272
*/
73+
#[ORM\Column(type: Types::ARRAY, nullable: true)]
6374
protected $data;
6475

6576
/**
6677
* @var string
6778
*
6879
* @ORM\Column(length=191, nullable=true)
6980
*/
81+
#[ORM\Column(length: 191, nullable: true)]
7082
protected $username;
7183

7284
/**

src/SoftDeleteable/Traits/SoftDeleteableEntity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Gedmo\SoftDeleteable\Traits;
44

55
use DateTime;
6+
use Doctrine\DBAL\Types\Types;
67
use Doctrine\ORM\Mapping as ORM;
78

89
/**
@@ -19,6 +20,7 @@ trait SoftDeleteableEntity
1920
*
2021
* @var DateTime|null
2122
*/
23+
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
2224
protected $deletedAt;
2325

2426
/**

src/Timestampable/Traits/TimestampableEntity.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Gedmo\Timestampable\Traits;
44

5+
use Doctrine\DBAL\Types\Types;
56
use Doctrine\ORM\Mapping as ORM;
67
use Gedmo\Mapping\Annotation as Gedmo;
78

@@ -18,13 +19,15 @@ trait TimestampableEntity
1819
* @Gedmo\Timestampable(on="create")
1920
* @ORM\Column(type="datetime")
2021
*/
22+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
2123
protected $createdAt;
2224

2325
/**
2426
* @var \DateTime
2527
* @Gedmo\Timestampable(on="update")
2628
* @ORM\Column(type="datetime")
2729
*/
30+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
2831
protected $updatedAt;
2932

3033
/**

src/Translatable/Entity/MappedSuperclass/AbstractPersonalTranslation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace Gedmo\Translatable\Entity\MappedSuperclass;
44

5+
use Doctrine\DBAL\Types\Types;
56
use Doctrine\ORM\Mapping as ORM;
67

78
/**
89
* Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation
910
*
1011
* @ORM\MappedSuperclass
1112
*/
13+
#[ORM\MappedSuperclass]
1214
abstract class AbstractPersonalTranslation
1315
{
1416
/**
@@ -18,20 +20,25 @@ abstract class AbstractPersonalTranslation
1820
* @ORM\Id
1921
* @ORM\GeneratedValue(strategy="IDENTITY")
2022
*/
23+
#[ORM\Column(type: Types::INTEGER)]
24+
#[ORM\Id]
25+
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
2126
protected $id;
2227

2328
/**
2429
* @var string
2530
*
2631
* @ORM\Column(type="string", length=8)
2732
*/
33+
#[ORM\Column(type: Types::STRING, length: 8)]
2834
protected $locale;
2935

3036
/**
3137
* @var string
3238
*
3339
* @ORM\Column(type="string", length=32)
3440
*/
41+
#[ORM\Column(type: Types::STRING, length: 32)]
3542
protected $field;
3643

3744
/**
@@ -47,6 +54,7 @@ abstract class AbstractPersonalTranslation
4754
*
4855
* @ORM\Column(type="text", nullable=true)
4956
*/
57+
#[ORM\Column(type: Types::TEXT, nullable: true)]
5058
protected $content;
5159

5260
/**

src/Translatable/Entity/MappedSuperclass/AbstractTranslation.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace Gedmo\Translatable\Entity\MappedSuperclass;
44

5+
use Doctrine\DBAL\Types\Types;
56
use Doctrine\ORM\Mapping as ORM;
67

78
/**
89
* Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation
910
*
1011
* @ORM\MappedSuperclass
1112
*/
13+
#[ORM\MappedSuperclass]
1214
abstract class AbstractTranslation
1315
{
1416
/**
@@ -18,41 +20,49 @@ abstract class AbstractTranslation
1820
* @ORM\Id
1921
* @ORM\GeneratedValue(strategy="IDENTITY")
2022
*/
23+
#[ORM\Column(type: Types::INTEGER)]
24+
#[ORM\Id]
25+
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
2126
protected $id;
2227

2328
/**
2429
* @var string
2530
*
2631
* @ORM\Column(type="string", length=8)
2732
*/
33+
#[ORM\Column(type: Types::STRING, length: 8)]
2834
protected $locale;
2935

3036
/**
3137
* @var string
3238
*
3339
* @ORM\Column(name="object_class", type="string", length=191)
3440
*/
41+
#[ORM\Column(name: 'object_class', type: Types::STRING, length: 191)]
3542
protected $objectClass;
3643

3744
/**
3845
* @var string
3946
*
4047
* @ORM\Column(type="string", length=32)
4148
*/
49+
#[ORM\Column(type: Types::STRING, length: 32)]
4250
protected $field;
4351

4452
/**
4553
* @var string
4654
*
4755
* @ORM\Column(name="foreign_key", type="string", length=64)
4856
*/
57+
#[ORM\Column(name: 'foreign_key', type: Types::STRING, length: 64)]
4958
protected $foreignKey;
5059

5160
/**
5261
* @var string
5362
*
5463
* @ORM\Column(type="text", nullable=true)
5564
*/
65+
#[ORM\Column(type: Types::TEXT, nullable: true)]
5666
protected $content;
5767

5868
/**

src/Translatable/Entity/Translation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\ORM\Mapping\Index;
77
use Doctrine\ORM\Mapping\Table;
88
use Doctrine\ORM\Mapping\UniqueConstraint;
9+
use Gedmo\Translatable\Entity\Repository\TranslationRepository;
910

1011
/**
1112
* Gedmo\Translatable\Entity\Translation
@@ -22,6 +23,10 @@
2223
* )
2324
* @Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
2425
*/
26+
#[Entity(repositoryClass: TranslationRepository::class)]
27+
#[Table(name: 'ext_translations', options: ['row_format' => 'DYNAMIC'])]
28+
#[Index(name: 'translations_lookup_idx', columns: ['locale', 'object_class', 'foreign_key'])]
29+
#[UniqueConstraint(name: 'lookup_unique_idx', columns: ['locale', 'object_class', 'field', 'foreign_key'])]
2530
class Translation extends MappedSuperclass\AbstractTranslation
2631
{
2732
/*

0 commit comments

Comments
 (0)