mezzio / mezzio-hal

Hypertext Application Language implementation for PHP and PSR-7

Home Page:https://docs.mezzio.dev/mezzio-hal/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to convert self-referring instances to resources

weierophinney opened this issue · comments

  • 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

still smells. but should fit now.


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

@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)

Any news on this issue?

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