From 92db4650e7036867255e8a8263a43afaf62562d0 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 8 Mar 2018 23:34:25 +0300 Subject: [PATCH] parse console command arguments w/o filename into super global (#17) --- src/Nono/Request.php | 4 +++- tests/RequestTest.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Nono/Request.php b/src/Nono/Request.php index 53f325c..f9f80f3 100644 --- a/src/Nono/Request.php +++ b/src/Nono/Request.php @@ -23,7 +23,9 @@ class Request public function __construct() { $_SERVER; - if (!in_array($this->method(), ['GET', 'POST'])) { + if (PHP_SAPI == 'cli') { + parse_str(implode('&', array_slice($this->server('argv'), 1)), $GLOBALS['_QUERY']); + } elseif (!in_array($this->method(), ['GET', 'POST'])) { parse_str($this->content(), $GLOBALS['_QUERY']); } } diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 2719297..c738a3b 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -47,6 +47,12 @@ public function testMethod() self::assertEquals('GET', $this->request->method()); } + public function testContentProducesNoError() + { + self::assertNotFalse($this->request->content()); + self::assertNull(error_get_last()); + } + public function testRequestTimeFloat() { self::assertTrue(is_numeric($this->request->requestTimeFloat()));