original_string: public function handleQuery(HTTPRequest $request)
      {
          //get requested model(s) details
          $model = $request->param('ModelReference');
  
          $modelMap = Config::inst()->get(self::class, 'models');
  
          if (array_key_exists($model, $modelMap)) {
              $model = $modelMap[$model];
          }
  
          $id = $request->param('ID');
          $response = false;
          $queryParams = $this->parseQueryParameters($request->getVars());
  
          //validate Model name + store
          if ($model) {
              $model = $this->deSerializer->unformatName($model);
              if (!class_exists($model)) {
                  return new RESTfulAPIError(400,
                      "Model does not exist. Received '$model'."
                  );
              } else {
                  //store requested model data and query data
                  $this->requestedData['model'] = $model;
              }
          } else {
              //if model missing, stop + return blank object
              return new RESTfulAPIError(400,
                  "Missing Model parameter."
              );
          }
  
          //check API access rules on model
          if (!RESTfulAPI::api_access_control($model, $request->httpMethod())) {
              return new RESTfulAPIError(403,
                  "API access denied."
              );
          }
  
          //validate ID + store
          if (($request->isPUT() || $request->isDELETE()) && !is_numeric($id)) {
              return new RESTfulAPIError(400,
                  "Invalid or missing ID. Received '$id'."
              );
          } elseif ($id !== null && !is_numeric($id)) {
              return new RESTfulAPIError(400,
                  "Invalid ID. Received '$id'."
              );
          } else {
              $this->requestedData['id'] = $id;
          }
  
          //store query parameters
          if ($queryParams) {
              $this->requestedData['params'] = $queryParams;
          }
  
          //map HTTP word to module method
          switch ($request->httpMethod()) {
              case 'GET':
                  return $this->findModel($model, $id, $queryParams, $request);
                  break;
              case 'POST':
                  return $this->createModel($model, $request);
                  break;
              case 'PUT':
                  return $this->updateModel($model, $id, $request);
                  break;
              case 'DELETE':
                  return $this->deleteModel($model, $id, $request);
                  break;
              default:
                  return new RESTfulAPIError(403,
                      "HTTP method mismatch."
                  );
                  break;
          }
      }
code: public function handleQuery(HTTPRequest $request)
      {
          //get requested model(s) details
          $model = $request->param('ModelReference');
  
          $modelMap = Config::inst()->get(self::class, 'models');
  
          if (array_key_exists($model, $modelMap)) {
              $model = $modelMap[$model];
          }
  
          $id = $request->param('ID');
          $response = false;
          $queryParams = $this->parseQueryParameters($request->getVars());
  
          //validate Model name + store
          if ($model) {
              $model = $this->deSerializer->unformatName($model);
              if (!class_exists($model)) {
                  return new RESTfulAPIError(400,
                      "Model does not exist. Received '$model'."
                  );
              } else {
                  //store requested model data and query data
                  $this->requestedData['model'] = $model;
              }
          } else {
              //if model missing, stop + return blank object
              return new RESTfulAPIError(400,
                  "Missing Model parameter."
              );
          }
  
          //check API access rules on model
          if (!RESTfulAPI::api_access_control($model, $request->httpMethod())) {
              return new RESTfulAPIError(403,
                  "API access denied."
              );
          }
  
          //validate ID + store
          if (($request->isPUT() || $request->isDELETE()) && !is_numeric($id)) {
              return new RESTfulAPIError(400,
                  "Invalid or missing ID. Received '$id'."
              );
          } elseif ($id !== null && !is_numeric($id)) {
              return new RESTfulAPIError(400,
                  "Invalid ID. Received '$id'."
              );
          } else {
              $this->requestedData['id'] = $id;
          }
  
          //store query parameters
          if ($queryParams) {
              $this->requestedData['params'] = $queryParams;
          }
  
          //map HTTP word to module method
          switch ($request->httpMethod()) {
              case 'GET':
                  return $this->findModel($model, $id, $queryParams, $request);
                  break;
              case 'POST':
                  return $this->createModel($model, $request);
                  break;
              case 'PUT':
                  return $this->updateModel($model, $id, $request);
                  break;
              case 'DELETE':
                  return $this->deleteModel($model, $id, $request);
                  break;
              default:
                  return new RESTfulAPIError(403,
                      "HTTP method mismatch."
                  );
                  break;
          }
      }
code_tokens: public function handleQuery ( HTTPRequest $ request ) { //get requested model(s) details $ model = $ request -> param ( 'ModelReference' ) ; $ modelMap = Config :: inst ( ) -> get ( self :: class , 'models' ) ; if ( array_key_exists ( $ model , $ modelMap ) ) { $ model = $ modelMap [ $ model ] ; } $ id = $ request -> param ( 'ID' ) ; $ response = false ; $ queryParams = $ this -> parseQueryParameters ( $ request -> getVars ( ) ) ; //validate Model name + store if ( $ model ) { $ model = $ this -> deSerializer -> unformatName ( $ model ) ; if ( ! class_exists ( $ model ) ) { return new RESTfulAPIError ( 400 , "Model does not exist. Received '$model'." ) ; } else { //store requested model data and query data $ this -> requestedData [ 'model' ] = $ model ; } } else { //if model missing, stop + return blank object return new RESTfulAPIError ( 400 , "Missing Model parameter." ) ; } //check API access rules on model if ( ! RESTfulAPI :: api_access_control ( $ model , $ request -> httpMethod ( ) ) ) { return new RESTfulAPIError ( 403 , "API access denied." ) ; } //validate ID + store if ( ( $ request -> isPUT ( ) || $ request -> isDELETE ( ) ) && ! is_numeric ( $ id ) ) { return new RESTfulAPIError ( 400 , "Invalid or missing ID. Received '$id'." ) ; } elseif ( $ id !== null && ! is_numeric ( $ id ) ) { return new RESTfulAPIError ( 400 , "Invalid ID. Received '$id'." ) ; } else { $ this -> requestedData [ 'id' ] = $ id ; } //store query parameters if ( $ queryParams ) { $ this -> requestedData [ 'params' ] = $ queryParams ; } //map HTTP word to module method switch ( $ request -> httpMethod ( ) ) { case 'GET' : return $ this -> findModel ( $ model , $ id , $ queryParams , $ request ) ; break ; case 'POST' : return $ this -> createModel ( $ model , $ request ) ; break ; case 'PUT' : return $ this -> updateModel ( $ model , $ id , $ request ) ; break ; case 'DELETE' : return $ this -> deleteModel ( $ model , $ id , $ request ) ; break ; default : return new RESTfulAPIError ( 403 , "HTTP method mismatch." ) ; break ; } }
docstring: All requests pass through here and are redirected depending on HTTP verb and params
  
  @param  HTTPRequest        $request    HTTP request
  @return DataObjec|DataList                DataObject/DataList result or stdClass on error
docstring_tokens: All requests pass through here and are redirected depending on HTTP verb and params