Skip to content

Context::getCurrentPath() returns indexes of list items#1325

Open
katin-dev wants to merge 1 commit into
schmittjoh:masterfrom
katin-dev:property_path_of_list_element
Open

Context::getCurrentPath() returns indexes of list items#1325
katin-dev wants to merge 1 commit into
schmittjoh:masterfrom
katin-dev:property_path_of_list_element

Conversation

@katin-dev
Copy link
Copy Markdown

Implementing ExclusionStrategyInterface i realized that there is no way to detect if current element is part on the list with specific index.

For example, we have a class

class Node {
  public string $name;
  /** @var Node[] */
  public array $children;
}

When one of $children element has been passed to shouldSkipProperty(PropertyMetadata $property, Context $context), i don't know which one. Context does not know the index of such element. But i have external rules like so which define whether property of element should be serialized or not:

$rules = [
  'children' => [
    0 => ['name'],
    2 => ['name', 'children']
  ]
]

I suggest $context->getCurrentPath() should return array like so: [children][0]['name'] instead of [children]['name'] (current behavior)

Q A
Bug fix? yes
New feature? no
Doc updated no
BC breaks? likely so
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT

@katin-dev
Copy link
Copy Markdown
Author

@goetas why Scrutinizer Canceled? What should I do to rerun it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant