| <?php |
|
|
| namespace Kanboard\Core\Http; |
|
|
| use Pimple\Container; |
| use Kanboard\Core\Base; |
|
|
| |
| |
| |
| |
| |
| |
| class Request extends Base |
| { |
| |
| |
| |
| |
| |
| |
| private $server; |
| private $get; |
| private $post; |
| private $files; |
| private $cookies; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function __construct(Container $container, array $server = array(), array $get = array(), array $post = array(), array $files = array(), array $cookies = array()) |
| { |
| parent::__construct($container); |
| $this->server = empty($server) ? $_SERVER : $server; |
| $this->get = empty($get) ? $_GET : $get; |
| $this->post = empty($post) ? $_POST : $post; |
| $this->files = empty($files) ? $_FILES : $files; |
| $this->cookies = empty($cookies) ? $_COOKIE : $cookies; |
| } |
|
|
| |
| |
| |
| |
| |
| public function setParams(array $params) |
| { |
| $this->get = array_merge($this->get, $params); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function getStringParam($name, $default_value = '') |
| { |
| return isset($this->get[$name]) ? $this->get[$name] : $default_value; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function getIntegerParam($name, $default_value = 0) |
| { |
| return isset($this->get[$name]) && ctype_digit((string) $this->get[$name]) ? (int) $this->get[$name] : $default_value; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getValue($name) |
| { |
| $values = $this->getValues(); |
| return isset($values[$name]) ? $values[$name] : null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getValues() |
| { |
| if (! empty($this->post) && ! empty($this->post['csrf_token']) && $this->token->validateCSRFToken($this->post['csrf_token'])) { |
| unset($this->post['csrf_token']); |
| return $this->filterValues($this->post); |
| } |
|
|
| return array(); |
| } |
|
|
| |
| |
| |
| |
| |
| public function getRawFormValues() |
| { |
| return $this->post; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getRawValue($name) |
| { |
| return isset($this->post[$name]) ? $this->post[$name] : null; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getBody() |
| { |
| return file_get_contents('php://input'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getJson() |
| { |
| return json_decode($this->getBody(), true) ?: array(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getFileContent($name) |
| { |
| if (isset($this->files[$name]['tmp_name'])) { |
| return file_get_contents($this->files[$name]['tmp_name']); |
| } |
|
|
| return ''; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getFilePath($name) |
| { |
| return isset($this->files[$name]['tmp_name']) ? $this->files[$name]['tmp_name'] : ''; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getFileInfo($name) |
| { |
| return isset($this->files[$name]) ? $this->files[$name] : array(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getMethod() |
| { |
| return $this->getServerVariable('REQUEST_METHOD'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function isPost() |
| { |
| return $this->getServerVariable('REQUEST_METHOD') === 'POST'; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function isAjax() |
| { |
| return $this->getHeader('X-Requested-With') === 'XMLHttpRequest'; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function isHTTPS() |
| { |
| if ($this->getServerVariable('HTTP_X_FORWARDED_PROTO') === 'https') { |
| return true; |
| } |
|
|
| return $this->getServerVariable('HTTPS') !== '' && $this->server['HTTPS'] !== 'off'; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getCookie($name) |
| { |
| return isset($this->cookies[$name]) ? $this->cookies[$name] : ''; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getHeader($name) |
| { |
| $name = 'HTTP_'.str_replace('-', '_', strtoupper($name)); |
| return $this->getServerVariable($name); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getRemoteUser() |
| { |
| return $this->getServerVariable(REVERSE_PROXY_USER_HEADER); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getRemoteEmail() |
| { |
| return $this->getServerVariable(REVERSE_PROXY_EMAIL_HEADER); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getRemoteName() |
| { |
| return $this->getServerVariable(REVERSE_PROXY_FULLNAME_HEADER); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getQueryString() |
| { |
| return $this->getServerVariable('QUERY_STRING'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getUri() |
| { |
| return $this->getServerVariable('REQUEST_URI'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getUserAgent() |
| { |
| return empty($this->server['HTTP_USER_AGENT']) ? t('Unknown') : $this->server['HTTP_USER_AGENT']; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getIpAddress() |
| { |
| $keys = array( |
| 'HTTP_X_REAL_IP', |
| 'HTTP_CLIENT_IP', |
| 'HTTP_X_FORWARDED_FOR', |
| 'HTTP_X_FORWARDED', |
| 'HTTP_X_CLUSTER_CLIENT_IP', |
| 'HTTP_FORWARDED_FOR', |
| 'HTTP_FORWARDED', |
| 'REMOTE_ADDR' |
| ); |
|
|
| foreach ($keys as $key) { |
| if ($this->getServerVariable($key) !== '') { |
| foreach (explode(',', $this->server[$key]) as $ipAddress) { |
| return trim($ipAddress); |
| } |
| } |
| } |
|
|
| return t('Unknown'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getStartTime() |
| { |
| return $this->getServerVariable('REQUEST_TIME_FLOAT') ?: 0; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getServerVariable($variable) |
| { |
| return isset($this->server[$variable]) ? $this->server[$variable] : ''; |
| } |
|
|
| protected function filterValues(array $values) |
| { |
| foreach ($values as $key => $value) { |
|
|
| |
| if (strpos($key, '-----------------------------') === 0) { |
| unset($values[$key]); |
| } |
| } |
|
|
| return $values; |
| } |
| } |
|
|