-
Notifications
You must be signed in to change notification settings - Fork 1
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 #7 from nutgram/abstract-class-resolver
add ability to resolve abstract class
- Loading branch information
Showing
10 changed files
with
183 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace SergiX44\Hydrator; | ||
|
||
interface ConcreteResolver | ||
{ | ||
/** | ||
* @param array $data | ||
* | ||
* @return class-string | ||
*/ | ||
public static function resolveAbstractClass(array $data): string; | ||
} |
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 | ||
|
||
namespace SergiX44\Hydrator\Tests\Fixtures; | ||
|
||
use SergiX44\Hydrator\Tests\Fixtures\Store\Apple; | ||
|
||
final class ObjectWithAbstract | ||
{ | ||
public Apple $value; | ||
} |
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 | ||
|
||
namespace SergiX44\Hydrator\Tests\Fixtures; | ||
|
||
use SergiX44\Hydrator\Tests\Fixtures\Store\Fruit; | ||
|
||
final class ObjectWithInvalidAbstract | ||
{ | ||
public Fruit $value; | ||
} |
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 | ||
|
||
namespace SergiX44\Hydrator\Tests\Fixtures\Store; | ||
|
||
use Exception; | ||
use SergiX44\Hydrator\ConcreteResolver; | ||
|
||
abstract class Apple implements ConcreteResolver | ||
{ | ||
public string $type; | ||
|
||
public static function resolveAbstractClass(array $data): string | ||
{ | ||
return match ($data['type']) { | ||
'jack' => AppleJack::class, | ||
'sauce' => AppleSauce::class, | ||
default => throw new Exception('Invalid apple type'), | ||
}; | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace SergiX44\Hydrator\Tests\Fixtures\Store; | ||
|
||
final class AppleJack extends Apple | ||
{ | ||
public string $category; | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace SergiX44\Hydrator\Tests\Fixtures\Store; | ||
|
||
final class AppleSauce extends Apple | ||
{ | ||
public int $sweetness; | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace SergiX44\Hydrator\Tests\Fixtures\Store; | ||
|
||
abstract class Fruit | ||
{ | ||
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