Skip to content

Commit

Permalink
Add attributes to make the code work even if doctrine/annotations is …
Browse files Browse the repository at this point in the history
…not installed
  • Loading branch information
W0rma committed Oct 22, 2024
1 parent 73fcb54 commit b3b5da5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Representation/AbstractSegmentedRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/**
* @Serializer\ExclusionPolicy("all")
*/
#[Serializer\ExclusionPolicy('all')]
abstract class AbstractSegmentedRepresentation extends RouteAwareRepresentation
{
/**
Expand All @@ -18,6 +19,9 @@ abstract class AbstractSegmentedRepresentation extends RouteAwareRepresentation
*
* @var int
*/
#[Serializer\Expose]
#[Serializer\Type('integer')]
#[Serializer\XmlAttribute]
private $limit;

/**
Expand All @@ -27,6 +31,9 @@ abstract class AbstractSegmentedRepresentation extends RouteAwareRepresentation
*
* @var int
*/
#[Serializer\Expose]
#[Serializer\Type('integer')]
#[Serializer\XmlAttribute]
private $total;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Representation/CollectionRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* embedded = @Hateoas\Embedded("expr(object.getResources())")
* )
*/
#[Serializer\ExclusionPolicy('all')]
#[Serializer\XmlRoot('collection')]
#[Hateoas\Relation(name: 'items', embedded: new Hateoas\Embedded(content: 'expr(object.getResources())'))]
class CollectionRepresentation
{
/**
Expand Down
9 changes: 9 additions & 0 deletions src/Representation/OffsetRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
* )
* )
*/
#[Serializer\ExclusionPolicy('all')]
#[Serializer\XmlRoot('collection')]
#[Serializer\AccessorOrder(order: 'custom', custom: ['offset', 'limit', 'total'])]
#[Hateoas\Relation(name: 'first', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters(0))', absolute: 'expr(object.isAbsolute())'))]
#[Hateoas\Relation(name: 'last', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters((object.getTotal() - 1) - (object.getTotal() - 1) % object.getLimit()))', absolute: 'expr(object.isAbsolute())'), exclusion: new Hateoas\Exclusion(excludeIf: 'expr(object.getTotal() === null)'))]
#[Hateoas\Relation(name: 'next', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters(object.getOffset() + object.getLimit()))', absolute: 'expr(object.isAbsolute())'), exclusion: new Hateoas\Exclusion(excludeIf: 'expr(object.getTotal() !== null && (object.getOffset() + object.getLimit()) >= object.getTotal())'))]
#[Hateoas\Relation(name: 'previous', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters((object.getOffset() > object.getLimit()) ? object.getOffset() - object.getLimit() : 0))', absolute: 'expr(object.isAbsolute())'), exclusion: new Hateoas\Exclusion(excludeIf: 'expr(! object.getOffset())'))]
class OffsetRepresentation extends AbstractSegmentedRepresentation
{
/**
Expand All @@ -62,6 +69,8 @@ class OffsetRepresentation extends AbstractSegmentedRepresentation
*
* @var int
*/
#[Serializer\Expose]
#[Serializer\XmlAttribute]
private $offset;

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Representation/PaginatedRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
* )
* )
*/
#[Serializer\ExclusionPolicy('all')]
#[Serializer\XmlRoot('collection')]
#[Serializer\AccessorOrder(order: 'custom', custom: ['page', 'limit', 'pages', 'total'])]
#[Hateoas\Relation(name: 'first', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters(1))', absolute: 'expr(object.isAbsolute())'))]
#[Hateoas\Relation(name: 'last', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters(object.getPages()))', absolute: 'expr(object.isAbsolute())'), exclusion: new Hateoas\Exclusion(excludeIf: 'expr(object.getPages() === null)'))]
#[Hateoas\Relation(name: 'next', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters(object.getPage() + 1))', absolute: 'expr(object.isAbsolute())'), exclusion: new Hateoas\Exclusion(excludeIf: 'expr(object.getPages() !== null && (object.getPage() + 1) > object.getPages())'))]
#[Hateoas\Relation(name: 'previous', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters(object.getPage() - 1))', absolute: 'expr(object.isAbsolute())'), exclusion: new Hateoas\Exclusion(excludeIf: 'expr((object.getPage() - 1) < 1)'))]
class PaginatedRepresentation extends AbstractSegmentedRepresentation
{
/**
Expand All @@ -63,6 +70,9 @@ class PaginatedRepresentation extends AbstractSegmentedRepresentation
*
* @var int
*/
#[Serializer\Expose]
#[Serializer\Type('integer')]
#[Serializer\XmlAttribute]
private $page;

/**
Expand All @@ -72,6 +82,9 @@ class PaginatedRepresentation extends AbstractSegmentedRepresentation
*
* @var int
*/
#[Serializer\Expose]
#[Serializer\Type('integer')]
#[Serializer\XmlAttribute]
private $pages;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Representation/RouteAwareRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* )
* )
*/
#[Serializer\ExclusionPolicy('all')]
#[Hateoas\Relation(name: 'self', href: new Hateoas\Route(name: 'expr(object.getRoute())', parameters: 'expr(object.getParameters())', absolute: 'expr(object.isAbsolute())'))]
class RouteAwareRepresentation
{
/**
Expand All @@ -27,6 +29,8 @@ class RouteAwareRepresentation
*
* @var mixed
*/
#[Serializer\Inline]
#[Serializer\Expose]
private $inline;

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Representation/VndErrorRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
* )
* )
*/
#[Serializer\ExclusionPolicy('all')]
#[Serializer\XmlRoot('resource')]
#[Hateoas\Relation(name: 'help', href: 'expr(object.getHelp())', exclusion: new Hateoas\Exclusion(excludeIf: 'expr(object.getHelp() === null)'))]
#[Hateoas\Relation(name: 'describes', href: 'expr(object.getDescribes())', exclusion: new Hateoas\Exclusion(excludeIf: 'expr(object.getDescribes() === null)'))]
#[Hateoas\Relation(name: 'about', href: 'expr(object.getAbout())', exclusion: new Hateoas\Exclusion(excludeIf: 'expr(object.getAbout() === null)'))]
class VndErrorRepresentation
{
/**
Expand All @@ -41,6 +46,8 @@ class VndErrorRepresentation
*
* @var string
*/
#[Serializer\Expose]
#[Serializer\Type('string')]
private $message;

/**
Expand All @@ -50,6 +57,9 @@ class VndErrorRepresentation
*
* @var int
*/
#[Serializer\Expose]
#[Serializer\XmlAttribute]
#[Serializer\Type('integer')]
private $logref;

/**
Expand Down

0 comments on commit b3b5da5

Please sign in to comment.