Esempio n. 1
0
 /**
  * Create route object.
  *
  * @param string $routePath
  * @param string $resourceName
  * @param string $actionType
  * @return Mage_Webapi_Controller_Router_Route_Rest
  */
 protected function _createRoute($routePath, $resourceName, $actionType)
 {
     $apiTypeRoutePath = Mage_Webapi_Controller_Router_Route_Webapi::API_AREA_NAME . '/:' . Mage_Webapi_Controller_Front::API_TYPE_REST;
     $fullRoutePath = $apiTypeRoutePath . $routePath;
     /** @var $route Mage_Webapi_Controller_Router_Route_Rest */
     $route = $this->_routeFactory->createRoute('Mage_Webapi_Controller_Router_Route_Rest', $fullRoutePath);
     $route->setResourceName($resourceName)->setResourceType($actionType);
     return $route;
 }
Esempio n. 2
0
 /**
  * Generate resource location.
  *
  * @param Mage_Core_Model_Abstract $createdItem
  * @return string URL
  */
 protected function _getCreatedItemLocation($createdItem)
 {
     $apiTypeRoute = $this->_routeFactory->createRoute('Mage_Webapi_Controller_Router_Route_Webapi', Mage_Webapi_Controller_Router_Route_Webapi::getApiRoute());
     $resourceName = $this->_request->getResourceName();
     $routeToItem = $this->_routeFactory->createRoute('Zend_Controller_Router_Route', $this->_apiConfig->getRestRouteToItem($resourceName));
     $chain = $apiTypeRoute->chain($routeToItem);
     $params = array(Mage_Webapi_Controller_Router_Route_Webapi::PARAM_API_TYPE => $this->_request->getApiType(), Mage_Webapi_Controller_Router_Route_Rest::PARAM_ID => $createdItem->getId(), Mage_Webapi_Controller_Router_Route_Rest::PARAM_VERSION => $this->_request->getResourceVersion());
     $uri = $chain->assemble($params);
     return '/' . $uri;
 }
Esempio n. 3
0
 /**
  * Determine current API type using application request (not web API request).
  *
  * @return string
  * @throws Mage_Core_Exception
  * @throws Mage_Webapi_Exception If requested API type is invalid.
  */
 public function determineApiType()
 {
     if (is_null($this->_apiType)) {
         $request = $this->_application->getRequest();
         $apiRoute = $this->_routeFactory->createRoute('Mage_Webapi_Controller_Router_Route_Webapi', Mage_Webapi_Controller_Router_Route_Webapi::getApiRoute());
         if (!($apiTypeMatch = $apiRoute->match($request, true))) {
             throw new Mage_Webapi_Exception($this->_helper->__('Request does not match any API type route.'), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
         }
         $apiType = $apiTypeMatch[Mage_Webapi_Controller_Router_Route_Webapi::PARAM_API_TYPE];
         if (!in_array($apiType, $this->getListOfAvailableApiTypes())) {
             throw new Mage_Webapi_Exception($this->_helper->__('The "%s" API type is not defined.', $apiType), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
         }
         $this->_apiType = $apiType;
     }
     return $this->_apiType;
 }