| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Contract\Core\Entity; |
| 4: | |
| 5: | use Salient\Contract\Core\DateFormatterInterface; |
| 6: | use Salient\Contract\Core\Immutable; |
| 7: | use Closure; |
| 8: | |
| 9: | /** |
| 10: | * @api |
| 11: | * |
| 12: | * @template TEntity of object |
| 13: | */ |
| 14: | interface SerializeRulesInterface extends Immutable |
| 15: | { |
| 16: | /** |
| 17: | * Get the entity to which the instance applies |
| 18: | * |
| 19: | * @return class-string<TEntity> |
| 20: | */ |
| 21: | public function getEntity(): string; |
| 22: | |
| 23: | /** |
| 24: | * Check if path-based rules are applied to nested instances of the entity |
| 25: | */ |
| 26: | public function getRecurseRules(): bool; |
| 27: | |
| 28: | /** |
| 29: | * Get an instance that applies path-based rules to nested instances of the |
| 30: | * entity |
| 31: | * |
| 32: | * @return static |
| 33: | */ |
| 34: | public function withRecurseRules(?bool $recurse = true): self; |
| 35: | |
| 36: | /** |
| 37: | * Merge with another instance, giving precedence to its values if there are |
| 38: | * any conflicts |
| 39: | * |
| 40: | * @param static $rules Must apply to the same entity or one of its |
| 41: | * subclasses. |
| 42: | * @return static |
| 43: | */ |
| 44: | public function merge(self $rules): self; |
| 45: | |
| 46: | /** |
| 47: | * Get keys to remove from a serialized class at a given path |
| 48: | * |
| 49: | * If `$baseClass` is given, rules applied to `$class` and its parents up to |
| 50: | * but not including `$baseClass` are inherited, otherwise the only |
| 51: | * class-based rules used are those applied directly to `$class`. |
| 52: | * |
| 53: | * @template T0 of object |
| 54: | * @template T1 of T0 |
| 55: | * |
| 56: | * @param class-string<T1>|null $class |
| 57: | * @param class-string<T0>|null $baseClass |
| 58: | * @param string[] $path |
| 59: | * @return array<string,string> Keys are mapped to themselves. |
| 60: | */ |
| 61: | public function getRemovableKeys(?string $class, ?string $baseClass, array $path): array; |
| 62: | |
| 63: | /** |
| 64: | * Get keys to replace in a serialized class at a given path |
| 65: | * |
| 66: | * If `$baseClass` is given, rules applied to `$class` and its parents up to |
| 67: | * but not including `$baseClass` are inherited, otherwise the only |
| 68: | * class-based rules used are those applied directly to `$class`. |
| 69: | * |
| 70: | * @template T0 of object |
| 71: | * @template T1 of T0 |
| 72: | * |
| 73: | * @param class-string<T1>|null $class |
| 74: | * @param class-string<T0>|null $baseClass |
| 75: | * @param string[] $path |
| 76: | * @return array<string,array{string|null,(Closure(mixed $value): mixed)|null}> Each |
| 77: | * key is mapped to an array with two values, one of which may be `null`: |
| 78: | * - a new key for the value |
| 79: | * - a closure to return a new value for the key |
| 80: | */ |
| 81: | public function getReplaceableKeys(?string $class, ?string $baseClass, array $path): array; |
| 82: | |
| 83: | /** |
| 84: | * Get the date formatter applied to the instance |
| 85: | */ |
| 86: | public function getDateFormatter(): ?DateFormatterInterface; |
| 87: | |
| 88: | /** |
| 89: | * Get an instance with a given date formatter |
| 90: | * |
| 91: | * @return static |
| 92: | */ |
| 93: | public function withDateFormatter(?DateFormatterInterface $formatter): self; |
| 94: | |
| 95: | /** |
| 96: | * Check if dynamic properties should be included when the entity is |
| 97: | * serialized |
| 98: | */ |
| 99: | public function getDynamicProperties(): bool; |
| 100: | |
| 101: | /** |
| 102: | * Get an instance where dynamic properties are included when the entity is |
| 103: | * serialized |
| 104: | * |
| 105: | * @return static |
| 106: | */ |
| 107: | public function withDynamicProperties(?bool $include = true): self; |
| 108: | |
| 109: | /** |
| 110: | * Check if serialized entities should be sorted by key |
| 111: | */ |
| 112: | public function getSortByKey(): bool; |
| 113: | |
| 114: | /** |
| 115: | * Get an instance where serialized entities are sorted by key |
| 116: | * |
| 117: | * @return static |
| 118: | */ |
| 119: | public function withSortByKey(?bool $sort = true): self; |
| 120: | |
| 121: | /** |
| 122: | * Get the maximum depth of nested values |
| 123: | */ |
| 124: | public function getMaxDepth(): int; |
| 125: | |
| 126: | /** |
| 127: | * Get an instance where the maximum depth of nested values is a given value |
| 128: | * |
| 129: | * @return static |
| 130: | */ |
| 131: | public function withMaxDepth(?int $depth): self; |
| 132: | |
| 133: | /** |
| 134: | * Check if recursion detection should be enabled when nested entities are |
| 135: | * serialized |
| 136: | */ |
| 137: | public function getDetectRecursion(): bool; |
| 138: | |
| 139: | /** |
| 140: | * Get an instance where recursion detection is enabled |
| 141: | * |
| 142: | * If circular references cannot arise when the entity is serialized, |
| 143: | * recursion detection should be disabled to improve performance and reduce |
| 144: | * memory consumption. |
| 145: | * |
| 146: | * @return static |
| 147: | */ |
| 148: | public function withDetectRecursion(?bool $detect = true): self; |
| 149: | } |
| 150: |