diff options
Diffstat (limited to 'lib/private/server.php')
-rw-r--r-- | lib/private/server.php | 86 |
1 files changed, 41 insertions, 45 deletions
diff --git a/lib/private/server.php b/lib/private/server.php index a16854d6288..18d996537e2 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -268,6 +268,46 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('TrustedDomainHelper', function ($c) { return new TrustedDomainHelper($this->getConfig()); }); + $this->registerService('Request', function ($c) { + if (isset($this['urlParams'])) { + $urlParams = $this['urlParams']; + } else { + $urlParams = []; + } + + if ($this->getSession()->exists('requesttoken')) { + $requestToken = $this->getSession()->get('requesttoken'); + } else { + $requestToken = false; + } + + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN + && in_array('fakeinput', stream_get_wrappers()) + ) { + $stream = 'fakeinput://data'; + } else { + $stream = 'php://input'; + } + + return new Request( + [ + 'get' => $_GET, + 'post' => $_POST, + 'files' => $_FILES, + 'server' => $_SERVER, + 'env' => $_ENV, + 'cookies' => $_COOKIE, + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) + ? $_SERVER['REQUEST_METHOD'] + : null, + 'urlParams' => $urlParams, + 'requesttoken' => $requestToken, + ], + $this->getSecureRandom(), + $this->getConfig(), + $stream + ); + }); } /** @@ -282,54 +322,10 @@ class Server extends SimpleContainer implements IServerContainer { * currently being processed is returned from this method. * In case the current execution was not initiated by a web request null is returned * - * FIXME: This should be queried as well. However, due to our totally awesome - * static code a lot of tests do stuff like $_SERVER['foo'] which obviously - * will not work with that approach. We even have some integration tests in our - * unit tests which setup a complete webserver. Once the code is all non-static - * or we don't have such mixed integration/unit tests setup anymore this can - * get moved out again. - * * @return \OCP\IRequest|null */ function getRequest() { - if (isset($this['urlParams'])) { - $urlParams = $this['urlParams']; - } else { - $urlParams = array(); - } - - if ($this->getSession()->exists('requesttoken')) { - $requestToken = $this->getSession()->get('requesttoken'); - } else { - $requestToken = false; - } - - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN - && in_array('fakeinput', stream_get_wrappers()) - ) { - $stream = 'fakeinput://data'; - } else { - $stream = 'php://input'; - } - - return new Request( - [ - 'get' => $_GET, - 'post' => $_POST, - 'files' => $_FILES, - 'server' => $_SERVER, - 'env' => $_ENV, - 'cookies' => $_COOKIE, - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) - ? $_SERVER['REQUEST_METHOD'] - : null, - 'urlParams' => $urlParams, - 'requesttoken' => $requestToken, - ], - $this->getSecureRandom(), - $this->getConfig(), - $stream - ); + return $this->query('Request'); } /** |