/** * 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; }
/** * Retrieve a list of all route objects associated with specified method. * * @param string $resourceName * @param string $methodName * @param string $version * @return Mage_Webapi_Controller_Router_Route_Rest[] * @throws InvalidArgumentException */ public function getMethodRestRoutes($resourceName, $methodName, $version) { $resourceData = $this->_getResourceData($resourceName, $version); if (!isset($resourceData['methods'][$methodName]['rest_routes'])) { throw new InvalidArgumentException(sprintf('The "%s" resource does not have any REST routes for "%s" method.', $resourceName, $methodName)); } $routes = array(); foreach ($resourceData['methods'][$methodName]['rest_routes'] as $routePath) { $routes[] = $this->_createRoute($routePath, $resourceName, Mage_Webapi_Controller_Request_Rest::getActionTypeByOperation($methodName)); } return $routes; }
public function testGetActionTypeException() { $methodName = 'invalidMethodV1'; $this->setExpectedException('InvalidArgumentException', sprintf('The "%s" method is not a valid resource method.', $methodName)); Mage_Webapi_Controller_Request_Rest::getActionTypeByOperation($methodName); }