|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Hateoas\Tests\Fixtures\Attribute; |
| 6 | + |
| 7 | +use Hateoas\Configuration\Annotation as Hateoas; |
| 8 | +use Hateoas\Configuration\Relation; |
| 9 | +use JMS\Serializer\Annotation as Serializer; |
| 10 | + |
| 11 | +/** |
| 12 | + * @Hateoas\Relation( |
| 13 | + * "self", |
| 14 | + * href = "http://adrienbrault.fr", |
| 15 | + * exclusion = @Hateoas\Exclusion( |
| 16 | + * groups = {"Default", "simple"}, |
| 17 | + * excludeIf = "expr(object.firstName !== 'Adrien' || object.lastName !== 'Brault')" |
| 18 | + * ) |
| 19 | + * ) |
| 20 | + * @Hateoas\Relation( |
| 21 | + * "broken-computer", |
| 22 | + * |
| 23 | + * embedded = "expr(object.getWindowsComputer())" |
| 24 | + * ) |
| 25 | + */ |
| 26 | +#[Hateoas\Relation( |
| 27 | + 'self', |
| 28 | + href: 'http://adrienbrault.fr', |
| 29 | + exclusion: new Hateoas\Exclusion( |
| 30 | + groups: ['Default', 'simple'], |
| 31 | + excludeIf: "expr(object.firstName !== 'Adrien' || object.lastName !== 'Brault')", |
| 32 | + ) |
| 33 | +)] |
| 34 | +#[Hateoas\Relation( |
| 35 | + 'computer', |
| 36 | + href: 'http://www.apple.com/macbook-pro/', |
| 37 | + exclusion: new Hateoas\Exclusion(groups: ['Default', 'simple']), |
| 38 | + embedded: new Hateoas\Embedded( |
| 39 | + 'expr(object.getMacbookPro())', |
| 40 | + type: 'Hateoas\Tests\Fixtures\Computer', |
| 41 | + exclusion: new Hateoas\Exclusion(groups: ['Default']), |
| 42 | + ), |
| 43 | +)] |
| 44 | +#[Hateoas\Relation( |
| 45 | + 'broken-computer', |
| 46 | + embedded: 'expr(object.getWindowsComputer())', |
| 47 | +)] |
| 48 | +#[Hateoas\Relation( |
| 49 | + 'smartphone', |
| 50 | + embedded: 'expr(object.getiOSSmartphone())', |
| 51 | +)] |
| 52 | +#[Hateoas\Relation( |
| 53 | + 'smartphone', |
| 54 | + embedded: 'expr(object.getAndroidSmartphone())', |
| 55 | +)] |
| 56 | +#[Hateoas\RelationProvider(name: 'Hateoas\Tests\Fixtures\Attribute\AdrienBrault::getRelations')] |
| 57 | +class AdrienBraultAttributesAndAnnotations |
| 58 | +{ |
| 59 | + #[Serializer\Groups(['Default', 'simple'])] |
| 60 | + public $firstName = 'Adrien'; |
| 61 | + |
| 62 | + #[Serializer\Groups(['Default', 'simple'])] |
| 63 | + public $lastName = 'Brault'; |
| 64 | + |
| 65 | + public function getMacbookPro() |
| 66 | + { |
| 67 | + return new Computer('MacBook Pro'); |
| 68 | + } |
| 69 | + |
| 70 | + public function getWindowsComputer() |
| 71 | + { |
| 72 | + return new Computer('Windows Computer'); |
| 73 | + } |
| 74 | + |
| 75 | + public function getiOSSmartphone() |
| 76 | + { |
| 77 | + return new Smartphone('iPhone 6'); |
| 78 | + } |
| 79 | + |
| 80 | + public function getAndroidSmartphone() |
| 81 | + { |
| 82 | + return new Smartphone('Nexus 5'); |
| 83 | + } |
| 84 | + |
| 85 | + public static function getRelations() |
| 86 | + { |
| 87 | + return [ |
| 88 | + new Relation('dynamic-relation', 'awesome!!!', ['wowowow']), |
| 89 | + ]; |
| 90 | + } |
| 91 | +} |
0 commit comments