Skip to content

Commit

Permalink
feat!: Removed JMS Serializer annotation, AbstractAjaxController requ…
Browse files Browse the repository at this point in the history
…ires a Symfony Serializer interface
  • Loading branch information
roadiz-ci committed Dec 2, 2024
1 parent 760c030 commit 297df80
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 196 deletions.
14 changes: 4 additions & 10 deletions src/Entity/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ class Folder extends AbstractDateTimedPositioned implements FolderInterface, Lea
/** @phpstan-ignore-next-line */
protected Collection $documents;

/**
* @Serializer\Groups({"folder", "folder_color"})
*
* @Serializer\Type("string")
*/
#[ORM\Column(
name: 'color',
type: 'string',
Expand All @@ -99,6 +94,8 @@ class Folder extends AbstractDateTimedPositioned implements FolderInterface, Lea
)]
#[Assert\Length(max: 7)]
#[SymfonySerializer\Groups(['folder', 'folder_color'])]
#[Serializer\Groups(['folder', 'folder_color'])]
#[Serializer\Type('string')]
protected string $color = '#000000';

#[ApiFilter(BaseFilter\SearchFilter::class, strategy: 'partial')]
Expand Down Expand Up @@ -219,12 +216,9 @@ public function getTranslatedFoldersByDefaultTranslation(): ?FolderTranslation
});
}

/**
* @Serializer\VirtualProperty
*
* @Serializer\Groups({"folder", "document_folders"})
*/
#[SymfonySerializer\Groups(['folder', 'document_folders'])]
#[Serializer\Groups(['folder', 'document_folders'])]
#[Serializer\VirtualProperty]
public function getName(): ?string
{
return $this->getTranslatedFolders()->first() ?
Expand Down
7 changes: 2 additions & 5 deletions src/Entity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ class Group extends AbstractEntity
#[Serializer\Type("ArrayCollection<RZ\Roadiz\CoreBundle\Entity\Role>")]
private Collection $roleEntities;

/**
* @Serializer\Groups({"group", "user"})
*
* @Serializer\Type("array<string>")
*/
#[SymfonySerializer\Groups(['group', 'user'])]
#[Serializer\Groups(['group', 'user'])]
#[Serializer\Type('array<string>')]
private ?array $roles = null;

public function __construct()
Expand Down
25 changes: 8 additions & 17 deletions src/Entity/NodesSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,11 @@ public function setNoIndex(bool $noIndex): NodesSources
return $this;
}

/**
* @Serializer\VirtualProperty
*
* @Serializer\SerializedName("slug")
*
* @Serializer\Groups({"nodes_sources", "nodes_sources_base"})
*/
#[SymfonySerializer\SerializedName('slug')]
#[SymfonySerializer\Groups(['nodes_sources', 'nodes_sources_base'])]
#[Serializer\SerializedName('slug')]
#[Serializer\VirtualProperty]
#[Serializer\Groups(['nodes_sources', 'nodes_sources_base'])]
public function getIdentifier(): string
{
$urlAlias = $this->getUrlAliases()->first();
Expand All @@ -484,11 +480,10 @@ public function getUrlAliases(): Collection
}

/**
* Get parent node’ source based on the same translation.
*
* @Serializer\Exclude
* Get parent node source based on the same translation.
*/
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
public function getParent(): ?NodesSources
{
/** @var Node|null $parent */
Expand Down Expand Up @@ -538,15 +533,11 @@ public function setTranslation(TranslationInterface $translation): NodesSources
return $this;
}

/**
* @Serializer\VirtualProperty
*
* @Serializer\Groups({"nodes_sources", "nodes_sources_default"})
*
* @Serializer\SerializedName("@type")
*/
#[SymfonySerializer\Groups(['nodes_sources', 'nodes_sources_default'])]
#[SymfonySerializer\SerializedName('@type')]
#[Serializer\Groups(['nodes_sources', 'nodes_sources_default'])]
#[Serializer\SerializedName('@type')]
#[Serializer\VirtualProperty]
public function getNodeTypeName(): string
{
return 'NodesSources';
Expand Down
4 changes: 1 addition & 3 deletions src/Entity/Realm.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ class Realm extends AbstractEntity implements RealmInterface
#[Assert\Regex('#^[\w\s]+$#u')]
private string $name = '';

/**
* @Serializer\Exclude()
*/
#[ORM\Column(name: 'plain_password', type: 'string', length: 255, unique: false, nullable: true)]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
#[Assert\Length(max: 255)]
private ?string $plainPassword = null;

Expand Down
3 changes: 1 addition & 2 deletions src/Entity/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ public function removeGroup(Group $group): Role
* Get a classified version of current role name.
*
* It replaces underscores by dashes and lowercase.
*
* @Serializer\Groups({"role"})
*/
#[SymfonySerializer\Groups(['role'])]
#[Serializer\Groups(['role'])]
public function getClassName(): string
{
return str_replace('_', '-', \mb_strtolower($this->getRole()));
Expand Down
30 changes: 9 additions & 21 deletions src/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,10 @@ public function __toString(): string
return (string) $this->getId();
}

/**
* @Serializer\Groups({"tag", "tag_base", "node", "nodes_sources"})
*
* @Serializer\VirtualProperty
*
* @Serializer\Type("string|null")
*/
#[SymfonySerializer\Ignore]
#[Serializer\Groups(['tag', 'tag_base', 'node', 'nodes_sources'])]
#[Serializer\VirtualProperty]
#[Serializer\Type('string|null')]
public function getName(): ?string
{
return $this->getTranslatedTags()->first() ?
Expand Down Expand Up @@ -432,29 +428,21 @@ public function setTranslatedTags(Collection $translatedTags): static
return $this;
}

/**
* @Serializer\Groups({"tag", "node", "nodes_sources"})
*
* @Serializer\VirtualProperty
*
* @Serializer\Type("string|null")
*/
#[SymfonySerializer\Ignore]
#[Serializer\VirtualProperty]
#[Serializer\Groups(['tag', 'node', 'nodes_sources'])]
#[Serializer\Type('string|null')]
public function getDescription(): ?string
{
return $this->getTranslatedTags()->first() ?
$this->getTranslatedTags()->first()->getDescription() :
'';
}

/**
* @Serializer\Groups({"tag", "node", "nodes_sources"})
*
* @Serializer\VirtualProperty
*
* @Serializer\Type("array<RZ\Roadiz\CoreBundle\Entity\Document>")
*/
#[SymfonySerializer\Ignore]
#[Serializer\VirtualProperty]
#[Serializer\Groups(['tag', 'node', 'nodes_sources'])]
#[Serializer\Type('array<RZ\Roadiz\CoreBundle\Entity\Document>')]
public function getDocuments(): array
{
return $this->getTranslatedTags()->first() ?
Expand Down
13 changes: 4 additions & 9 deletions src/Entity/TagTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class TagTranslation extends AbstractEntity

/**
* @var Collection<int, TagTranslationDocuments>
*
* @Serializer\Exclude
*/
#[ORM\OneToMany(
mappedBy: 'tagTranslation',
Expand All @@ -69,6 +67,7 @@ class TagTranslation extends AbstractEntity
)]
#[ORM\OrderBy(['position' => 'ASC'])]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
protected Collection $tagTranslationDocuments;

/**
Expand Down Expand Up @@ -151,14 +150,10 @@ public function __clone()
}
}

/**
* @Serializer\Groups({"tag"})
*
* @Serializer\VirtualProperty
*
* @Serializer\Type("array<RZ\Roadiz\CoreBundle\Entity\Document>")
*/
#[SymfonySerializer\Groups(['tag'])]
#[Serializer\Groups(['tag'])]
#[Serializer\VirtualProperty]
#[Serializer\Type('array<RZ\Roadiz\CoreBundle\Entity\Document>')]
public function getDocuments(): array
{
return array_map(function (TagTranslationDocuments $tagTranslationDocument) {
Expand Down
34 changes: 10 additions & 24 deletions src/Entity/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,10 @@ class Translation extends AbstractDateTimed implements TranslationInterface
* fr or en for example
*
* @see https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
*
* @Serializer\Groups({"translation", "document", "nodes_sources", "tag", "attribute", "folder", "log_sources"})
*
* @Serializer\Type("string")
*/
#[ORM\Column(type: 'string', length: 10, unique: true, nullable: false)]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
#[Assert\NotBlank]
#[Assert\NotNull]
#[Assert\Length(max: 10)]
Expand All @@ -565,27 +562,20 @@ class Translation extends AbstractDateTimed implements TranslationInterface
)]
private string $locale = '';

/**
* @Serializer\Groups({"translation", "document", "nodes_sources", "tag", "attribute", "folder"})
*
* @Serializer\Type("string")
*/
#[ORM\Column(name: 'override_locale', type: 'string', length: 10, unique: true, nullable: true)]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
#[Assert\Length(max: 10)]
#[ApiProperty(
description: 'Override standard locale with an other one (for example, `uk` instead of `en`)',
example: 'uk',
)]
private ?string $overrideLocale = null;

/**
* @Serializer\Groups({"translation", "translation_base"})
*
* @Serializer\Type("string")
*/
#[ORM\Column(type: 'string', length: 250, unique: true)]
#[SymfonySerializer\Groups(['translation', 'translation_base'])]
#[Serializer\Groups(['translation', 'translation_base'])]
#[Serializer\Type('string')]
#[Assert\NotNull]
#[Assert\NotBlank]
#[Assert\Length(max: 250)]
Expand All @@ -595,26 +585,20 @@ class Translation extends AbstractDateTimed implements TranslationInterface
)]
private string $name = '';

/**
* @Serializer\Groups({"translation", "translation_base"})
*
* @Serializer\Type("bool")
*/
#[ORM\Column(name: 'default_translation', type: 'boolean', nullable: false, options: ['default' => false])]
#[SymfonySerializer\Groups(['translation', 'translation_base'])]
#[Serializer\Groups(['translation', 'translation_base'])]
#[Serializer\Type('bool')]
#[ApiProperty(
description: 'Is translation default one?',
example: 'true',
)]
private bool $defaultTranslation = false;

/**
* @Serializer\Groups({"translation", "translation_base"})
*
* @Serializer\Type("bool")
*/
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => true])]
#[SymfonySerializer\Groups(['translation', 'translation_base'])]
#[Serializer\Groups(['translation', 'translation_base'])]
#[Serializer\Type('bool')]
#[ApiProperty(
description: 'Is translation available publicly?',
example: 'true',
Expand Down Expand Up @@ -778,6 +762,8 @@ public function setOverrideLocale(?string $overrideLocale): Translation
*/
#[SymfonySerializer\SerializedName('locale')]
#[SymfonySerializer\Groups(['translation_base'])]
#[Serializer\SerializedName('locale')]
#[Serializer\Groups(['translation_base'])]
#[ApiProperty(
description: 'Translation ISO 639-1 locale. See https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes',
example: 'fr',
Expand Down
Loading

0 comments on commit 297df80

Please sign in to comment.