-
-
Notifications
You must be signed in to change notification settings - Fork 14
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 #57 from jboctor/patch-1
Update TypeField to be inheritable and transitive
- Loading branch information
Showing
10 changed files
with
227 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
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Attributes; | ||
|
||
use Attribute; | ||
use Crell\Serde\TypeField; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
class ReducingTransitiveTypeField implements TypeField | ||
{ | ||
public function acceptsType(string $type): bool | ||
{ | ||
return $type === 'object' || class_exists($type) || interface_exists($type); | ||
} | ||
|
||
public function validate(mixed $value): bool | ||
{ | ||
return true; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Attributes; | ||
|
||
use Attribute; | ||
use Crell\Serde\TypeField; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
class TransitiveTypeField implements TypeField | ||
{ | ||
public function acceptsType(string $type): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function validate(mixed $value): bool | ||
{ | ||
return true; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/Records/ClassWithPropertyWithTransitiveTypeField.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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Records; | ||
|
||
class ClassWithPropertyWithTransitiveTypeField | ||
{ | ||
public function __construct( | ||
public readonly TransitiveField $transitive, | ||
) { | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Records; | ||
|
||
class ClassWithReducibleProperty | ||
{ | ||
public function __construct( | ||
public ReducibleClass $dbReference, | ||
) {} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Records; | ||
|
||
use Crell\Serde\Attributes\ReducingTransitiveTypeField; | ||
|
||
#[ReducingTransitiveTypeField] | ||
class ReducibleClass | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public string $name, | ||
) {} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Crell\Serde\Records; | ||
|
||
use Crell\Serde\Attributes\TransitiveTypeField; | ||
|
||
#[TransitiveTypeField] | ||
class TransitiveField | ||
{ | ||
public function __construct( | ||
public readonly string $name = 'Transitive', | ||
) { | ||
} | ||
} |
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