Skip to content

Commit

Permalink
DISPLAY-1030: Switch from doctrine annotations to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
turegjorup committed Nov 24, 2023
1 parent 90646e4 commit 2a6ecb7
Show file tree
Hide file tree
Showing 32 changed files with 169 additions and 532 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

- [#174](https://github.com/os2display/display-api-service/pull/174)
Update composer dependencies, Enforce strict types
- Update composer dependencies
- Update `symfony/flex` 1.x -> 2.x
- Update `vich/uploader-bundle` 1.x -> 2.x
- Update `debril/feed-io 5.x -> 6.x
- Enforce strict types
- Switch from doctrine annotations to attributes
- [#173](https://github.com/os2display/display-api-service/pull/173)
Upgraded to API Platform 3
- [#172](https://github.com/os2display/display-api-service/pull/172)
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"api-platform/core": "^3.1",
"composer/package-versions-deprecated": "^1.11",
"debril/feed-io": "^6.0",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^2.9",
Expand Down
78 changes: 1 addition & 77 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ doctrine:
mappings:
App:
is_bundle: false
type: annotation
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
// DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
// DoctrineSetList::DOCTRINE_DBAL_30,
// DoctrineSetList::DOCTRINE_ORM_214,
// DoctrineSetList::DOCTRINE_CODE_QUALITY,
Expand Down
47 changes: 13 additions & 34 deletions src/Entity/AbstractBaseEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,27 @@
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Component\Uid\Ulid;

/**
* @ORM\MappedSuperclass
*
* @ORM\HasLifecycleCallbacks
*/
#[ORM\MappedSuperclass]
#[ORM\HasLifecycleCallbacks]
abstract class AbstractBaseEntity implements BlameableInterface
{
/**
* @ORM\Id
*
* @ORM\Column(type="ulid", unique=true)
*
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class=UlidGenerator::class)
*/
#[ApiProperty(identifier: true)]
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private ?Ulid $id = null;

/**
* @ORM\Column(type="datetime_immutable", nullable=false)
*/
#[ORM\Column(type: 'datetime_immutable', nullable: false)]
private \DateTimeImmutable $createdAt;

/**
* @ORM\Column(type="datetime_immutable", nullable=false)
*/
#[ORM\Column(type: 'datetime_immutable', nullable: false)]
private \DateTimeImmutable $modifiedAt;

/**
* @ORM\Column(type="string", nullable=false, options={"default":""})
*/
#[ORM\Column(type: 'string', nullable: false, options: ['default' => ''])]
private string $createdBy = '';

/**
* @ORM\Column(type="string", nullable=false, options={"default":""})
*/
#[ORM\Column(type: 'string', nullable: false, options: ['default' => ''])]
private string $modifiedBy = '';

/**
Expand Down Expand Up @@ -74,10 +58,8 @@ public function getCreatedAt(): \DateTimeInterface
return $this->createdAt;
}

/**
* @ORM\PrePersist()
*/
#[Ignore]
#[ORM\PrePersist]
public function setCreatedAt(): self
{
$this->createdAt = isset($this->id) ? $this->id->getDateTime() : new \DateTimeImmutable();
Expand All @@ -90,12 +72,9 @@ public function getModifiedAt(): \DateTimeInterface
return $this->modifiedAt;
}

/**
* @ORM\PrePersist()
*
* @ORM\PreUpdate()
*/
#[Ignore]
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function setModifiedAt(): self
{
$this->modifiedAt = new \DateTimeImmutable();
Expand Down
8 changes: 3 additions & 5 deletions src/Entity/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;

/**
* @ORM\Entity
*
* @ORM\Table("refresh_tokens")
*/

#[ORM\Table('refresh_tokens')]
#[ORM\Entity]
class RefreshToken extends BaseRefreshToken
{
}
23 changes: 6 additions & 17 deletions src/Entity/ScreenLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,24 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass=ScreenLayoutRepository::class)
*
* @ORM\EntityListeners({"App\EventListener\ScreenLayoutDoctrineEventListener"})
*/
#[ORM\Entity(repositoryClass: ScreenLayoutRepository::class)]
#[ORM\EntityListeners([\App\EventListener\ScreenLayoutDoctrineEventListener::class])]
class ScreenLayout extends AbstractBaseEntity implements MultiTenantInterface
{
use MultiTenantTrait;

use EntityTitleDescriptionTrait;

/**
* @ORM\Column(type="integer", nullable=false, options={"default": 0})
*/
#[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])]
private int $gridRows = 0;

/**
* @ORM\Column(type="integer", nullable=false, options={"default": 0})
*/
#[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])]
private int $gridColumns = 0;

/**
* @ORM\OneToMany(targetEntity=Screen::class, mappedBy="screenLayout")
*/
#[ORM\OneToMany(targetEntity: Screen::class, mappedBy: 'screenLayout')]
private Collection $screens;

/**
* @ORM\OneToMany(targetEntity=ScreenLayoutRegions::class, mappedBy="screenLayout")
*/
#[ORM\OneToMany(targetEntity: ScreenLayoutRegions::class, mappedBy: 'screenLayout')]
private Collection $regions;

public function __construct()
Expand Down
24 changes: 7 additions & 17 deletions src/Entity/ScreenLayoutRegions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,34 @@
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
* @ORM\Entity(repositoryClass=ScreenLayoutRegionsRepository::class)
*
* @ORM\EntityListeners({"App\EventListener\ScreenLayoutRegionsDoctrineEventListener"})
*/
#[ORM\Entity(repositoryClass: ScreenLayoutRegionsRepository::class)]
#[ORM\EntityListeners([\App\EventListener\ScreenLayoutRegionsDoctrineEventListener::class])]
class ScreenLayoutRegions extends AbstractBaseEntity implements MultiTenantInterface
{
use MultiTenantTrait;

/**
* @ORM\Column(type="string", length=255, nullable=false, options={"default" : ""})
*
* @Groups({"read"})
*/
#[ORM\Column(type: 'string', length: 255, nullable: false, options: ['default' => ''])]
private string $title = '';

/**
* @ORM\Column(type="array", nullable=false)
*
* @Groups({"read"})
*/
#[ORM\Column(type: 'array', nullable: false)]
private array $gridArea = [];

/**
* @ORM\OneToMany(targetEntity=PlaylistScreenRegion::class, mappedBy="region", orphanRemoval=true)
*/
#[ORM\OneToMany(targetEntity: PlaylistScreenRegion::class, mappedBy: 'region', orphanRemoval: true)]
private Collection $playlistScreenRegions;

/**
* @ORM\ManyToOne(targetEntity=ScreenLayout::class, inversedBy="regions")
*/
#[ORM\ManyToOne(targetEntity: ScreenLayout::class, inversedBy: 'regions')]
private ?ScreenLayout $screenLayout = null;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Groups({"read"})
*/
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $type = null;

public function __construct()
Expand Down
16 changes: 4 additions & 12 deletions src/Entity/ScreenUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/**
* @ORM\Entity(repositoryClass=ScreenUserRepository::class)
*/
#[ORM\Entity(repositoryClass: ScreenUserRepository::class)]
class ScreenUser extends AbstractTenantScopedEntity implements UserInterface, TenantScopedUserInterface
{
final public const ROLE_SCREEN = 'ROLE_SCREEN';

/**
* @ORM\Column(type="string", length=180, unique=true)
*/
#[ORM\Column(type: 'string', length: 180, unique: true)]
private string $username;

/**
* @ORM\Column(type="json")
*/
#[ORM\Column(type: 'json')]
private array $roles = [];

/**
* @ORM\OneToOne(targetEntity=Screen::class, inversedBy="screenUser")
*/
#[ORM\OneToOne(targetEntity: Screen::class, inversedBy: 'screenUser')]
private Screen $screen;

/**
Expand Down
19 changes: 5 additions & 14 deletions src/Entity/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,21 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass=TemplateRepository::class)
*
* @ORM\EntityListeners({"App\EventListener\TemplateDoctrineEventListener"})
*/
#[ORM\Entity(repositoryClass: TemplateRepository::class)]
#[ORM\EntityListeners([\App\EventListener\TemplateDoctrineEventListener::class])]
class Template extends AbstractBaseEntity implements MultiTenantInterface
{
use MultiTenantTrait;

use EntityTitleDescriptionTrait;

/**
* @ORM\Column(type="string", length=255, nullable=false, options={"default" : ""})
*/
#[ORM\Column(type: 'string', length: 255, nullable: false, options: ['default' => ''])]
private string $icon = '';

/**
* @ORM\Column(type="array")
*/
#[ORM\Column(type: 'array')]
private array $resources = [];

/**
* @ORM\OneToMany(targetEntity=Slide::class, mappedBy="template")
*/
#[ORM\OneToMany(targetEntity: Slide::class, mappedBy: 'template')]
private Collection $slides;

public function __construct()
Expand Down
Loading

0 comments on commit 2a6ecb7

Please sign in to comment.