File tree Expand file tree Collapse file tree
packages/mapper/src/Casters Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222 */
2323 public function __construct (
2424 private string $ enum ,
25+ private bool $ nullable = false ,
2526 ) {}
2627
2728 public static function accepts (PropertyReflector |TypeReflector $ input ): bool
@@ -35,11 +36,18 @@ public static function accepts(PropertyReflector|TypeReflector $input): bool
3536
3637 public static function configure (PropertyReflector $ property , Context $ context ): self
3738 {
38- return new self (enum: $ property ->getType ()->getName ());
39+ return new self (
40+ enum: $ property ->getType ()->getName (),
41+ nullable: $ property ->isNullable (),
42+ );
3943 }
4044
4145 public function cast (mixed $ input ): ?object
4246 {
47+ if ($ this ->nullable && ($ input === null || $ input === '' || is_string ($ input ) && mb_strtolower ($ input ) === 'null ' )) {
48+ return null ;
49+ }
50+
4351 if ($ input === null ) {
4452 return null ;
4553 }
You can’t perform that action at this time.
0 commit comments