Пример #1
0
 /**
  * @covers \Airship\array_from_http_query()
  */
 public function testArrayFromHttpQuery()
 {
     $this->assertSame([], \Airship\array_from_http_query(''), 'Empty string should return empty array.');
     $this->assertSame(['foo' => 'bar'], \Airship\array_from_http_query('foo=bar'), 'foo=bar should become an array of size 1with key foo and element bar');
     $this->assertSame(['foo' => 'bar', 'apple' => '1'], \Airship\array_from_http_query('foo=bar&apple=1'));
     $this->assertSame(['foo' => 'bar', 'apple' => ['1']], \Airship\array_from_http_query('foo=bar&apple[]=1'), 'Arrays are not being respected');
     $this->assertSame(['foo' => 'bar', 'apple' => ['baz' => '1']], \Airship\array_from_http_query('foo=bar&apple[baz]=1'), 'Arrays are not being parsed correctly');
 }
Пример #2
0
 /**
  * Work around poorly-configured web servers by parsing out the GET parameters
  *
  * Be forewarned: this will overwrite $lastPiece
  *
  * @param string& $lastPiece (optional)
  * @return array
  */
 protected function httpGetParams(string &$lastPiece = null) : array
 {
     if ($lastPiece === null) {
         return $_GET ?? [];
     }
     $p = \strpos($lastPiece, '?');
     if ($p !== false && empty($_GET)) {
         $_GET = \Airship\array_from_http_query(Binary::safeSubstr($lastPiece, $p + 1));
         $lastPiece = Binary::safeSubstr($lastPiece, 0, $p);
     }
     return $_GET;
 }