本文整理汇总了PHP中URL::getScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP URL::getScheme方法的具体用法?PHP URL::getScheme怎么用?PHP URL::getScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类URL
的用法示例。
在下文中一共展示了URL::getScheme方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toExternalForm
/**
* @param URL $u
* @return blaze\lang\String
*/
public function toExternalForm(URL $u)
{
$str = $u->getScheme() . '://';
if ($u->getUser() != null) {
$str .= $u->getUser();
if ($u->getPassword() != null) {
$str .= ':' . $u->getPassword();
}
$str .= '@';
}
$str .= $u->getHost();
if ($u->getPort() != -1) {
$str .= ':' . $u->getPort();
}
if ($u->getPath() != null) {
$str .= '/' . $u->getPath();
}
if ($u->getQuery() != null) {
$str .= '?' . $u->getQuery();
}
if ($u->getFragment() != null) {
$str .= '#' . $u->getFragment();
}
return new \blaze\lang\String($str);
}
示例2: acquire
/**
* Acquire a handler instance
*
* @param string key
* @return remote.protocol.ProtocolHandler
* @throws remote.protocol.UnknownProtocolException
*/
public function acquire($key, $initialize = FALSE)
{
$url = new URL($key);
$key = new URL($url->getScheme() . '://' . $url->getHost());
if ($this->pool->containsKey($key)) {
$instance = $this->pool->get($key);
} else {
sscanf($url->getScheme(), '%[^+]+%s', $type, $option);
$class = HandlerFactory::handlerFor($type);
$instance = $this->pool($key, $class->newInstance($option));
}
// Add logger
if (NULL !== ($cat = $url->getParam('log'))) {
$instance->setTrace(Logger::getInstance()->getCategory($cat));
}
// Set timeout, defaults to 60 seconds
$instance->setTimeout($url->getParam('timeout', 60));
$initialize && $instance->initialize($url);
return $instance;
}
示例3: newRequest
/**
* Creates a new request object
*
* @param string method
* @param peer.URL url
* @return scriptlet.HttpScriptletRequest
*/
protected function newRequest($method, URL $url)
{
$q = $url->getQuery('');
$req = new HttpScriptletRequest();
$req->method = $method;
$req->env['SERVER_PROTOCOL'] = 'HTTP/1.1';
$req->env['REQUEST_URI'] = $url->getPath('/') . ($q ? '?' . $q : '');
$req->env['QUERY_STRING'] = $q;
$req->env['HTTP_HOST'] = $url->getHost();
if ('https' === $url->getScheme()) {
$req->env['HTTPS'] = 'on';
}
$req->setHeaders(array());
$req->setParams($url->getParams());
return $req;
}
示例4: doCreate
public function doCreate()
{
$req = $this->newRequest('GET', new URL('http://localhost/'));
$res = new HttpScriptletResponse();
$s = newinstance('scriptlet.xml.XMLScriptlet', array(), '{
public function needsSession($request) { return TRUE; }
}');
$s->service($req, $res);
$this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
// Check URL from Location: header contains the session ID
with($redirect = new URL(substr($res->headers[0], strlen('Location: '))));
$this->assertEquals('http', $redirect->getScheme());
$this->assertEquals('localhost', $redirect->getHost());
$this->assertEquals(sprintf('/xml/psessionid=%s/static', session_id()), $redirect->getPath());
$this->assertEquals(array(), $redirect->getParams(), $redirect->getURL());
}
示例5: transportFor
/**
* Get transport implementation for a specific URL
*
* @param peer.URL url
* @return peer.http.HttpTransport
* @throws lang.IllegalArgumentException in case the scheme is not supported
*/
public static function transportFor(URL $url)
{
sscanf($url->getScheme(), '%[^+]+%s', $scheme, $arg);
if (!isset(self::$transports[$scheme])) {
throw new IllegalArgumentException('Scheme "' . $scheme . '" unsupported');
}
return self::$transports[$scheme]->newInstance($url, $arg);
}
示例6: handleSessionInitializationError
public function handleSessionInitializationError()
{
$req = $this->newRequest('GET', new URL('http://localhost/?psessionid=MALFORMED'));
$res = new HttpScriptletResponse();
$s = newinstance('scriptlet.HttpScriptlet', array(), '{
public function needsSession($request) { return TRUE; }
public function handleSessionInitialization($request) {
if (!preg_match("/^a-f0-9$/", $request->getSessionId())) {
throw new IllegalArgumentException("Invalid characters in session id");
}
parent::handleSessionInitialization($request);
}
public function handleSessionInitializationError($request, $response) {
$request->getURL()->addParam("relogin", 1);
return $request->session->initialize(NULL);
}
}');
$s->service($req, $res);
$this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
// Check URL from Location: header contains the session ID
with($redirect = new URL(substr($res->headers[0], strlen('Location: '))));
$this->assertEquals('http', $redirect->getScheme());
$this->assertEquals('localhost', $redirect->getHost());
$this->assertEquals('/', $redirect->getPath());
$this->assertEquals(session_id(), $redirect->getParam('psessionid'));
$this->assertEquals('1', $redirect->getParam('relogin'));
}
示例7: navigateTo
/**
* Navigate to a given URL
*
* @param string target
* @param string params
* @param string method
* @throws unittest.AssertionFailedError
*/
public function navigateTo($target, $params = NULL, $method = HttpConstants::GET)
{
if (strstr($target, '://')) {
$url = new URL($target);
$this->conn = $this->getConnection(sprintf('%s://%s%s/', $url->getScheme(), $url->getHost(), -1 === $url->getPort(-1) ? '' : ':' . $url->getPort()));
$params ? $url->setParams($params) : '';
$this->beginAt($url->getPath(), $url->getParams(), $method);
} else {
if ('' !== $target && '/' === $target[0]) {
$this->beginAt($target, $params, $method);
} else {
$base = $this->getBase();
$this->beginAt(substr($base, 0, strrpos($base, '/')) . '/' . $target, $params, $method);
}
}
}
示例8: my_has_URL_invalid_content
function my_has_URL_invalid_content($bookmark_url)
{
return URL::getScheme($bookmark_url) === 'javascript';
}
示例9: testSettingTypes
//.........这里部分代码省略.........
} elseif ($optional) {
$settingVal = null;
} else {
throw new SettingException('Required setting ' . $setting . ' is not defined.');
}
if ($optional && $settingVal === null) {
continue;
}
if (substr($test, 0, 1) == '/') {
if (!preg_match($test, $settingVal)) {
throw new SettingException('Setting ' . $setting . ' failed the required ' . 'regular expression match.');
}
continue;
}
$exceptionMessage = null;
switch ($test) {
case 'boolean':
case 'bool':
if (!is_bool($settingVal)) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'a boolean value.';
}
break;
case 'string':
case 'str':
if (!is_string($settingVal)) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'a string value.';
}
break;
case 'integer':
case 'int':
if (filter_var($settingVal, FILTER_VALIDATE_INT) === false) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'an integer value.';
}
break;
case 'num':
case 'number':
case 'numeric':
if (!is_numeric($settingVal)) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'a numeric value.';
}
break;
case 'ratio':
if (!is_numeric($settingVal) || $settingVal < 0 || $settingVal > 1) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'a ratio.';
}
break;
case 'file':
if (!is_file($settingVal) && !is_link($settingVal)) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'a path to a real file.';
}
break;
case 'dir':
case 'directory':
// Don't allow trailing slashes
if (substr($settingVal, -1) == DIRECTORY_SEPARATOR) {
$exceptionMessage = 'Setting ' . $setting . ' must ' . 'not contain a trailing slash.';
} elseif (!is_dir($settingVal)) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'a real directory.';
}
break;
case 'writable':
if (!strlen($settingVal) || !self::testWritable($settingVal)) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'a writable file.';
}
break;
case 'email':
// Allow comma-delimited instances of multiple addresses
$addresses = explode(',', $settingVal);
foreach ($addresses as $address) {
if (!filter_var($address, FILTER_VALIDATE_EMAIL)) {
$exceptionMessage = 'Setting ' . $setting . ' must be either a ' . 'single email address, or a comma-delimited ' . 'list of email addresses.';
break;
}
}
break;
case 'executable':
if (!is_executable($settingVal)) {
$exceptionMessage = 'Setting ' . $setting . ' must be ' . 'an executable file.';
}
break;
case 'url':
try {
$url = new URL($settingVal);
// Require the presence of a scheme
if (strpos($settingVal, $url->getScheme() . '://') !== 0) {
$exceptionMessage = 'The value of setting ' . $setting . ' is missing a ' . 'scheme.';
}
} catch (URLException $e) {
$exceptionMessage = 'Setting ' . $setting . ' must ' . 'be a valid URL.';
}
break;
default:
throw new SettingException('Unrecognized setting test "' . $test . '".');
}
if ($exceptionMessage) {
throw new SettingException($exceptionMessage);
}
self::$_validatedSettings[$setting] = null;
}
}
示例10: _parsedsn
/**
* Parse DSN
*
* @param string dsn
* @return bool success
*/
protected function _parsedsn($dsn)
{
if (NULL === $dsn) {
return TRUE;
}
$u = new URL($dsn);
if (!$u->getHost()) {
throw new IllegalArgumentException('DSN parsing failed ["' . $dsn . '"]');
}
// Scheme
switch (strtoupper($u->getScheme())) {
case 'ESMTP':
$this->ext = TRUE;
break;
case 'SMTP':
$this->ext = FALSE;
break;
default:
throw new IllegalArgumentException('Scheme "' . $u->getScheme() . '" not supported');
}
// Copy host and port
$this->host = $u->getHost();
$this->port = $u->getPort() ? $u->getPort() : 25;
// User & password
if ($u->getUser()) {
$this->auth = $u->getParam('auth', SMTP_AUTH_PLAIN);
$this->user = $u->getUser();
$this->pass = $u->getPassword();
}
}