| @@ 22-57 (lines=36) @@ | ||
| 19 | * @Annotation |
|
| 20 | * @Target({"CLASS", "PROPERTY", "METHOD"}) |
|
| 21 | */ |
|
| 22 | class Exclude extends AbstractAnnotation |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * Exclude this property during serialization |
|
| 26 | * |
|
| 27 | * @var bool |
|
| 28 | */ |
|
| 29 | private $serialize = true; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Exclude this property during deserialization |
|
| 33 | * |
|
| 34 | * @var bool |
|
| 35 | */ |
|
| 36 | private $deserialize = true; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Initialize annotation data |
|
| 40 | */ |
|
| 41 | protected function init(): void |
|
| 42 | { |
|
| 43 | $this->serialize = $this->data['serialize'] ?? true; |
|
| 44 | $this->deserialize = $this->data['deserialize'] ?? true; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Returns true if the property should be excluded based on the direction (serialize/deserialize) |
|
| 49 | * |
|
| 50 | * @param bool $serialize |
|
| 51 | * @return bool |
|
| 52 | */ |
|
| 53 | public function shouldExclude(bool $serialize): bool |
|
| 54 | { |
|
| 55 | return $serialize ? $this->serialize : $this->deserialize; |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| @@ 22-57 (lines=36) @@ | ||
| 19 | * @Annotation |
|
| 20 | * @Target({"CLASS", "PROPERTY", "METHOD"}) |
|
| 21 | */ |
|
| 22 | class Expose extends AbstractAnnotation |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * Expose this property during serialization |
|
| 26 | * |
|
| 27 | * @var bool |
|
| 28 | */ |
|
| 29 | private $serialize = true; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Expose this property during deserialization |
|
| 33 | * |
|
| 34 | * @var bool |
|
| 35 | */ |
|
| 36 | private $deserialize = true; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Initialize annotation data |
|
| 40 | */ |
|
| 41 | protected function init(): void |
|
| 42 | { |
|
| 43 | $this->serialize = $this->data['serialize'] ?? true; |
|
| 44 | $this->deserialize = $this->data['deserialize'] ?? true; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Returns true if the property should be exposed based on the direction (serialize/deserialize) |
|
| 49 | * |
|
| 50 | * @param bool $serialize |
|
| 51 | * @return bool |
|
| 52 | */ |
|
| 53 | public function shouldExpose(bool $serialize): bool |
|
| 54 | { |
|
| 55 | return $serialize ? $this->serialize : $this->deserialize; |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||