Пример #1
0
 public function testAddQuery()
 {
     $u = new \Ark4ne\Helpers\URL('/Ark4ne?a=a&b[]=b');
     $u->addParam('a', 'z');
     $this->assertEquals(['a' => 'z', 'b' => ['b']], $u->getParams());
     $this->assertEquals('?a=z&b[]=b', $u->getParamsString());
     $u->addParam('c', 'c');
     $this->assertEquals(['a' => 'z', 'b' => ['b'], 'c' => 'c'], $u->getParams());
     $this->assertEquals('?a=z&b[]=b&c=c', $u->getParamsString());
     $u->addParam('b', 'b1');
     $this->assertEquals(['a' => 'z', 'b' => ['b', 'b1'], 'c' => 'c'], $u->getParams());
     $this->assertEquals('?a=z&b[]=b&b[]=b1&c=c', $u->getParamsString());
     $u->addParam('b', 'b1');
     $this->assertEquals(['a' => 'z', 'b' => ['b', 'b1'], 'c' => 'c'], $u->getParams());
     $this->assertEquals('?a=z&b[]=b&b[]=b1&c=c', $u->getParamsString());
     $this->assertEquals('/Ark4ne?a=z&b[]=b&b[]=b1&c=c', (string) $u);
 }
Пример #2
0
 /**
  * Return formatted url.
  *
  * @param string    $to
  * @param array     $params
  * @param null|bool $secure
  * @param null|bool $domain
  *
  * @return string
  */
 function ark_url($to, $params = [], $secure = null, $domain = null)
 {
     $url = new \Ark4ne\Helpers\URL($to);
     foreach ($params as $key => $value) {
         $url->addParam($key, $value);
     }
     $secure !== null && $url->setSecure($secure);
     $domain !== null && $url->setDomainString($domain);
     return (string) $url;
 }