/** * Generate a list of routes available fo the specified method. * * @param ReflectionMethod $methodReflection * @return array */ public function generateRestRoutes(ReflectionMethod $methodReflection) { $routes = array(); $routePath = "/:" . Mage_Webapi_Controller_Router_Route_Rest::PARAM_VERSION; $routeParts = $this->_helper->getResourceNameParts($methodReflection->getDeclaringClass()->getName()); $partsCount = count($routeParts); for ($i = 0; $i < $partsCount; $i++) { if ($this->_isParentResourceIdExpected($methodReflection) && $i == $partsCount - 1) { $routePath .= "/:" . Mage_Webapi_Controller_Router_Route_Rest::PARAM_PARENT_ID; } $routePath .= "/" . lcfirst($this->_helper->convertSingularToPlural($routeParts[$i])); } if ($this->_isResourceIdExpected($methodReflection)) { $routePath .= "/:" . Mage_Webapi_Controller_Router_Route_Rest::PARAM_ID; } foreach ($this->_getAdditionalRequiredParamNames($methodReflection) as $additionalRequired) { $routePath .= "/{$additionalRequired}/:{$additionalRequired}"; } $actionType = Mage_Webapi_Controller_Request_Rest::getActionTypeByOperation($this->_helper->getMethodNameWithoutVersionSuffix($methodReflection)); $resourceName = $this->_helper->translateResourceName($methodReflection->getDeclaringClass()->getName()); $optionalParams = $this->_getOptionalParamNames($methodReflection); foreach ($this->_getPathCombinations($optionalParams, $routePath) as $finalRoutePath) { $routes[$finalRoutePath] = array('actionType' => $actionType, 'resourceName' => $resourceName); } $this->_routes = array_merge($this->_routes, $routes); return $routes; }
/** * @dataProvider dataProviderForTestConvertSingularToPlural */ public function testConvertSingularToPlural($singular, $expectedPlural) { $this->assertEquals($expectedPlural, $this->_helper->convertSingularToPlural($singular), "Conversion from singular to plural was performed incorrectly."); }