示例#1
0
 /**
  * Handle REST request.
  *
  * @return Mage_Webapi_Controller_Dispatcher_Rest
  */
 public function dispatch()
 {
     try {
         $this->_authentication->authenticate();
         $route = $this->_router->match($this->_request);
         $operation = $this->_request->getOperationName();
         $resourceVersion = $this->_request->getResourceVersion();
         $this->_apiConfig->validateVersionNumber($resourceVersion, $this->_request->getResourceName());
         $method = $this->_apiConfig->getMethodNameByOperation($operation, $resourceVersion);
         $controllerClassName = $this->_apiConfig->getControllerClassByOperationName($operation);
         $controllerInstance = $this->_controllerFactory->createActionController($controllerClassName, $this->_request);
         $versionAfterFallback = $this->_apiConfig->identifyVersionSuffix($operation, $resourceVersion, $controllerInstance);
         /**
          * Route check has two stages:
          * The first is performed against full list of routes that is merged from all resources.
          * The second stage of route check can be performed only when actual version to be executed is known.
          */
         $this->_router->checkRoute($this->_request, $method, $versionAfterFallback);
         $this->_apiConfig->checkDeprecationPolicy($route->getResourceName(), $method, $versionAfterFallback);
         $action = $method . $versionAfterFallback;
         $this->_authorization->checkResourceAcl($route->getResourceName(), $method);
         $inputData = $this->_restPresentation->fetchRequestData($controllerInstance, $action);
         $outputData = call_user_func_array(array($controllerInstance, $action), $inputData);
         $this->_restPresentation->prepareResponse($method, $outputData);
     } catch (Exception $e) {
         $this->_response->setException($e);
     }
     $this->_response->sendResponse();
     return $this;
 }
示例#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;
 }
示例#3
0
 /**
  * Check whether current request matches any route of specified method or not. Method version is taken into account.
  *
  * @param Mage_Webapi_Controller_Request_Rest $request
  * @param string $methodName
  * @param string $version
  * @throws Mage_Webapi_Exception In case when request does not match any route of specified method.
  */
 public function checkRoute(Mage_Webapi_Controller_Request_Rest $request, $methodName, $version)
 {
     $resourceName = $request->getResourceName();
     $routes = $this->_apiConfig->getMethodRestRoutes($resourceName, $methodName, $version);
     foreach ($routes as $route) {
         if ($route->match($request)) {
             return;
         }
     }
     throw new Mage_Webapi_Exception($this->_helper->__('Request does not match any route.'), Mage_Webapi_Exception::HTTP_NOT_FOUND);
 }