-
Notifications
You must be signed in to change notification settings - Fork 22
Unable to convert self-referring instances to resources #57
base: master
Are you sure you want to change the base?
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,23 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Zend\Expressive\Hal\Metadata; | ||
|
||
interface MetadataInterface | ||
{ | ||
/** | ||
* Returns the configured metadata class name | ||
* | ||
* @return string | ||
*/ | ||
public function getClass() : string; | ||
|
||
/** | ||
* Determines whenever the current depth level exceeds the allowed max depth | ||
* | ||
* @param int $currentDepth | ||
* | ||
* @return bool | ||
*/ | ||
public function hasReachedMaxDepth(int $currentDepth): bool; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,7 @@ public function fromArray(array $data, string $uri = null) : HalResource | |
* against types registered in the metadata map. | ||
* @param ServerRequestInterface $request | ||
*/ | ||
public function fromObject($instance, ServerRequestInterface $request) : HalResource | ||
public function fromObject($instance, ServerRequestInterface $request, int $depth = 0) : HalResource | ||
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. To help me as I create the changelog: could you please collate everywhere there is an additional optional argument passed to a public method? If I have that list, it will be far easier to communicate to users what may have changed in any extensions or custom implementations they have created. Thanks in advance! 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.
|
||
{ | ||
if (! is_object($instance)) { | ||
throw Exception\InvalidObjectException::forNonObject($instance); | ||
|
@@ -146,7 +146,8 @@ public function fromObject($instance, ServerRequestInterface $request) : HalReso | |
$instance, | ||
$metadata, | ||
$this, | ||
$request | ||
$request, | ||
$depth | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ public function createResource( | |
$instance, | ||
Metadata\AbstractMetadata $metadata, | ||
ResourceGenerator $resourceGenerator, | ||
ServerRequestInterface $request | ||
ServerRequestInterface $request, | ||
int $depth = 0 | ||
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. Oof- this is a BC break, as it changes a signature in an interface. 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. yep :/ this was the thing i mentioned as i opened the PR. still don't know how to resolve this without breaking BC. Not changing signature could end up in szenarios like this: $a = new stdClass;
$b = new stdClass;
$a->b = $b;
$b->a = $a;
// using custom strategy for `$b` without passing the depth param would cause the issue i try to solve 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. That was my point with one of my previous comments — this may be an excellent reason to break BC and have an immediate major release. As such, let's figure out what all we should change to make this as robust as possible for that release. 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. sounds good to me. should i just create a new PR with a few ideas or did you want to discuss it in issues first? 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 main thing here is to ensure that this is the only change necessary to fix the depth issues. If you know of other fixes that need to be done to address other issues, and which require BC breaks, submit those as separate patches. In all likelihood, I won't do the major release immediately; I'm going to be looking at #42 as well, as I understand it represents a common Doctrine scenario, which means the component fails for it. |
||
) : HalResource; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't know exactly where the config is coming from, it may be a good idea to do something like:
somewhere before this, and then, here:
to ensure that there are not type issues.
(Many config formats will return everything as strings by default.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if silently supporting a wrong type is the right way to go here.
i'd rather see an TypeError to inform me that i use a wrong type instead of continuing using the wrong but silently supported type.
IMHO this is just hiding a some kind of complexity (using string in config which is then "magically" (from an outer perspective) casted to int).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @weierophinney
any thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave it as-is. Most of the config libraries we support will cast values as they are processed, before they are pushed into the container. And the primary config type is pure PHP.