Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Getters instead of magic __get in Hal\Entity #99

Closed
wants to merge 10 commits into from

Conversation

Wilt
Copy link
Contributor

@Wilt Wilt commented Apr 8, 2015

In the Hal\Collection class the magic __get for collection has been deprecated and now the getCollection 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 and getId methods

This pull request is related to zfcampus/zf-rest#70

Wilt added 7 commits April 8, 2015 16:43
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`?
@Wilt
Copy link
Contributor Author

Wilt commented Apr 9, 2015

I realize now that the magic __get in Hal\Entity is by reference:

    public function &__get($name)
    {
        ...
    }

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.

@weierophinney
Copy link
Member

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.');
Copy link
Member

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 an E_USER_DEPRECATED, and then proxy to the appropriate getter.

If you do those changes, I will merge.

Wilt and others added 3 commits July 2, 2015 09:23
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.
@Wilt
Copy link
Contributor Author

Wilt commented Mar 17, 2016

@weierophinney I synched this branch with master. Will it still be merged?

@weierophinney weierophinney added this to the 1.4.0 milestone Jul 6, 2016
@weierophinney weierophinney self-assigned this Jul 6, 2016
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
@weierophinney
Copy link
Member

Merged to develop for release with 1.4.0.

@Wilt Wilt deleted the patch-6 branch July 7, 2016 07:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants