-
-
Notifications
You must be signed in to change notification settings - Fork 588
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 #1175 from schmittjoh/FrKevin-master
Handle discriminator groups
- Loading branch information
Showing
9 changed files
with
150 additions
and
0 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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Tests\Fixtures\Discriminator\Serialization; | ||
|
||
use JMS\Serializer\Annotation as JMS; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
|
||
abstract class Entity | ||
{ | ||
/** | ||
* @JMS\Type("int") | ||
* @JMS\Groups({"base"}) | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
public function __construct(int $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @throws ReflectionException | ||
* | ||
* @JMS\VirtualProperty() | ||
* @JMS\SerializedName("entityName") | ||
* @JMS\Groups({"entity.identification"}) | ||
*/ | ||
public function getEntityName(): string | ||
{ | ||
$reflect = new ReflectionClass($this); | ||
return $reflect->getShortName(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/Fixtures/Discriminator/Serialization/ExtendedUser.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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Tests\Fixtures\Discriminator\Serialization; | ||
|
||
use JMS\Serializer\Annotation as JMS; | ||
|
||
class ExtendedUser extends User | ||
{ | ||
/** | ||
* @JMS\Type("string") | ||
* @JMS\Groups({"base"}) | ||
* @var string | ||
*/ | ||
public $extendAttribute; | ||
|
||
public function __construct($id, $name, $description, $extendAttribute) | ||
{ | ||
parent::__construct($id, $name, $description); | ||
$this->extendAttribute = $extendAttribute; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Tests\Fixtures\Discriminator\Serialization; | ||
|
||
use JMS\Serializer\Annotation as JMS; | ||
|
||
/** | ||
* Class User | ||
* | ||
* @JMS\Discriminator(field = "entityName", | ||
* groups={"entity.identification"}, | ||
* map = { | ||
* "User": "JMS\Serializer\Tests\Fixtures\Discriminator\Serialization\User", | ||
* "ExtendedUser": "JMS\Serializer\Tests\Fixtures\Discriminator\Serialization\ExtendedUser" | ||
* }) | ||
*/ | ||
class User extends Entity | ||
{ | ||
/** | ||
* @JMS\Type("string") | ||
* @JMS\Groups({"base"}) | ||
* @var string | ||
*/ | ||
public $name; | ||
/** | ||
* @JMS\Type("string") | ||
* @JMS\Groups({"base"}) | ||
* @var string | ||
*/ | ||
public $description; | ||
|
||
public function __construct(int $id, string $name, string $description) | ||
{ | ||
parent::__construct($id); | ||
$this->name = $name; | ||
$this->description = $description; | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<result> | ||
<entityName><![CDATA[User]]></entityName> | ||
</result> |
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,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<result> | ||
<entry> | ||
<entityName><![CDATA[User]]></entityName> | ||
</entry> | ||
<entry> | ||
<entityName><![CDATA[ExtendedUser]]></entityName> | ||
</entry> | ||
</result> |
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<result> | ||
<entityName><![CDATA[ExtendedUser]]></entityName> | ||
</result> |