Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider dataProviderForTestGetResourceNameParts
  * @param $className
  * @param $expectedParts
  */
 public function testGetResourceNameParts($className, $expectedParts)
 {
     $this->assertEquals($expectedParts, $this->_helper->getResourceNameParts($className), "Resource parts for rest route were identified incorrectly.");
 }