Skip to content

Commit

Permalink
feature #31030 [Serializer] Deprecate calling createChildContext with…
Browse files Browse the repository at this point in the history
…out the format parameter (dbu)

This PR was submitted for the master branch but it was merged into the 4.3 branch instead (closes #31030).

Discussion
----------

[Serializer] Deprecate calling createChildContext without the format parameter

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

as discussed in #30907 deprecate omitting the format parameter when extending the AbstractNormalizer.

Commits
-------

cb77902 deprecate calling createChildContext without the format parameter
  • Loading branch information
fabpot committed May 15, 2019
2 parents b529e07 + cb77902 commit c5772ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -555,8 +555,12 @@ protected function denormalizeParameter(\ReflectionClass $class, \ReflectionPara
*
* @internal
*/
protected function createChildContext(array $parentContext, $attribute/*, string $format = null */)
protected function createChildContext(array $parentContext, $attribute/*, ?string $format */)
{
if (\func_num_args() < 3) {
@trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED);
$format = null;
}
if (isset($parentContext[self::ATTRIBUTES][$attribute])) {
$parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute];
} else {
Expand Down
Expand Up @@ -559,18 +559,19 @@ private function isMaxDepthReached(array $attributesMetadata, string $class, str
* We must not mix up the attribute cache between parent and children.
*
* {@inheritdoc}
*
* @param string|null $format
*/
protected function createChildContext(array $parentContext, $attribute/*, string $format = null */)
protected function createChildContext(array $parentContext, $attribute/*, ?string $format */)
{
if (\func_num_args() >= 3) {
$format = \func_get_arg(2);
} else {
// will be deprecated in version 4
@trigger_error(sprintf('Method "%s::%s()" will have a third "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED);
$format = null;
}

$context = parent::createChildContext($parentContext, $attribute, $format);
// format is already included in the cache_key of the parent.
$context['cache_key'] = $this->getCacheKey($format, $context);

return $context;
Expand Down

0 comments on commit c5772ae

Please sign in to comment.