forked from Crell/Serde
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Crell#22 from Crell/uninitialized
Allow fields to require a value be provided on deserialiation.
- Loading branch information
Showing
12 changed files
with
193 additions
and
5 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
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
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde; | ||
|
||
class MissingRequiredValueWhenDeserializing extends \InvalidArgumentException | ||
{ | ||
public readonly string $name; | ||
public readonly string $class; | ||
public readonly string $format; | ||
|
||
public static function create(string $name, string $class, string $format): self | ||
{ | ||
$new = new self(); | ||
$new->name = $name; | ||
$new->class = $class; | ||
$new->format = $format; | ||
|
||
$new->message = sprintf('No data found for required field "%s" on class %s when deserializing from %s.', $name, $class, $format); | ||
|
||
return $new; | ||
} | ||
} |
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
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Records; | ||
|
||
use Crell\Serde\Attributes\ClassSettings; | ||
use Crell\Serde\Attributes\Field; | ||
|
||
#[ClassSettings] | ||
class RequiresFieldValues | ||
{ | ||
public function __construct( | ||
#[Field(requireValue: true)] | ||
public string $a, | ||
// This field has a default, so it being missing should not be an error. | ||
#[Field(requireValue: true)] | ||
public string $b = 'B', | ||
) {} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Records; | ||
|
||
use Crell\Serde\Attributes\ClassSettings; | ||
use Crell\Serde\Attributes\Field; | ||
|
||
#[ClassSettings(requireValues: true)] | ||
class RequiresFieldValuesClass | ||
{ | ||
public function __construct( | ||
public string $a, | ||
// This field has a default, so it being missing should not be an error. | ||
public string $b = 'B', | ||
) {} | ||
} |
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