Skip to content

Commit de10005

Browse files
Throw deprecation notice on non-abstract parent when it's not in the map
1 parent 4751668 commit de10005

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

src/JMS/Serializer/Metadata/ClassMetadata.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,22 @@ public function unserialize($str)
268268

269269
private function handleDiscriminatorProperty()
270270
{
271-
if (
272-
$this->discriminatorMap
273-
&& !$this->reflection->isAbstract()
274-
&& !$this->reflection->isInterface()
275-
) {
276-
if (
277-
false === ($typeValue = array_search($this->name, $this->discriminatorMap, true))
278-
&& $this->discriminatorBaseClass !== $this->name
279-
) {
280-
throw new \LogicException(sprintf(
281-
'The sub-class "%s" is not listed in the discriminator of the base class "%s".',
282-
$this->name,
283-
$this->discriminatorBaseClass
284-
));
271+
if ($this->discriminatorMap && !$this->reflection->isAbstract() && !$this->reflection->isInterface()) {
272+
if (false === $typeValue = array_search($this->name, $this->discriminatorMap, true)) {
273+
if ($this->discriminatorBaseClass === $this->name) {
274+
@trigger_error(
275+
'Discriminator map was configured on non-abstract parent class but parent class'
276+
.' was not included into discriminator map. It will throw exception in next major version.'
277+
.' Either declare parent as abstract class or add it into discriminator map.',
278+
E_USER_DEPRECATED
279+
);
280+
} else {
281+
throw new \LogicException(sprintf(
282+
'The sub-class "%s" is not listed in the discriminator of the base class "%s".',
283+
$this->name,
284+
$this->discriminatorBaseClass
285+
));
286+
}
285287
}
286288

287289
$this->discriminatorValue = $typeValue;

0 commit comments

Comments
 (0)