-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Provide context information from attribute for promoted properties #46680
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?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\Annotations; | ||
|
||
use Symfony\Component\Serializer\Annotation\Context; | ||
|
||
/** | ||
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com> | ||
*/ | ||
class ContextDummyPromotedProperties extends ContextDummyParent | ||
{ | ||
public function __construct( | ||
/** | ||
* @Context({ "foo" = "value", "bar" = "value", "nested" = { | ||
* "nested_key" = "nested_value", | ||
* }, "array": { "first", "second" } }) | ||
* @Context({ "bar" = "value_for_group_a" }, groups = "a") | ||
*/ | ||
public $foo, | ||
|
||
/** | ||
* @Context( | ||
* normalizationContext = { "format" = "d/m/Y" }, | ||
* denormalizationContext = { "format" = "m-d-Y H:i" }, | ||
* groups = {"a", "b"} | ||
* ) | ||
*/ | ||
public $bar, | ||
|
||
/** | ||
* @Context(normalizationContext={ "prop" = "dummy_value" }) | ||
*/ | ||
public $overriddenParentProperty, | ||
) { | ||
} | ||
|
||
/** | ||
* @Context({ "method" = "method_with_context" }) | ||
*/ | ||
public function getMethodWithContext() | ||
{ | ||
return 'method_with_context'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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\Attributes; | ||
|
||
use Symfony\Component\Serializer\Annotation\Context; | ||
|
||
/** | ||
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com> | ||
*/ | ||
class ContextDummyPromotedProperties extends ContextDummyParent | ||
{ | ||
public function __construct( | ||
#[Context(['foo' => 'value', 'bar' => 'value', 'nested' => [ | ||
'nested_key' => 'nested_value', | ||
], 'array' => ['first', 'second']])] | ||
#[Context(context: ['bar' => 'value_for_group_a'], groups: ['a'])] | ||
public $foo, | ||
|
||
#[Context( | ||
normalizationContext: ['format' => 'd/m/Y'], | ||
denormalizationContext: ['format' => 'm-d-Y H:i'], | ||
groups: ['a', 'b'], | ||
)] | ||
public $bar, | ||
|
||
#[Context(normalizationContext: ['prop' => 'dummy_value'])] | ||
public $overriddenParentProperty, | ||
) { | ||
} | ||
|
||
#[Context(['method' => 'method_with_context'])] | ||
public function getMethodWithContext() | ||
{ | ||
return 'method_with_context'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,14 @@ public function testLoadContexts() | |
$this->assertLoadedContexts($this->getNamespace().'\ContextDummy', $this->getNamespace().'\ContextDummyParent'); | ||
} | ||
|
||
/** | ||
* @requires PHP 8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to merge it either in 4.4 (as i saw this is latest maintained version) or 6.2. Or do you need me to update this here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The attribute is not available in 4.4 yet. |
||
*/ | ||
public function testLoadContextsPropertiesPromoted() | ||
{ | ||
$this->assertLoadedContexts($this->getNamespace().'\ContextDummyPromotedProperties', $this->getNamespace().'\ContextDummyParent'); | ||
} | ||
|
||
public function testThrowsOnContextOnInvalidMethod() | ||
{ | ||
$class = $this->getNamespace().'\BadMethodContextDummy'; | ||
|
Uh oh!
There was an error while loading. Please reload this page.