Skip to content

Instantly share code, notes, and snippets.

@Bendihossan
Last active December 10, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bendihossan/bd08ec2488eb816c561d to your computer and use it in GitHub Desktop.
Save Bendihossan/bd08ec2488eb816c561d to your computer and use it in GitHub Desktop.
Suggested modification to generateRouteName() function from RestActionReader.php (FosRestBundle) to fix a bug.
<?php
/**
* Generates route name from resources list.
*
* @param array $resources
* @param \ReflectionMethod $method
*
* @return string
*/
private function generateRouteName(array $resources, \ReflectionMethod $method)
{
$routeName = '';
foreach ($resources as $resource) {
if (null !== $resource) {
// Checks if the resource is an uncountable word and if the method call is a collection get action.
if ($method->name == 'cgetAction'
&& true == in_array(strtolower($resource), Pluralization::$uncountables)
) {
// If both are true then we add '_collection' to the route name to
// avoid a potential duplicate with the get action for a single resource.
$routeName .= '_collection';
}
$routeName .= '_' . basename($resource);
}
}
return $routeName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment