Repository navigation
Commit b0c0b60
committed
Add UnserializeCast
Data objects can now restore values that were stored with serialize(),
such as serialized database columns or cache entries, through
#[WithCast(UnserializeCast::class)]. The cast can fail silently, leaving
the value to the built-in conversion, and allowedClasses limits which
classes unserialize() may create.
Port of spatie/laravel-data#1220 at main a161f325d5.
Hypervel adaptations:
- allowedClasses defaults to false, so no objects are restored unless
their classes are listed. Spatie allows every class by default, which
runs __wakeup() and __destruct() for any class named in the value.
Pass true to allow every class.
- failSilently no longer turns coroutine cancellation into a failed
cast. The restore hooks of allowed classes can suspend, such as
SerializesModels querying the database.
- The docs cover the allowed classes, including nested ones, and warn
against unserializing untrusted data. Their failSilently example lists
the class it restores.
All upstream UnserializeCast tests are ported, with coverage for the
default, a data object restoring only allowed classes, and cancellation
during a restore hook. The cast tests, analysis and formatting pass.1 parent d99d3fe commit b0c0b60
2 files changed
Lines changed: 35 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
898 | 899 | | |
899 | 900 | | |
900 | 901 | | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
901 | 934 | | |
902 | 935 | | |
903 | 936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
720 | 720 | | |
721 | 721 | | |
722 | 722 | | |
723 | | - | |
| 723 | + | |
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
| |||
734 | 734 | | |
735 | 735 | | |
736 | 736 | | |
| 737 | + | |
737 | 738 | | |
738 | 739 | | |
739 | 740 | | |
| |||
0 commit comments