Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove WHRC reference, phpstan-baseline.neon, and added customizable …
…payload edge value serialization
- Loading branch information
Showing
5 changed files
with
85 additions
and
20 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Serialization/CustomizedSerializablePayloadEdgeValue.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dflydev\EventSauce\Support\Serialization; | ||
|
||
interface CustomizedSerializablePayloadEdgeValue | ||
{ | ||
/** | ||
* @param class-string $type | ||
*/ | ||
public static function hasCustomSerializablePayloadEdgeValue(string $type, string $name): bool; | ||
|
||
/** | ||
* @param class-string $type | ||
*/ | ||
public function toCustomSerializablePayloadEdgeValue(string $type, string $name, mixed $value = null): string|array|null; | ||
|
||
/** | ||
* @template TType | ||
* | ||
* @param class-string<TType> $type | ||
* | ||
* @return TType | ||
*/ | ||
public static function fromCustomSerializablePayloadEdgeValue(string $type, string $name, string|array|null $value = null): mixed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Serialization/SupportsAwareCustomizedSerializablePayloadEdgeValues.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dflydev\EventSauce\Support\Serialization; | ||
|
||
trait SupportsAwareCustomizedSerializablePayloadEdgeValues | ||
{ | ||
abstract public static function supportsCustomSerializablePayloadEdgeValues(): array; | ||
|
||
public static function hasCustomSerializablePayloadEdgeValue(string $type, string $name): bool | ||
{ | ||
return array_key_exists($name, self::supportsCustomSerializablePayloadEdgeValues()); | ||
} | ||
|
||
public function toCustomSerializablePayloadEdgeValue(string $type, string $name, mixed $value = null): string|array|null | ||
{ | ||
$callable = static::supportsCustomSerializablePayloadEdgeValues()[$name]['toPayload']; | ||
|
||
return $callable($type, $name, $value); | ||
} | ||
|
||
public static function fromCustomSerializablePayloadEdgeValue(string $type, string $name, array|string|null $value = null): mixed | ||
{ | ||
$callable = static::supportsCustomSerializablePayloadEdgeValues()[$name]['fromPayload']; | ||
|
||
return $callable($type, $name, $value); | ||
} | ||
} |