sensiolabs/SensioFrameworkExtraBundle — pull request #271 by tvlooy (2014-01-20 20:07:21+00:00)
Title: Repository method with arguments

Example:

I have set this:

/**
* @ParamConverter(
* "post",
* class="AcmeBlogBundle:Post",
* options={
* "repository_method" = "findForCreationDateAndLink",
* "mapping": {"year": "year", "month": "month", "day": "day", "permalink": "permalink"}
* }
* )
*/

My repository method looks like this:

public function findForYmdLink($year, $month, $day, $permalink)
{
$creationDate = \DateTime::createFromFormat('Ymd', $year.$month.$day);

return $this->findOneBy(array(
'creationDate' => $creationDate,
'permalink' => $permalink,
'published' => true,
));
}

My Post entity doesn't have the fields day, month and year but has creationDate instead (DateTime). The current implementation of the converter doesn't pass the 3 fields because they are not in the metadata. I don't see why they should be if I pass a custom repository_method. This patch changes that behaviour.

With the current implementation, I would also have to change the repository method to this:

public function findForYmdLink($params)
{
list($year, $month, $day, $permalink) = $params;
...

This patch changes that behaviour by calling invokeArgs on the reflectionMethod so the exact parameters are in the method signature.