Skip to content

Commit

Permalink
Use jms serializer php attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Nov 4, 2024
1 parent 0c1261c commit 3dc58c1
Show file tree
Hide file tree
Showing 30 changed files with 52 additions and 138 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"symfony/security-bundle": "^5.4 || ^6.4 || ^7.0",
"twig/twig": "^3.0",
"vimeo/psalm": "^5.20",
"willdurand/hateoas": "^3.1 || ^3.12@beta",
"willdurand/hateoas-bundle": "^2.0 || ^2.7@beta",
"winzou/state-machine-bundle": "^0.6.2"
},
Expand Down
18 changes: 5 additions & 13 deletions tests/Application/src/Entity/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[ORM\Embeddable]
final class Author
{
/**
* @Serializer\Expose
*
* @Serializer\Type("string")
*/
#[Serializer\Expose]
#[Serializer\Type(name: 'string')]
#[ORM\Column(name: 'first_name', length: 255)]
private ?string $firstName = null;

/**
* @Serializer\Expose
*
* @Serializer\Type("string")
*/
#[Serializer\Expose]
#[Serializer\Type(name: 'string')]
#[ORM\Column(name: 'last_name', length: 255)]
private ?string $lastName = null;

Expand Down
28 changes: 8 additions & 20 deletions tests/Application/src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
use Sylius\Resource\Model\TranslatableInterface;
use Sylius\Resource\Model\TranslatableTrait;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[ORM\Entity]
#[ORM\MappedSuperclass]
#[ORM\Table(name: 'app_book')]
Expand All @@ -31,23 +29,16 @@ class Book implements ResourceInterface, TranslatableInterface
__construct as private initializeTranslationsCollection;
}

/**
* @Serializer\Expose
*
* @Serializer\Type("integer")
*
* @Serializer\XmlAttribute
*/
#[Serializer\Expose]
#[Serializer\Type(name: 'integer')]
#[Serializer\XmlAttribute]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;

/**
* @Serializer\Expose
*
* @Serializer\Type("string")
*/
#[Serializer\Expose]
#[Serializer\Type(name: 'string')]
#[ORM\Column(length: 255)]
private ?string $author = null;

Expand All @@ -56,11 +47,8 @@ public function getId(): ?int
return $this->id;
}

/**
* @Serializer\VirtualProperty()
*
* @Serializer\SerializedName("title")
*/
#[Serializer\VirtualProperty]
#[Serializer\SerializedName(name: 'title')]
public function getTitle(): ?string
{
return $this->getTranslation()->getTitle();
Expand Down
42 changes: 12 additions & 30 deletions tests/Application/src/Entity/ComicBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,27 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Model\ResourceInterface;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[ORM\Entity(repositoryClass: ComicBookRepository::class)]
#[ORM\MappedSuperclass]
#[ORM\Table(name: 'app_comic_book')]
class ComicBook implements ResourceInterface
{
/**
* @Serializer\Expose
*
* @Serializer\Type("integer")
*
* @Serializer\XmlAttribute
*/
#[Serializer\Expose]
#[Serializer\Type(name: 'integer')]
#[Serializer\XmlAttribute]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;

/**
* @Serializer\Expose
*
* @Serializer\Until("1.1")
*/
#[Serializer\Expose]
#[Serializer\Until(version: '1.1')]
#[ORM\Embedded]
private ?Author $author = null;

/**
* @Serializer\Expose
*
* @Serializer\Type("string")
*/
#[Serializer\Expose]
#[Serializer\Type(name: 'string')]
#[ORM\Column(length: 255)]
private ?string $title = null;

Expand All @@ -69,21 +57,15 @@ public function setTitle(?string $title): void
$this->title = $title;
}

/**
* @Serializer\VirtualProperty()
*
* @Serializer\Since("1.1")
*/
#[Serializer\VirtualProperty]
#[Serializer\Since(version: '1.1')]
public function getAuthorFirstName(): ?string
{
return $this->author?->getFirstName();
}

/**
* @Serializer\VirtualProperty()
*
* @Serializer\Since("1.1")
*/
#[Serializer\VirtualProperty]
#[Serializer\Since(version: '1.1')]
public function getAuthorLastName(): ?string
{
return $this->author?->getLastName();
Expand Down
1 change: 1 addition & 0 deletions tests/Application/src/Entity/CrudRoutes/BookWithAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
)]
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/CrudRoutes/BookWithCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'criteria',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/CrudRoutes/BookWithExcept.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'except',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/CrudRoutes/BookWithGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'grid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'legacy_attribute',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/CrudRoutes/BookWithOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'only',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'permission',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/CrudRoutes/BookWithRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'redirect',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/CrudRoutes/BookWithSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'admin',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/CrudRoutes/BookWithTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'template',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/CrudRoutes/BookWithVars.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusCrudRoutes;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusCrudRoutes(
alias: 'app.book',
section: 'vars',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/Route/PublishBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'publish_book',
path: '/books/{id}',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/Route/ShowBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book',
path: '/book/{id}',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/Route/ShowBookWithCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book_with_criteria',
path: '/library/{libraryId}/book/{id}',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/Route/ShowBookWithHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book_with_host',
path: '/book/{id}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Component\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book_with_legacy_attribute',
path: '/book/{id}',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/Route/ShowBookWithMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book_with_methods',
path: '/book/{id}',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/Route/ShowBookWithOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book_with_options',
path: '/book/{id}',
Expand Down
4 changes: 1 addition & 3 deletions tests/Application/src/Entity/Route/ShowBookWithPriority.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book_without_priority',
path: '/book/{id}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book_with_repository',
path: '/book/{id}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use JMS\Serializer\Annotation as Serializer;
use Sylius\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy(policy: 'ALL')]
#[SyliusRoute(
name: 'show_book_with_requirements',
path: '/book/{id}',
Expand Down
Loading

0 comments on commit 3dc58c1

Please sign in to comment.