Skip to content

Commit a577901

Browse files
franmomuphansys
authored andcommitted
Support PHP8 attribute mapping for doctrine/mongodb-odm
1 parent 82f2327 commit a577901

File tree

27 files changed

+179
-33
lines changed

27 files changed

+179
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ a release.
2020

2121
## [Unreleased]
2222
### Added
23+
- PHP 8 Attributes support for Doctrine MongoDB to document & traits
2324
- Support for doctrine/dbal >=3.2
2425
- Timestampable: Support to use annotations as attributes on PHP >= 8.0.
2526

src/Blameable/Traits/BlameableDocument.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Gedmo\Blameable\Traits;
1111

1212
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
13+
use Doctrine\ODM\MongoDB\Types\Type;
1314
use Gedmo\Mapping\Annotation as Gedmo;
1415

1516
/**
@@ -24,13 +25,15 @@ trait BlameableDocument
2425
* @Gedmo\Blameable(on="create")
2526
* @ODM\Field(type="string")
2627
*/
28+
#[ODM\Field(type: Type::STRING)]
2729
protected $createdBy;
2830

2931
/**
3032
* @var string
3133
* @Gedmo\Blameable(on="update")
3234
* @ODM\Field(type="string")
3335
*/
36+
#[ODM\Field(type: Type::STRING)]
3437
protected $updatedBy;
3538

3639
/**

src/IpTraceable/Traits/IpTraceableDocument.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Gedmo\IpTraceable\Traits;
1111

1212
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
13+
use Doctrine\ODM\MongoDB\Types\Type;
1314
use Gedmo\Mapping\Annotation as Gedmo;
1415

1516
/**
@@ -24,13 +25,15 @@ trait IpTraceableDocument
2425
* @Gedmo\IpTraceable(on="create")
2526
* @ODM\Field(type="string")
2627
*/
28+
#[ODM\Field(type: Type::STRING)]
2729
protected $createdFromIp;
2830

2931
/**
3032
* @var string
3133
* @Gedmo\IpTraceable(on="update")
3234
* @ODM\Field(type="string")
3335
*/
36+
#[ODM\Field(type: Type::STRING)]
3437
protected $updatedFromIp;
3538

3639
/**

src/Loggable/Document/LogEntry.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Gedmo\Loggable\Document;
1111

1212
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoODM;
13+
use Gedmo\Loggable\Document\Repository\LogEntryRepository;
1314

1415
/**
1516
* Gedmo\Loggable\Document\LogEntry
@@ -24,6 +25,11 @@
2425
* }
2526
* )
2627
*/
28+
#[MongoODM\Document(repositoryClass: LogEntryRepository::class)]
29+
#[MongoODM\Index(keys: ['objectId' => 'asc', 'objectClass' => 'asc', 'version' => 'asc'])]
30+
#[MongoODM\Index(keys: ['loggedAt' => 'asc'])]
31+
#[MongoODM\Index(keys: ['objectClass' => 'asc'])]
32+
#[MongoODM\Index(keys: ['username' => 'asc'])]
2733
class LogEntry extends MappedSuperclass\AbstractLogEntry
2834
{
2935
/*

src/Loggable/Document/MappedSuperclass/AbstractLogEntry.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,78 @@
1010
namespace Gedmo\Loggable\Document\MappedSuperclass;
1111

1212
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoODM;
13+
use Doctrine\ODM\MongoDB\Types\Type;
1314

1415
/**
1516
* Gedmo\Loggable\Document\MappedSuperclass\AbstractLogEntry
1617
*
1718
* @MongoODM\MappedSuperclass
1819
*/
20+
#[MongoODM\MappedSuperclass]
1921
abstract class AbstractLogEntry
2022
{
2123
/**
2224
* @var int
2325
*
2426
* @MongoODM\Id
2527
*/
28+
#[MongoODM\Id]
2629
protected $id;
2730

2831
/**
2932
* @var string
3033
*
3134
* @MongoODM\Field(type="string")
3235
*/
36+
#[MongoODM\Field(type: Type::STRING)]
3337
protected $action;
3438

3539
/**
3640
* @var \DateTime
3741
*
3842
* @MongoODM\Field(type="date")
3943
*/
44+
#[MongoODM\Field(type: Type::DATE)]
4045
protected $loggedAt;
4146

4247
/**
4348
* @var string
4449
*
4550
* @MongoODM\Field(type="string", nullable=true)
4651
*/
52+
#[MongoODM\Field(type: Type::STRING, nullable: true)]
4753
protected $objectId;
4854

4955
/**
5056
* @var string
5157
*
5258
* @MongoODM\Field(type="string")
5359
*/
60+
#[MongoODM\Field(type: Type::STRING)]
5461
protected $objectClass;
5562

5663
/**
5764
* @var int
5865
*
5966
* @MongoODM\Field(type="int")
6067
*/
68+
#[MongoODM\Field(type: Type::INT)]
6169
protected $version;
6270

6371
/**
6472
* @var string
6573
*
6674
* @MongoODM\Field(type="hash", nullable=true)
6775
*/
76+
#[MongoODM\Field(type: Type::HASH, nullable: true)]
6877
protected $data;
6978

7079
/**
7180
* @var string
7281
*
7382
* @MongoODM\Field(type="string", nullable=true)
7483
*/
84+
#[MongoODM\Field(type: Type::STRING, nullable: true)]
7585
protected $username;
7686

7787
/**

src/SoftDeleteable/Traits/SoftDeleteableDocument.php

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

1212
use DateTime;
1313
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
14+
use Doctrine\ODM\MongoDB\Types\Type;
1415

1516
/**
1617
* A soft deletable trait you can apply to your MongoDB entities.
@@ -25,6 +26,7 @@ trait SoftDeleteableDocument
2526
*
2627
* @var DateTime|null
2728
*/
29+
#[ODM\Field(type: Type::DATE)]
2830
protected $deletedAt;
2931

3032
/**

src/Timestampable/Traits/TimestampableDocument.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Gedmo\Timestampable\Traits;
1111

1212
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
13+
use Doctrine\ODM\MongoDB\Types\Type;
1314
use Gedmo\Mapping\Annotation as Gedmo;
1415

1516
/**
@@ -24,13 +25,17 @@ trait TimestampableDocument
2425
* @Gedmo\Timestampable(on="create")
2526
* @ODM\Field(type="date")
2627
*/
28+
#[Gedmo\Timestampable(on: 'create')]
29+
#[ODM\Field(type: Type::DATE)]
2730
protected $createdAt;
2831

2932
/**
3033
* @var \DateTime
3134
* @Gedmo\Timestampable(on="update")
3235
* @ODM\Field(type="date")
3336
*/
37+
#[Gedmo\Timestampable(on: 'update')]
38+
#[ODM\Field(type: Type::DATE)]
3439
protected $updatedAt;
3540

3641
/**

src/Translatable/Document/MappedSuperclass/AbstractPersonalTranslation.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,30 @@
1010
namespace Gedmo\Translatable\Document\MappedSuperclass;
1111

1212
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoODM;
13+
use Doctrine\ODM\MongoDB\Types\Type;
1314

1415
/**
1516
* Gedmo\Translatable\Document\AbstractPersonalTranslation
1617
*
1718
* @MongoODM\MappedSuperclass
1819
*/
20+
#[MongoODM\MappedSuperclass]
1921
abstract class AbstractPersonalTranslation
2022
{
2123
/**
2224
* @var string|null
2325
*
2426
* @MongoODM\Id
2527
*/
28+
#[MongoODM\Id]
2629
protected $id;
2730

2831
/**
2932
* @var string
3033
*
3134
* @MongoODM\Field(type="string")
3235
*/
36+
#[MongoODM\Field(type: Type::STRING)]
3337
protected $locale;
3438

3539
/**
@@ -45,13 +49,15 @@ abstract class AbstractPersonalTranslation
4549
*
4650
* @MongoODM\Field(type="string")
4751
*/
52+
#[MongoODM\Field(type: Type::STRING)]
4853
protected $field;
4954

5055
/**
5156
* @var string
5257
*
5358
* @MongoODM\Field(type="string")
5459
*/
60+
#[MongoODM\Field(type: Type::STRING)]
5561
protected $content;
5662

5763
/**

src/Translatable/Document/MappedSuperclass/AbstractTranslation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,62 @@
1010
namespace Gedmo\Translatable\Document\MappedSuperclass;
1111

1212
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoODM;
13+
use Doctrine\ODM\MongoDB\Types\Type;
1314

1415
/**
1516
* Gedmo\Translatable\Document\MappedSuperclass\AbstractTranslation
1617
*
1718
* @MongoODM\MappedSuperclass
1819
*/
20+
#[MongoODM\MappedSuperclass]
1921
abstract class AbstractTranslation
2022
{
2123
/**
2224
* @var int
2325
*
2426
* @MongoODM\Id
2527
*/
28+
#[MongoODM\Id]
2629
protected $id;
2730

2831
/**
2932
* @var string
3033
*
3134
* @MongoODM\Field(type="string")
3235
*/
36+
#[MongoODM\Field(type: Type::STRING)]
3337
protected $locale;
3438

3539
/**
3640
* @var string
3741
*
3842
* @MongoODM\Field(type="string")
3943
*/
44+
#[MongoODM\Field(type: Type::STRING)]
4045
protected $objectClass;
4146

4247
/**
4348
* @var string
4449
*
4550
* @MongoODM\Field(type="string")
4651
*/
52+
#[MongoODM\Field(type: Type::STRING)]
4753
protected $field;
4854

4955
/**
5056
* @var string
5157
*
5258
* @MongoODM\Field(type="string", name="foreign_key")
5359
*/
60+
#[MongoODM\Field(name: 'foreign_key', type: Type::STRING)]
5461
protected $foreignKey;
5562

5663
/**
5764
* @var string
5865
*
5966
* @MongoODM\Field(type="string")
6067
*/
68+
#[MongoODM\Field(type: Type::STRING)]
6169
protected $content;
6270

6371
/**

src/Translatable/Document/Translation.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,28 @@
99

1010
namespace Gedmo\Translatable\Document;
1111

12-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
13-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Index;
14-
use Doctrine\ODM\MongoDB\Mapping\Annotations\UniqueIndex;
12+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
13+
use Gedmo\Translatable\Document\Repository\TranslationRepository;
1514

1615
/**
1716
* Gedmo\Translatable\Document\Translation
1817
*
19-
* @Document(repositoryClass="Gedmo\Translatable\Document\Repository\TranslationRepository")
20-
* @UniqueIndex(name="lookup_unique_idx", keys={
18+
* @ODM\Document(repositoryClass="Gedmo\Translatable\Document\Repository\TranslationRepository")
19+
* @ODM\UniqueIndex(name="lookup_unique_idx", keys={
2120
* "locale" = "asc",
2221
* "object_class" = "asc",
2322
* "foreign_key" = "asc",
2423
* "field" = "asc"
2524
* })
26-
* @Index(name="translations_lookup_idx", keys={
25+
* @ODM\Index(name="translations_lookup_idx", keys={
2726
* "locale" = "asc",
2827
* "object_class" = "asc",
2928
* "foreign_key" = "asc"
3029
* })
3130
*/
31+
#[ODM\Document(repositoryClass: TranslationRepository::class)]
32+
#[ODM\UniqueIndex(name: 'lookup_unique_idx', keys: ['locale' => 'asc', 'object_class' => 'asc', 'foreign_key' => 'asc', 'field' => 'asc'])]
33+
#[ODM\Index(name: 'translations_lookup_idx', keys: ['locale' => 'asc', 'object_class' => 'asc', 'foreign_key' => 'asc'])]
3234
class Translation extends MappedSuperclass\AbstractTranslation
3335
{
3436
/*

0 commit comments

Comments
 (0)