Scalr\Api\Rest\Http\Request::post PHP Method

post() public method

Gets POST data
public post ( string $key = null, string $default = null ) : mixed
$key string optional Variable name
$default string optional Default value for the variable
return mixed Returns variable value
    public function post($key = null, $default = null)
    {
        if (!isset($this->env['request.post'])) {
            if ($this->isJsonData() && !empty($this->env['raw.body'])) {
                $this->env['request.post'] = @json_decode(trim($this->env['raw.body']));
            } else {
                if ($this->isFormData() && is_string($this->env['raw.body'])) {
                    $data = [];
                    if (function_exists('mb_parse_str')) {
                        mb_parse_str($this->env['raw.body'], $data);
                    } else {
                        parse_str($this->env['raw.body'], $data);
                    }
                    $this->env['request.post'] = $data;
                } else {
                    $this->env['request.post'] = $_POST;
                }
            }
        }
        if ($key !== null) {
            if (is_object($this->env['request.post'])) {
                return isset($this->env['request.post']->{$key}) ? $this->env['request.post']->{$key} : $default;
            } else {
                return isset($this->env['request.post'][$key]) ? $this->env['request.post'][$key] : $default;
            }
        } else {
            return $this->env['request.post'];
        }
    }