summaryrefslogtreecommitdiff
path: root/core/request.php
blob: b2c3e12e90911fc0965fa328ffdac5cd80711e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

namespace Core;

class Request
{
    public function getStringParam($name, $default_value = '')
    {
        return isset($_GET[$name]) ? $_GET[$name] : $default_value;
    }

    public function getIntegerParam($name, $default_value = 0)
    {
        return isset($_GET[$name]) && ctype_digit($_GET[$name]) ? (int) $_GET[$name] : $default_value;
    }

    public function getValue($name)
    {
        $values = $this->getValues();
        return isset($values[$name]) ? $values[$name] : null;
    }

    public function getValues()
    {
        if (! empty($_POST)) return $_POST;

        $result = json_decode($this->getBody(), true);
        if ($result) return $result;

        return array();
    }

    public function getBody()
    {
        return file_get_contents('php://input');
    }

    public function getFileContent($name)
    {
        if (isset($_FILES[$name])) {
            return file_get_contents($_FILES[$name]['tmp_name']);
        }

        return '';
    }
}