This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Getters instead of magic __get in Hal\Entity #99
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In the `Hal\Collection` class the magic `__get` for getting properties has been deprecated. To get `$collection` the `getCollection` method has to be called instead. Would it not be better to also use similar solution for the `Hal\Entity` class. So `getEntity` and `getId` methods instead of the magic `__get`?
I realize now that the magic
So I am not sure if changing this to a getter like I proposed will be possible at all. But @weierophinney can maybe shed some light on this. |
We return by reference so that if the entity is an array and you make changes to it, you don't need to re-inject. Not ideal, but changing that behavior now would break BC. |
} | ||
$prop = $names[$name]; | ||
return $this->{$prop}; | ||
throw new \Exception('Direct query of values is deprecated. Use getters.'); |
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.
We can make this BC by doing the following:
- Make
getEntity()
return by reference. - Alter
__get()
to raise anE_USER_DEPRECATED
, and then proxy to the appropriate getter.
If you do those changes, I will merge.
Added changes to make this pull request backwards compatible according to suggestions by @weierophinney - Make getEntity() return by reference. - Alter __get() to raise an E_USER_DEPRECATED, and then proxy to the appropriate getter. Hope this is what you were thinking off.
Made a mistake in returning by reference from `getEnitity` method.
@weierophinney I synched this branch with master. Will it still be merged? |
weierophinney
added a commit
that referenced
this pull request
Jul 6, 2016
Getters instead of magic __get in Hal\Entity
weierophinney
added a commit
that referenced
this pull request
Jul 6, 2016
- Tests were not updated to use new accessors; fixed. - Added new test to ensure deprecation notice is now emitted from Entity instances.
weierophinney
added a commit
that referenced
this pull request
Jul 6, 2016
weierophinney
added a commit
that referenced
this pull request
Jul 6, 2016
Merged to develop for release with 1.4.0. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the
Hal\Collection
class the magic__get
for collection has been deprecated and now thegetCollection
method has to be called instead.For consistency would it not be better to also use similar solution for the
Hal\Entity
class.So
getEntity
andgetId
methodsThis pull request is related to zfcampus/zf-rest#70