/** * Gets the appropriate callback name to use for a given request. * * @param Request $request the request to check for * * @return string the callback name */ public function getRequestCallbackName(Request $request) { if ($this->allowCustomCallback) { return $request->getParam('jsonp', $request->getParam('callback', $this->callbackName)); } else { return $this->callbackName; } }
/** * Parse the given input and return either an array of attributes => values * or null if the input could not be parsed. * * @param Request $request the request object * * @return array|null */ public function parse(Request $request) { $input = $request->getRawBody(); if (empty($input)) { return null; } return $this->xmlToArray($input); }
/** * Parse the given input and return either an array of attributes => values * or null if the input could not be parsed. * * @param Request $request the request object * * @return array|null */ public function parse(Request $request) { if ($request->getIsPostRequest()) { $data = count($_POST) ? $_POST : array(); foreach ($_FILES as $name => $file) { $data[$name] = \CUploadedFile::getInstanceByName($name); } return $data === array() ? null : $data; } else { if ($request->getIsPutRequest()) { $data = $request->getRestParams(); return $data && count($data) ? $data : null; } else { return null; } } }
/** * Predicate that determines whether the requested accept * types match this mime type. * * @param Request $request the request object to check * * @return bool true if the accept header matches */ public function matchAcceptTypes(Request $request) { $acceptTypes = $request->getPreferredAcceptTypes(); foreach ($acceptTypes as $preferredType) { $preferredString = $preferredType['type']; if (!empty($preferredType['subType'])) { $preferredString .= '/' . $preferredType['subType']; } if (!empty($preferredType['baseType'])) { $preferredString .= '+' . $preferredType['baseType']; } foreach ($this->mimeTypes as $type) { if (strcasecmp($type, $preferredString) === 0) { return true; } } } return false; }
/** * Override the default implementation to return a routing object when passed a string instead of a request object. * @param \CHttpRequest|string $url the request or string to parse * @param string|null $verb the http verb to assume when parsing string urls * * @return array|bool|string false if the request or url could not be parsed, otherwise the route or routing object */ public function parseUrl($url, $verb = 'GET') { if (!is_string($url)) { return parent::parseUrl($url); } $request = new Request(); $request->setRequestType($verb); $request->setUrl($url); $oldGET = $_GET; $oldREQUEST = $_REQUEST; $_GET = array(); $parsed = parent::parseUrl($request); $params = $_GET; $_GET = $oldGET; $_REQUEST = $oldREQUEST; if ($parsed === false) { return false; } array_unshift($params, $parsed); return $params; }
/** * Parse the given input and return either an array of attributes => values * or null if the input could not be parsed. * * @param Request $request the request object * * @return array|null */ public function parse(Request $request) { $input = $request->getRawBody(); if (empty($input)) { return null; } ini_set('auto_detect_line_endings', true); $stream = fopen('php://memory', 'r+'); fwrite($stream, $input); rewind($stream); $data = array(); $names = null; $totalRows = 0; while (($row = fgetcsv($stream, 4096, $this->delimiter, $this->enclosure)) !== false) { if ($names === null) { $names = $row; } else { $item = array(); foreach ($row as $key => $value) { if (!isset($names[$key])) { break; } $item[$names[$key]] = $value; } $data[] = $item; $totalRows++; } } fclose($stream); if ($totalRows === 0) { return null; } if ($totalRows === 1) { $data = $data[0]; } return $data; }
/** * Parse the given input and return either an array of attributes => values * or null if the input could not be parsed. * * @param Request $request the request object * * @return array|null */ public function parse(Request $request) { $data = json_decode($request->getRawBody(), true); return $data ? $data : null; }