-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc788e8
commit 41631fc
Showing
5 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Windwalker\ORM\Attributes; | ||
|
||
use Windwalker\Utilities\TypeCast; | ||
|
||
/** | ||
* The ForceObjectSerializer class. | ||
*/ | ||
#[\Attribute] | ||
class ForceObjectJsonSerializer implements JsonSerializerInterface | ||
{ | ||
public function __construct( | ||
public bool $deep = false, | ||
public bool $nullable = false, | ||
public string $class = \stdClass::class | ||
) { | ||
} | ||
|
||
public function serialize(mixed $data): mixed | ||
{ | ||
if ($this->nullable && $data === null) { | ||
return null; | ||
} | ||
|
||
return TypeCast::toObject($data, $this->deep, $this->class); | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Windwalker\ORM\Attributes; | ||
|
||
#[\Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_PROPERTY)] | ||
class JsonObject extends Cast | ||
{ | ||
|
||
} |
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
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Windwalker\ORM\Attributes; | ||
|
||
interface JsonSerializerInterface | ||
{ | ||
public function serialize(mixed $data): 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