-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add ArrayCollection map() method capability to access inner array key #221
base: 2.0.x
Are you sure you want to change the base?
Conversation
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.
Please adjust commit message (to explain what is being done), PR title and tests (required)
I think you should also update PHPDoc for the |
I don't think we should update the documentation for the |
I always thought that ArrayCollection is just an implementation of original Collection interface, and in general it shouldn't add more functionality than declared by the original interface. Because e.g. i have /** @Entity */
class User
{
/** @OneToMany(...) */
private $comments;
public function __construct()
{
$this->comments = new ArrayCollection();
}
public function getCommentStats(): Collection
{
return $this->comments->map(function ($value, $key) {
return new CommentStatistics($key, $value);
});
}
} I expect that |
There's a BC problem here if we move it to Specifically, the signature is currently something like If we change it to If we don't change it, then I don't have a solution for now, but I hope this explains the problem. |
This PR targets master so it shouldn't be a problem afaik. |
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.
Fixed PHPDoc misstype
Please improve your commit message according to the contributing guide. Please kindly squash your commits together. If you don't, we'll try to remember to do it for you but it's best if you save us this trouble. How to do that?
|
Oh sorry. This is my first PR. I never do it before ( Im very newbie ). I just do it the modifications at Github, not in my local, so I don't know if I can do the rebase at the web page. What should I do now? I have to clone the repository then? P.S: For future commits and PR I'll keep in my mind the procedure to make a proper PR. Thanks in advance |
I can totally do it for you if you don't feel comfortable jumping through the following hoops:
|
Ok, thank you so much. I'll do it right now and see what happens :) 👍 |
This enhancement gives to map() Closure the capability to access also the keys of the inner array holding the elements. Until now, we were able to access just the element on map Closure but not the key. So I propose to add the ability to access also the key for do some statements inside the Closure with key related. I have the need to add it since in my project I must get the asociative key to take a decision in function of the current key element and I thought that may be usefull for everyone in some other projects to access the key of current processing element.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
If we add keys to the map method, maybe the key should be the first param to add consistency with others methods. |
This seems stalled, I'm removing it from the 2.0.0 milestone. |
This enhancement gives to map() Closure the capability to access also the keys of the inner array holding the elements. Until now, we were able to access just the element on map Closure but not the key. So I propose to add the ability to access also the key for do some statements inside the Closure with key related.
I have the need to add it since in my project I must get the asociative key to take a decision in function of the current key element and I thought that may be usefull for everyone in some other projects to access the key of current processing element