_isJsonApi = true; } // parse parameters, depending on request type switch (array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'GET') { case 'PUT': parse_str(file_get_contents($this->_inputStream), $this->_params); break; case 'POST': $this->_params = $_POST; break; default: $this->_params = $_GET; } // prepare paremeters, depending on current operation if ( (array_key_exists('data', $this->_params) && !empty($this->_params['data'])) || (array_key_exists('attachment', $this->_params) && !empty($this->_params['attachment'])) ) { $this->_operation = 'create'; } elseif ( array_key_exists('pasteid', $this->_params) && !empty($this->_params['pasteid']) && array_key_exists('deletetoken', $this->_params) && !empty($this->_params['deletetoken']) ) { $this->_operation = 'delete'; } // display an existing paste elseif (array_key_exists('QUERY_STRING', $_SERVER) && !empty($_SERVER['QUERY_STRING'])) { $this->_operation = 'read'; $this->_params['pasteid'] = $_SERVER['QUERY_STRING']; } } /** * Get current operation. * * @access public * @return string */ public function getOperation() { return $this->_operation; } /** * Get a request parameter. * * @access public * @param string $param * @param string $default * @return string */ public function getParam($param, $default = '') { return array_key_exists($param, $this->_params) ? $this->_params[$param] : $default; } /** * If we are in a JSON API context. * * @access public * @return bool */ public function isJsonApiCall() { return $this->_isJsonApi; } /** * Override the default input stream source * * @param unknown $input */ public function setInputStream($input) { $this->_inputStream = $input; $this->__construct(); } }