-
-
Notifications
You must be signed in to change notification settings - Fork 18
Fix missing data if it was passed later using attachTo method #94
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
Conversation
Thanks for the PR. It's not quite clear what it purpose is tho, could you give a bit more details please? Also some tests seem to fail after this change. |
In the current version, when adding data using the attachTo method, they disappear after adding the Error object to ErrorDocument |
Travis builds were failing. I fixed those and took the liberty of updating your PR as well so we can see if the tests are still failing. |
src/JsonApi.php
Outdated
@@ -8,15 +8,13 @@ | |||
|
|||
final class JsonApi implements MetaDocumentMember, DataDocumentMember, ErrorDocumentMember | |||
{ | |||
private $obj; | |||
public $version; |
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.
This change makes the object mutable. Why is it necessary?
This use case also goes against immutability which is one of the features of this implementation. All dependencies are supposed to be passed to the constructor of the object being built. If you need to build something dynamically, gather the dependencies first and then pass them using the array spread operator, like this <?php
$error_members = [ new Id('1'), new AboutLink('/errors/not_found')];
if ($need_meta) {
$error_members[] = new Meta('foo', 'bar');
}
$error = new Error(...$error_members); Does this make sense? |
In fact, the |
Thank you, now everything has become clear. Maybe it makes sense to add |
Makes sense to me. Thanks. |
Example that will work after this commit:
$error = new Error();
(new Error\Code('code')->attachTo($error);
$jsonapi = new JsonApi();
(new Meta('key', 'value'))->attachTo($jsonapi);