/**
  * @param Request $request
  *
  * @return Request
  */
 public function beforeSend(Request $request)
 {
     $headers = array(self::X_AUTH_KEY => $this->data_store->getClientV4APIKey(), self::X_AUTH_EMAIL => $this->data_store->getCloudFlareEmail(), self::CONTENT_TYPE_KEY => self::APPLICATION_JSON_KEY);
     $request->setHeaders($headers);
     // Remove cfCSRFToken (a custom header) to save bandwidth
     $body = $request->getBody();
     $body['cfCSRFToken'] = null;
     $request->setBody($body);
     return $request;
 }
 /**
  * @param Request $request
  *
  * @return array|bool
  */
 public function getRoute(Request $request)
 {
     /*
      * This method allows CPanel to hook into our API calls that require Cpanel specific functionality.
      * Be VERY careful editing it, make sure you're code only fires for the specific API call you need to interact with.
      */
     //Load up our routes and replace their placeholders (i.e. :id changes to [0-9a-z]{32})
     foreach ($this->routes as $routeKey => $route_details_array) {
         //Replace placeholders in route
         $regex = str_replace(array_keys(static::$API_ROUTING_PLACEHOLDERS), array_values(static::$API_ROUTING_PLACEHOLDERS), $routeKey);
         //Check to see if this is our route
         if (preg_match('#^' . $regex . '/?$#', $request->getUrl())) {
             if (in_array($request->getMethod(), $route_details_array['methods']) || array_key_exists($request->getMethod(), $route_details_array['methods'])) {
                 $this->logger->debug('Route matched for ' . $request->getMethod() . $request->getUrl() . ' now using ' . $route_details_array['methods'][$request->getMethod()]['function']);
                 return array('class' => $route_details_array['class'], 'function' => $route_details_array['methods'][$request->getMethod()]['function']);
             }
         }
     }
     //if no route was found call our API normally
     return false;
 }
 public function shouldRouteRequest(Request $request)
 {
     return strpos($request->getUrl(), $this->getEndpoint()) !== false;
 }