From ef630a42e2750762d6242d601c0746f4cc2017d2 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Mon, 30 Oct 2023 14:36:55 +0200 Subject: [PATCH] Issue #413: Doctrine: replaced annotations with attributes. Signed-off-by: alexmerlin --- src/App/src/Common/TimestampAwareTrait.php | 10 ++--- src/App/src/Common/UuidAwareTrait.php | 10 ++--- src/Contact/src/ConfigProvider.php | 4 +- src/Contact/src/Entity/Message.php | 19 +++++---- src/User/src/ConfigProvider.php | 4 +- src/User/src/Entity/User.php | 45 ++++++++++------------ src/User/src/Entity/UserAvatar.php | 24 ++++-------- src/User/src/Entity/UserDetail.php | 24 ++++-------- src/User/src/Entity/UserIdentity.php | 17 ++------ src/User/src/Entity/UserRememberMe.php | 20 ++++------ src/User/src/Entity/UserResetPassword.php | 20 ++++------ src/User/src/Entity/UserRole.php | 11 +++--- 12 files changed, 83 insertions(+), 125 deletions(-) diff --git a/src/App/src/Common/TimestampAwareTrait.php b/src/App/src/Common/TimestampAwareTrait.php index 847ff687..53796dff 100644 --- a/src/App/src/Common/TimestampAwareTrait.php +++ b/src/App/src/Common/TimestampAwareTrait.php @@ -14,16 +14,14 @@ trait TimestampAwareTrait { private string $dateFormat = 'Y-m-d H:i:s'; - /** @ORM\Column(name="created", type="datetime_immutable") */ + #[ORM\Column(name: 'created', type: 'datetime_immutable')] protected ?DateTimeImmutable $created = null; - /** @ORM\Column(name="updated", type="datetime_immutable", nullable=true) */ + #[ORM\Column(name: 'updated', type: 'datetime_immutable', nullable: true)] protected ?DateTimeImmutable $updated = null; - /** - * @ORM\PrePersist() - * @ORM\PreUpdate() - */ + #[ORM\PrePersist] + #[ORM\PreUpdate] public function updateTimestamps(): void { $this->touch(); diff --git a/src/App/src/Common/UuidAwareTrait.php b/src/App/src/Common/UuidAwareTrait.php index f91c7a5b..8b1dec60 100644 --- a/src/App/src/Common/UuidAwareTrait.php +++ b/src/App/src/Common/UuidAwareTrait.php @@ -9,12 +9,10 @@ trait UuidAwareTrait { - /** - * @ORM\Id() - * @ORM\Column(name="uuid", type="uuid_binary_ordered_time", unique=true) - * @ORM\GeneratedValue(strategy="CUSTOM") - * @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidOrderedTimeGenerator") - */ + #[ORM\Id] + #[ORM\Column(name: 'uuid', type: 'uuid_binary_ordered_time', unique: true)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: \Ramsey\Uuid\Doctrine\UuidOrderedTimeGenerator::class)] protected ?UuidInterface $uuid = null; public function getUuid(): ?UuidInterface diff --git a/src/Contact/src/ConfigProvider.php b/src/Contact/src/ConfigProvider.php index b3b952a5..7f1492c9 100644 --- a/src/Contact/src/ConfigProvider.php +++ b/src/Contact/src/ConfigProvider.php @@ -4,7 +4,7 @@ namespace Frontend\Contact; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Dot\AnnotatedServices\Factory\AnnotatedRepositoryFactory; use Dot\AnnotatedServices\Factory\AnnotatedServiceFactory; use Frontend\Contact\Controller\ContactController; @@ -77,7 +77,7 @@ public function getDoctrineConfig(): array ], ], 'ContactEntities' => [ - 'class' => AnnotationDriver::class, + 'class' => AttributeDriver::class, 'cache' => 'array', 'paths' => [__DIR__ . '/Entity'], ], diff --git a/src/Contact/src/Entity/Message.php b/src/Contact/src/Entity/Message.php index 5357c5a6..7828929b 100644 --- a/src/Contact/src/Entity/Message.php +++ b/src/Contact/src/Entity/Message.php @@ -6,29 +6,28 @@ use Doctrine\ORM\Mapping as ORM; use Frontend\App\Common\AbstractEntity; +use Frontend\Contact\Repository\MessageRepository; -/** - * @ORM\Entity(repositoryClass="Frontend\Contact\Repository\MessageRepository") - * @ORM\Table(name="contact_message") - * @ORM\HasLifecycleCallbacks - */ +#[ORM\Entity(repositoryClass: MessageRepository::class)] +#[ORM\Table(name: 'contact_message')] +#[ORM\HasLifecycleCallbacks] class Message extends AbstractEntity { public const PLATFORM_WEBSITE = 'website'; - /** @ORM\Column(name="email", type="string", length=150) */ + #[ORM\Column(name: 'email', type: 'string', length: 150)] protected string $email = ''; - /** @ORM\Column(name="name", type="string", length=150) */ + #[ORM\Column(name: 'name', type: 'string', length: 150)] protected string $name = ''; - /** @ORM\Column(name="subject", type="text") */ + #[ORM\Column(name: 'subject', type: 'text')] protected string $subject = ''; - /** @ORM\Column(name="message", type="text") */ + #[ORM\Column(name: 'message', type: 'text')] protected string $message = ''; - /** @ORM\Column(name="platform", type="text") */ + #[ORM\Column(name: 'platform', type: 'text')] protected string $platform = ''; public function __construct( diff --git a/src/User/src/ConfigProvider.php b/src/User/src/ConfigProvider.php index 6a5290ff..047cb808 100644 --- a/src/User/src/ConfigProvider.php +++ b/src/User/src/ConfigProvider.php @@ -4,7 +4,7 @@ namespace Frontend\User; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Dot\AnnotatedServices\Factory\AnnotatedRepositoryFactory; use Dot\AnnotatedServices\Factory\AnnotatedServiceFactory; use Frontend\User\Adapter\AuthenticationAdapter; @@ -96,7 +96,7 @@ public function getDoctrineConfig(): array ], ], 'UserEntities' => [ - 'class' => AnnotationDriver::class, + 'class' => AttributeDriver::class, 'cache' => 'array', 'paths' => [__DIR__ . '/Entity'], ], diff --git a/src/User/src/Entity/User.php b/src/User/src/Entity/User.php index aca06ec5..b6564539 100644 --- a/src/User/src/Entity/User.php +++ b/src/User/src/Entity/User.php @@ -11,15 +11,14 @@ use Exception; use Frontend\App\Common\AbstractEntity; use Frontend\App\Common\UuidOrderedTimeGenerator; +use Frontend\User\Repository\UserRepository; use function bin2hex; use function random_bytes; -/** - * @ORM\Entity(repositoryClass="Frontend\User\Repository\UserRepository") - * @ORM\Table(name="user") - * @ORM\HasLifecycleCallbacks() - */ +#[ORM\Entity(repositoryClass: UserRepository::class)] +#[ORM\Table(name: 'user')] +#[ORM\HasLifecycleCallbacks] class User extends AbstractEntity implements UserInterface { public const STATUS_PENDING = 'pending'; @@ -37,41 +36,39 @@ class User extends AbstractEntity implements UserInterface self::IS_DELETED_NO, ]; - /** @ORM\OneToOne(targetEntity="Frontend\User\Entity\UserDetail", cascade={"persist", "remove"}, mappedBy="user") */ + #[ORM\OneToOne(mappedBy: 'user', targetEntity: UserDetail::class, cascade: ['persist', 'remove'])] protected UserDetail $detail; - /** @ORM\OneToOne(targetEntity="Frontend\User\Entity\UserAvatar", cascade={"persist", "remove"}, mappedBy="user") */ + #[ORM\OneToOne(mappedBy: 'user', targetEntity: UserAvatar::class, cascade: ['persist', 'remove'])] protected ?UserAvatar $avatar; - /** @ORM\Column(name="identity", type="string", length=191, nullable=false, unique=true) */ + #[ORM\Column(name: 'identity', type: 'string', length: 191, unique: true, nullable: false)] protected string $identity; - /** @ORM\Column(name="password", type="string", length=191, nullable=false) */ + #[ORM\Column(name: 'password', type: 'string', length: 191, nullable: false)] protected string $password; - /** @ORM\Column(name="status", type="string", length=20, columnDefinition="ENUM('pending', 'active')") */ + #[ORM\Column(name: 'status', type: 'string', length: 20, columnDefinition: "ENUM('pending', 'active')")] protected string $status = self::STATUS_PENDING; - /** @ORM\Column(name="isDeleted", type="boolean") */ + #[ORM\Column(name: 'isDeleted', type: 'boolean')] protected bool $isDeleted = self::IS_DELETED_NO; - /** @ORM\Column(name="hash", type="string", length=64, nullable=false, unique=true) */ + #[ORM\Column(name: 'hash', type: 'string', length: 64, unique: true, nullable: false)] protected string $hash; - /** - * @ORM\ManyToMany(targetEntity="Frontend\User\Entity\UserRole") - * @ORM\JoinTable( - * name="user_roles", - * joinColumns={@ORM\JoinColumn(name="userUuid", referencedColumnName="uuid")}, - * inverseJoinColumns={@ORM\JoinColumn(name="roleUuid", referencedColumnName="uuid")} - * ) - */ + #[ORM\ManyToMany(targetEntity: UserRole::class)] + #[ORM\JoinTable(name: 'user_roles')] + #[ORM\JoinColumn(name: 'userUuid', referencedColumnName: 'uuid')] + #[ORM\InverseJoinColumn(name: 'roleUuid', referencedColumnName: 'uuid')] protected Collection $roles; - /** - * @ORM\OneToMany(targetEntity="UserResetPassword", - * cascade={"persist", "remove"}, mappedBy="user", fetch="EXTRA_LAZY") - */ + #[ORM\OneToMany( + mappedBy: 'user', + targetEntity: UserResetPassword::class, + cascade: ['persist', 'remove'], + fetch: 'EXTRA_LAZY' + )] protected Collection $resetPasswords; /** diff --git a/src/User/src/Entity/UserAvatar.php b/src/User/src/Entity/UserAvatar.php index 29a748a1..e30cf1bf 100644 --- a/src/User/src/Entity/UserAvatar.php +++ b/src/User/src/Entity/UserAvatar.php @@ -7,31 +7,23 @@ use Doctrine\ORM\Mapping as ORM; use Frontend\App\Common\AbstractEntity; use Frontend\User\EventListener\UserAvatarEventListener; +use Frontend\User\Repository\UserAvatarRepository; -/** - * @ORM\Entity(repositoryClass="Frontend\User\Repository\UserAvatarRepository") - * @ORM\Table(name="user_avatar") - * @ORM\HasLifecycleCallbacks() - * @ORM\EntityListeners({UserAvatarEventListener::class}) - */ +#[ORM\Entity(repositoryClass: UserAvatarRepository::class)] +#[ORM\Table(name: 'user_avatar')] +#[ORM\HasLifecycleCallbacks] +#[ORM\EntityListeners([UserAvatarEventListener::class])] class UserAvatar extends AbstractEntity { - /** - * @ORM\OneToOne(targetEntity="Frontend\User\Entity\User", inversedBy="avatar") - * @ORM\JoinColumn(name="userUuid", referencedColumnName="uuid", nullable=false) - */ + #[ORM\OneToOne(inversedBy: 'avatar', targetEntity: User::class)] + #[ORM\JoinColumn(name: 'userUuid', referencedColumnName: 'uuid', nullable: false)] protected UserInterface $user; - /** @ORM\Column(name="name", type="string", length=191) */ + #[ORM\Column(name: 'name', type: 'string', length: 191)] protected string $name; protected string $url; - public function __construct() - { - parent::__construct(); - } - public function getUser(): UserInterface { return $this->user; diff --git a/src/User/src/Entity/UserDetail.php b/src/User/src/Entity/UserDetail.php index 1f0a0471..147aa0dd 100644 --- a/src/User/src/Entity/UserDetail.php +++ b/src/User/src/Entity/UserDetail.php @@ -6,31 +6,23 @@ use Doctrine\ORM\Mapping as ORM; use Frontend\App\Common\AbstractEntity; +use Frontend\User\Repository\UserDetailRepository; -/** - * @ORM\Entity(repositoryClass="Frontend\User\Repository\UserDetailRepository") - * @ORM\Table(name="user_detail") - * @ORM\HasLifecycleCallbacks() - */ +#[ORM\Entity(repositoryClass: UserDetailRepository::class)] +#[ORM\Table(name: 'user_detail')] +#[ORM\HasLifecycleCallbacks] class UserDetail extends AbstractEntity { - /** - * @ORM\OneToOne(targetEntity="Frontend\User\Entity\User", inversedBy="detail") - * @ORM\JoinColumn(name="userUuid", referencedColumnName="uuid", nullable=false) - */ + #[ORM\OneToOne(inversedBy: 'detail', targetEntity: User::class)] + #[ORM\JoinColumn(name: 'userUuid', referencedColumnName: 'uuid', nullable: false)] protected UserInterface $user; - /** @ORM\Column(name="firstName", type="string", length=191, nullable=true) */ + #[ORM\Column(name: 'firstName', type: 'string', length: 191, nullable: true)] protected string $firstName; - /** @ORM\Column(name="lastName", type="string", length=191, nullable=true) */ + #[ORM\Column(name: 'lastName', type: 'string', length: 191, nullable: true)] protected string $lastName; - public function __construct() - { - parent::__construct(); - } - public function getUser(): UserInterface { return $this->user; diff --git a/src/User/src/Entity/UserIdentity.php b/src/User/src/Entity/UserIdentity.php index c98e6829..3112937d 100644 --- a/src/User/src/Entity/UserIdentity.php +++ b/src/User/src/Entity/UserIdentity.php @@ -8,21 +8,12 @@ class UserIdentity implements UserInterface { - protected string $identity; - protected array $roles; - protected array $details; - protected string $uuid; - public function __construct( - string $uuid, - string $identity, - array $roles = [], - array $details = [] + protected string $uuid, + protected string $identity, + protected array $roles = [], + protected array $details = [] ) { - $this->uuid = $uuid; - $this->identity = $identity; - $this->roles = $roles; - $this->details = $details; } public function getUuid(): string diff --git a/src/User/src/Entity/UserRememberMe.php b/src/User/src/Entity/UserRememberMe.php index d6674d2e..3ddccf61 100644 --- a/src/User/src/Entity/UserRememberMe.php +++ b/src/User/src/Entity/UserRememberMe.php @@ -8,26 +8,22 @@ use Doctrine\ORM\Mapping as ORM; use Frontend\App\Common\AbstractEntity; -/** - * @ORM\Entity() - * @ORM\Table(name="user_remember_me") - * @ORM\HasLifecycleCallbacks() - */ +#[ORM\Entity] +#[ORM\Table(name: 'user_remember_me')] +#[ORM\HasLifecycleCallbacks] class UserRememberMe extends AbstractEntity { - /** - * @ORM\ManyToOne(targetEntity="Frontend\User\Entity\User") - * @ORM\JoinColumn(name="userUuid", referencedColumnName="uuid", nullable=false) - */ + #[ORM\ManyToOne(targetEntity: User::class)] + #[ORM\JoinColumn(name: 'userUuid', referencedColumnName: 'uuid', nullable: false)] protected User $user; - /** @ORM\Column(name="rememberMeToken", type="string", length=100, nullable=false, unique=true) */ + #[ORM\Column(name: 'rememberMeToken', type: 'string', length: 100, unique: true, nullable: false)] protected string $rememberMeToken = ''; - /** @ORM\Column(name="userAgent", type="text") */ + #[ORM\Column(name: 'userAgent', type: 'text')] protected ?string $userAgent = null; - /** @ORM\Column(name="expireDate", type="datetime_immutable") */ + #[ORM\Column(name: 'expireDate', type: 'datetime_immutable')] protected DateTimeImmutable $expireDate; public function getUser(): User diff --git a/src/User/src/Entity/UserResetPassword.php b/src/User/src/Entity/UserResetPassword.php index 410b266e..0e3f6c26 100644 --- a/src/User/src/Entity/UserResetPassword.php +++ b/src/User/src/Entity/UserResetPassword.php @@ -11,11 +11,9 @@ use Exception; use Frontend\App\Common\AbstractEntity; -/** - * @ORM\Entity() - * @ORM\Table(name="user_reset_password") - * @ORM\HasLifecycleCallbacks() - */ +#[ORM\Entity] +#[ORM\Table(name: 'user_reset_password')] +#[ORM\HasLifecycleCallbacks] class UserResetPassword extends AbstractEntity { public const STATUS_COMPLETED = 'completed'; @@ -25,19 +23,17 @@ class UserResetPassword extends AbstractEntity self::STATUS_REQUESTED, ]; - /** - * @ORM\ManyToOne(targetEntity="User", cascade={"persist", "remove"}, inversedBy="resetPasswords") - * @ORM\JoinColumn(name="userUuid", referencedColumnName="uuid", nullable=false) - */ + #[ORM\ManyToOne(targetEntity: User::class, cascade: ['persist', 'remove'], inversedBy: 'resetPasswords')] + #[ORM\JoinColumn(name: 'userUuid', referencedColumnName: 'uuid', nullable: false)] protected User $user; - /** @ORM\Column(name="expires", type="datetime_immutable", nullable=false) */ + #[ORM\Column(name: 'expires', type: 'datetime_immutable', nullable: false)] protected DateTimeImmutable $expires; - /** @ORM\Column(name="hash", type="string", length=64, nullable=false, unique=true) */ + #[ORM\Column(name: 'hash', type: 'string', length: 64, unique: true, nullable: false)] protected string $hash; - /** @ORM\Column(name="status", type="string", length=20, nullable=false) */ + #[ORM\Column(name: 'status', type: 'string', length: 20, nullable: false)] protected string $status = self::STATUS_REQUESTED; public function __construct() diff --git a/src/User/src/Entity/UserRole.php b/src/User/src/Entity/UserRole.php index 42f49848..4bf3dbe1 100644 --- a/src/User/src/Entity/UserRole.php +++ b/src/User/src/Entity/UserRole.php @@ -7,12 +7,11 @@ use Doctrine\ORM\Mapping as ORM; use Dot\Authorization\Role\RoleInterface; use Frontend\App\Common\AbstractEntity; +use Frontend\User\Repository\UserRoleRepository; -/** - * @ORM\Entity(repositoryClass="Frontend\User\Repository\UserRoleRepository") - * @ORM\Table(name="user_role") - * @ORM\HasLifecycleCallbacks() - */ +#[ORM\Entity(repositoryClass: UserRoleRepository::class)] +#[ORM\Table(name: 'user_role')] +#[ORM\HasLifecycleCallbacks] class UserRole extends AbstractEntity implements RoleInterface { public const ROLE_ADMIN = 'admin'; @@ -24,7 +23,7 @@ class UserRole extends AbstractEntity implements RoleInterface self::ROLE_GUEST, ]; - /** @ORM\Column(name="name", type="string", length=30, nullable=false, unique=true) */ + #[ORM\Column(name: 'name', type: 'string', length: 30, unique: true, nullable: false)] protected string $name; public function getName(): string