Skip to content

Unable to convert self-referring instances to resources #1

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

Closed
6 of 7 tasks
weierophinney opened this issue Dec 31, 2019 · 4 comments · Fixed by #22
Closed
6 of 7 tasks

Unable to convert self-referring instances to resources #1

weierophinney opened this issue Dec 31, 2019 · 4 comments · Fixed by #22
Milestone

Comments

@weierophinney
Copy link
Contributor

  • Are you fixing a bug?
    • Detail how the bug is invoked currently.
    • Detail the original, incorrect behavior.
    • Detail the new, expected behavior.
    • Base your feature on the master branch, and submit against that branch.
    • Add a regression test that demonstrates the bug, and proves the fix.
    • Add a CHANGELOG.md entry for the fix.

Imagine the following example:

class Parent {
    /** @var Child[] */
    public $childs;
    public function addChild(Child $child) {
        $this->childs[] = $child;
        $child->parent = $this;
    }
}
class Child {
    /** @var Parent */
    public $parent;
}

$parent = new Parent();
$parent->addChild(new Child());
$parent->addChild(new Child());

$generator->fromObject($parent, $request);
// the call above will result in an error:
// Error : Maximum function nesting level of '256' reached, aborting!

Other examples:
One-To-One, Bidirectional
One-To-One, Self-referencing
One-To-Many, Bidirectional
One-To-Many, Self-referencing
Many-To-Many, Bidirectional
Many-To-Many, Self-referencing

The zfcampus/zf-hal component solved this issue by using a $maxDepth property in metadata which is then passed through here and here.

Using this approach would result in a change of the \Zend\Expressive\Hal\ResourceGenerator\StrategyInterface interface which would be a BC break.

I would love if someone comes up with an alternate solution which will not break BC.


Originally posted by @tobias-trozowski at zendframework/zend-expressive-hal#57

@weierophinney
Copy link
Contributor Author

still smells. but should fit now.


Originally posted by @tobias-trozowski at zendframework/zend-expressive-hal#57 (comment)

@weierophinney
Copy link
Contributor Author

@tobias-trozowski I've rebased your branch to squash several commits and remove both the revert commits and the commits they were reverting; the diff ends up the same as you had committed previously.

In the future, feel free to use git rebase -i + git push -f liberally when working on a patch; these help ensure the history is easier to follow, particularly when removing patches.

I'll review again now to see where we are in terms of ability to merge.


Originally posted by @weierophinney at zendframework/zend-expressive-hal#57 (comment)

@guliano
Copy link

guliano commented Jan 30, 2020

Any news on this issue?

@weierophinney
Copy link
Contributor Author

@guliano Not yet. We're still finishing out tasks related to the Laminas migration, so it may be a few weeks.

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 a pull request may close this issue.

2 participants