本文整理汇总了PHP中Uri::setQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::setQuery方法的具体用法?PHP Uri::setQuery怎么用?PHP Uri::setQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uri
的用法示例。
在下文中一共展示了Uri::setQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Parses the string and returns the {@link Uri}.
*
* Parses the string and returns the {@link Uri}. If parsing fails, null is returned.
*
* @param String $string The url.
*
* @return \Bumble\Uri\Uri The Uri object.
*/
public function parse($string)
{
$data = parse_url($string);
//helper function gets $a[$k], checks if exists
function get($a, $k)
{
if (array_key_exists($k, $a)) {
return empty($a[$k]) ? null : $a[$k];
}
return null;
}
if ($data === null) {
return null;
}
$uri = new Uri();
$uri->setProtocol(get($data, 'scheme'));
$uri->setUsername(get($data, 'user'));
$uri->setPassword(get($data, 'pass'));
$uri->setHost(get($data, 'host'));
$uri->setPort(get($data, 'port'));
$uri->setPath(get($data, 'path'));
$uri->setQuery(get($data, 'query'));
$uri->setAnchor(get($data, 'anchor'));
return $uri;
}
示例2: testSetGetQuery
public function testSetGetQuery()
{
$this->assertInstanceOf('Web\\QueryString', $this->uri->getQuery());
$expected = 'one=1&two=2';
$this->uri->setQuery($expected);
$this->assertEquals($expected, (string) $this->uri->getQuery());
$this->uri->setQuery(new QueryString());
$this->assertEmpty((string) $this->uri->getQuery());
}
示例3: parse
public function parse($str)
{
$uri = new Uri();
$matched = preg_match('/^(?:([a-z\\.-]+):\\/\\/)?' . '(?:([^:]+)(?::(\\S+))?@)?' . '(' . '(?:[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})' . '|(?:(?:(?:[^\\.:\\/\\s-]+)(?:-[^\\.:\\/\\s-]+)*\\.)+)(?:[^?\\/:\\.]+)' . ')' . '(?::([0-9]+))?' . '(' . '\\/(?:[^#?\\/\\s.]+\\/?)*' . '(?:[^\\.\\s]*\\.[^#?\\s]+)?' . ')?' . '(\\?(?:[a-z0-9%-]+(?:=[a-z0-9%-]+)?)(?:&(?:[a-z0-9%-]+(?:=[a-z0-9%-]+)?))*)?' . '(?:\\#([a-z0-9&=-]+))?' . '$/ixSs', $str, $data);
if (!$matched) {
return null;
}
$protocol = isset($data[1]) && !empty($data[1]) ? $data[1] : null;
$username = isset($data[2]) && !empty($data[2]) ? $data[2] : null;
$password = isset($data[3]) && !empty($data[3]) ? $data[3] : null;
$domain = trim($data[4], '.');
//domain always exists
$port = isset($data[6]) && !empty($data[6]) ? $data[6] : null;
$path = isset($data[7]) && !empty($data[7]) ? $data[7] : null;
$query = isset($data[8]) && !empty($data[8]) ? ltrim($data[8], '?') : null;
$anchor = isset($data[9]) && !empty($data[9]) ? $data[9] : null;
//the entire ip/domain is caught as one piece.. was easier than regexing it
//so we tld is null for ip
//and we separate tld/domain for the domain version
if (is_numeric(str_replace('.', '', $domain))) {
//ip is not the right length
if (count(explode('.', $domain)) != 4) {
return null;
}
$tld = null;
} else {
$tld = end(explode('.', $domain));
$domain = implode('.', explode('.', $domain, -1));
}
$uri->setProtocol($protocol);
$uri->setUsername($username);
$uri->setPassword($password);
$uri->setDomain($domain);
$uri->setTld($tld);
$uri->setPort($port);
$uri->setPath($path);
$uri->setQuery($query);
$uri->setAnchor($anchor);
return $uri;
}
示例4: testQuery
/**
* Query test.
* @return void
*/
public function testQuery()
{
$uri = new Uri('http://hostname/path?arg=value');
$this->assertEquals('arg=value', $uri->query);
$uri->appendQuery(NULL);
$this->assertEquals('arg=value', $uri->query);
$uri->appendQuery(array(NULL));
$this->assertEquals('arg=value', $uri->query);
$uri->appendQuery('arg2=value2');
$this->assertEquals('arg=value&arg2=value2', $uri->query);
$uri->appendQuery(array('arg3' => 'value3'));
$this->assertEquals('arg=value&arg2=value2&arg3=value3', $uri->query);
$uri->setQuery(array('arg3' => 'value3'));
$this->assertEquals('arg3=value3', $uri->query);
}
示例5: testSetQuery
/**
* @covers MediaCore\Uri::setQuery
*/
public function testSetQuery()
{
$url = 'http://example.com/path/to/directory';
$query = 'foo=bar&baz=qux';
$uri = new Uri($url);
$uri->setQuery($query);
$this->assertEquals($query, $uri->getQuery());
$url = 'http://example.com/path/to/directory?foo=bar&baz=qux';
$query = 'foo=bar&baz=qux&foo=bar&baz=qux';
$uri = new Uri($url);
$uri->setQuery($query);
$this->assertEquals($query, $uri->getQuery());
}