8000 [Serializer] Allow to use proxies in object_to_populate by dunglas · Pull Request #17328 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Allow to use proxies in object_to_populate #17328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
if (
isset($context['object_to_populate']) &&
is_object($context['object_to_populate']) &&
$class === get_class($context['object_to_populate'])
$context['object_to_populate'] instanceof $class
) {
return $context['object_to_populate'];
}
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Serializer/Tests/Fixtures/ProxyDummy.php 8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Serializer\Tests\Fixtures;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class ProxyDummy extends ToBeProxyfiedDummy
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Serializer\Tests\Fixtures;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class ToBeProxyfiedDummy
{
private $foo;

public function setFoo($foo)
{
$this->foo = $foo;
}

public function getFoo()
{
return $this->foo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Tests\Fixtures\AbstractNormalizerDummy;
use Symfony\Component\Serializer\Tests\Fixtures\ProxyDummy;

/**
* Provides a dummy Normalizer which extends the AbstractNormalizer.
Expand Down Expand Up @@ -88,4 +90,16 @@ public function testGetAllowedAttributesAsObjects()
$result = $this->normalizer->getAllowedAttributes('c', array('groups' => array('other')), false);
$this->assertEquals(array($a3, $a4), $result);
}

public function testObjectToPopulateWithProxy()
{
$proxyDummy = new ProxyDummy();

$context = array('object_to_populate' => $proxyDummy);

$normalizer = new ObjectNormalizer();
$normalizer->denormalize(array('foo' => 'bar'), 'Symfony\Component\Serializer\Tests\Fixtures\ToBeProxyfiedDummy', null, $context);

$this->assertSame('bar', $proxyDummy->getFoo());
}
}
0