本文整理汇总了PHP中Url::getScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::getScheme方法的具体用法?PHP Url::getScheme怎么用?PHP Url::getScheme使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Url
的用法示例。
在下文中一共展示了Url::getScheme方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getScheme
private function _getScheme()
{
if ($schemeHeader = $this->_getSchemeHeader()) {
return $schemeHeader;
} else {
$requestUrl = new Url($this->_server['REQUEST_URI']);
return $requestUrl->hasScheme() ? $requestUrl->getScheme() : 'http';
}
}
示例2: areSchemesEquivalent
/**
*
* @return boolean
*/
private function areSchemesEquivalent()
{
if ($this->sourceUrl->getScheme() === $this->comparatorUrl->getScheme()) {
return true;
}
foreach ($this->equivalentSchemes as $equivalentSchemeSet) {
if (in_array($this->sourceUrl->getScheme(), $equivalentSchemeSet) && in_array($this->comparatorUrl->getScheme(), $equivalentSchemeSet)) {
return true;
}
}
return false;
}
示例3: testUrl
function testUrl()
{
$url = new Url(self::TEST_URL);
$this->assertEquals($url->getFull(), self::TEST_URL);
$this->assertEquals($url->getScheme(), 'https');
$this->assertEquals($url->getHost(), 'www.google.com');
$this->assertEquals($url->getPort(), '80');
$this->assertEquals($url->getPath(), '/some_path');
// The HTML entities remain intact
$this->assertEquals($url->getQuery(), 'some=query&something=%20weird');
// The HTML entities are resolved
$this->assertEquals($url->getParam('some'), 'query');
$this->assertEquals($url->getParam('something'), ' weird');
$this->assertEquals($url->getParams(), ['some' => 'query', 'something' => ' weird']);
$this->assertEquals($url->getFragment(), 'some_fragment');
$this->assertEquals($url->getUser(), 'user');
$this->assertEquals($url->getPass(), 'pass');
}
示例4: baseString
/**
* Generate a base string for a RSA-SHA1 signature
* based on the given a url, method, and any parameters.
*
* @param Url $url
* @param string $method
* @param array $parameters
*
* @return string
*/
protected function baseString(Url $url, $method = 'POST', array $parameters = [])
{
$baseString = rawurlencode($method) . '&';
$schemeHostPath = $url->getScheme() . '://' . $url->getHost();
if ($url->getPort() != '') {
$schemeHostPath .= ':' . $url->getPort();
}
if ($url->getPath() != '') {
$schemeHostPath .= $url->getPath();
}
$baseString .= rawurlencode($schemeHostPath) . '&';
$data = [];
parse_str($url->getQuery(), $query);
foreach (array_merge($query, $parameters) as $key => $value) {
$data[rawurlencode($key)] = rawurlencode($value);
}
ksort($data);
array_walk($data, function (&$value, $key) {
$value = $key . '=' . $value;
});
$baseString .= rawurlencode(implode('&', $data));
return $baseString;
}
示例5: testDefaultScheme
/**
* Test default http scheme.
*/
public function testDefaultScheme()
{
$url = new Url(self::$baseUrl);
$this->assertEquals('http', $url->getScheme());
$url = new Url('domain.tld');
$this->assertEquals('http', $url->getScheme());
$url = new Url('ssh://domain.tld');
$this->assertEquals('ssh', $url->getScheme());
$url = new Url('ftp://domain.tld');
$this->assertEquals('ftp', $url->getScheme());
$url = new Url('git://domain.tld/push?pull=clone#checkout');
$this->assertEquals('git', $url->getScheme());
}
示例6: isBaseOf
/**
* Checks this url is base uri for the given url.
*
* @param Url $targetUri The url to inspect the base part.
*
* @return boolean
*/
public function isBaseOf(Url $targetUri)
{
if ($this->_parts['scheme'] !== $targetUri->getScheme() || $this->_parts['host'] !== $targetUri->getHost() || $this->getPort() !== $targetUri->getPort()) {
return false;
}
$srcSegmentCount = count($this->_segments);
$targetSegments = $targetUri->getSegments();
$targetSegmentCount = count($targetSegments);
if ($srcSegmentCount > $targetSegmentCount) {
return false;
}
for ($i = 0; $i < $srcSegmentCount; $i++) {
if ($this->_segments[$i] !== $targetSegments[$i]) {
return false;
}
}
return true;
}
示例7: linkTo
/**
* get a link from the current URL to another one
* @param UrlInterface|string $url the URL to link to
* @param boolean $forceAbsolute should an absolute path be used, defaults to `true`)
* @return string the link
*/
public function linkTo($url, $forceAbsolute = true)
{
if (is_string($url)) {
$url = new Url($url);
}
$str = (string) $url;
if ($this->getScheme() !== $url->getScheme()) {
return $str;
}
$str = preg_replace('(^[^/]+//)', '', $str);
if ($this->getHost() !== $url->getHost() || $this->getPort() !== $url->getPort()) {
return '//' . $str;
}
$str = preg_replace('(^[^/]+)', '', $str);
if ($this->getPath() !== $url->getPath()) {
if ($forceAbsolute) {
return $str;
}
$cnt = 0;
$tseg = $this->getSegments();
$useg = $url->getSegments();
foreach ($tseg as $k => $v) {
if (!isset($useg[$k]) || $useg[$k] !== $v) {
break;
}
$cnt++;
}
$str = './' . str_repeat('../', count($useg) - $cnt) . implode('/', array_slice($useg, $cnt));
if ($url->getQuery()) {
$str .= '?' . $url->getQuery();
}
if ($url->getFragment()) {
$str .= '#' . $url->getFragment();
}
return $str;
}
$str = preg_replace('(^[^?]+)', '', $str);
if ($this->getQuery() !== $url->getQuery() || $url->getFragment() === null) {
return $str;
}
return '#' . $url->getFragment();
}
示例8: testGetScheme
/**
* @param $url
* @param $expectedScheme
*
* @dataProvider dataProviderForTestGetScheme
*/
public function testGetScheme($url, $expectedScheme)
{
$url = new Url($url);
$this->assertEquals($expectedScheme, $url->getScheme());
}
示例9: testUrlFragmentEncoding
public function testUrlFragmentEncoding()
{
$url = new Url('http://127.0.0.1/foobar?bar=foo#!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~');
$this->assertEquals('http', $url->getScheme());
$this->assertEquals(null, $url->getUserInfo());
$this->assertEquals('127.0.0.1', $url->getHost());
$this->assertEquals(null, $url->getPort());
$this->assertEquals('/foobar', $url->getPath());
$this->assertEquals(array('bar' => 'foo'), $url->getParameters());
$this->assertEquals('!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~', $url->getFragment());
}
示例10: get_url_scheme
/**
* Get URL scheme.
*
* @param string url Url for which the scheme is requested
*
* @return mixed the URL scheme or false if none is provided.
*/
function get_url_scheme($url)
{
$obj_url = new Url($url);
return $obj_url->getScheme();
}
示例11: renderPage
//.........这里部分代码省略.........
if (!$link) {
header('Location: ?');
exit;
}
// Link not found in database.
$PAGE = new pageBuilder();
$PAGE->assign('linkcount', count($LINKSDB));
$PAGE->assign('link', $link);
$PAGE->assign('link_is_new', false);
$PAGE->assign('token', getToken());
// XSRF protection.
$PAGE->assign('http_referer', isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : '');
$PAGE->assign('tags', $LINKSDB->allTags());
$PAGE->renderPage('editlink');
exit;
}
// -------- User want to post a new link: Display link edit form.
if (isset($_GET['post'])) {
$url = new Url($_GET['post']);
$url->cleanup();
$link_is_new = false;
// Check if URL is not already in database (in this case, we will edit the existing link)
$link = $LINKSDB->getLinkFromUrl((string) $url);
if (!$link) {
$link_is_new = true;
$linkdate = strval(date('Ymd_His'));
// Get title if it was provided in URL (by the bookmarklet).
$title = empty($_GET['title']) ? '' : $_GET['title'];
// Get description if it was provided in URL (by the bookmarklet). [Bronco added that]
$description = empty($_GET['description']) ? '' : $_GET['description'];
$tags = empty($_GET['tags']) ? '' : $_GET['tags'];
$private = !empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0;
// If this is an HTTP(S) link, we try go get the page to extract the title (otherwise we will to straight to the edit form.)
if (empty($title) && strpos($url->getScheme(), 'http') !== false) {
list($status, $headers, $data) = getHTTP($url, 4);
// Short timeout to keep the application responsive.
// FIXME: Decode charset according to specified in either 1) HTTP response headers or 2) <head> in html
if (strpos($status, '200 OK') !== false) {
// Look for charset in html header.
preg_match('#<meta .*charset=.*>#Usi', $data, $meta);
// If found, extract encoding.
if (!empty($meta[0])) {
// Get encoding specified in header.
preg_match('#charset="?(.*)"#si', $meta[0], $enc);
// If charset not found, use utf-8.
$html_charset = !empty($enc[1]) ? strtolower($enc[1]) : 'utf-8';
} else {
$html_charset = 'utf-8';
}
// Extract title
$title = html_extract_title($data);
if (!empty($title)) {
// Re-encode title in utf-8 if necessary.
$title = $html_charset == 'iso-8859-1' ? utf8_encode($title) : $title;
}
}
}
if ($url == '') {
$url = '?' . smallHash($linkdate);
$title = 'Note: ';
}
$link = array('linkdate' => $linkdate, 'title' => $title, 'url' => (string) $url, 'description' => $description, 'tags' => $tags, 'private' => $private);
}
$PAGE = new pageBuilder();
$PAGE->assign('linkcount', count($LINKSDB));
$PAGE->assign('link', $link);