PHPDaemon\HTTPRequest\Generic::postPrepare PHP Method

postPrepare() public method

Prepares the request body
public postPrepare ( ) : void
return void
    public function postPrepare()
    {
        if (!$this->attrs->server['REQUEST_METHOD_POST']) {
            return;
        }
        if (isset($this->attrs->server['REQUEST_PREPARED_UPLOADS']) && $this->attrs->server['REQUEST_PREPARED_UPLOADS'] === 'nginx') {
            if (isset($this->attrs->server['REQUEST_PREPARED_UPLOADS_URL_PREFIX'])) {
                $URLprefix = $this->attrs->server['REQUEST_PREPARED_UPLOADS_URL_PREFIX'];
                $l = mb_orig_strlen($URLprefix);
                foreach (['PHP_SELF', 'REQUEST_URI', 'SCRIPT_NAME', 'DOCUMENT_URI'] as $k) {
                    if (!isset($this->attrs->server[$k])) {
                        continue;
                    }
                    if (strncmp($this->attrs->server[$k], $URLprefix, $l) === 0) {
                        $this->attrs->server[$k] = substr($this->attrs->server[$k], $l - 1);
                    }
                }
            }
            $prefix = 'file.';
            $prefixlen = mb_orig_strlen($prefix);
            foreach ($this->attrs->post as $k => $v) {
                if (strncmp($k, $prefix, $prefixlen) === 0) {
                    $e = explode('.', substr($k, $prefixlen));
                    if (!isset($e[1])) {
                        $e = ['file', $e[0]];
                    }
                    if (!isset($this->attrs->files[$e[0]])) {
                        $this->attrs->files[$e[0]] = ['error' => UPLOAD_ERR_OK];
                    }
                    $this->attrs->files[$e[0]][$e[1]] = $v;
                    unset($this->attrs->post[$k]);
                }
            }
            $uploadTmp = $this->getUploadTempDir();
            foreach ($this->attrs->files as $k => &$file) {
                if (!isset($file['tmp_name']) || !isset($file['name']) || !ctype_digit(basename($file['tmp_name'])) || mb_orig_strpos(pathinfo($file['tmp_name'], PATHINFO_DIRNAME), $uploadTmp) !== 0) {
                    unset($this->attrs->files[$k]);
                    continue;
                }
                FileSystem::open($file['tmp_name'], 'c+!', function ($fp) use(&$file) {
                    if (!$fp) {
                        return;
                    }
                    $file['fp'] = $fp;
                });
            }
            unset($file);
        }
        if (isset($this->attrs->server['REQUEST_BODY_FILE']) && $this->upstream->pool->config->autoreadbodyfile->value) {
            $this->readBodyFile();
        }
    }