本文整理汇总了PHP中URL::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP URL::getPath方法的具体用法?PHP URL::getPath怎么用?PHP URL::getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类URL
的用法示例。
在下文中一共展示了URL::getPath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: forURL
/**
* Create client by inspecting the URL
*
* @param string url The API url
* @return com.atlassian.jira.api.JiraClientProtocol
*/
public static function forURL($url)
{
$u = new URL($url);
// Check for REST API client v2
if (create(new String($u->getPath()))->contains('/rest/api/2')) {
return XPClass::forName('com.atlassian.jira.api.protocol.JiraClientRest2Protocol')->newInstance($u);
// No suitable protocol found
} else {
throw new IllegalArgumentException('No suitable client found for ' . $url);
}
}
示例3: setup
/**
* Setup the class instance. A dsn string must be given with the relevant information
* about the server and script:
*
* Eg: nagios://nagios.xp_framework.net:5667/service_to_monitor
*
* @param string dsn
*/
public function setup($dsn)
{
$url = new URL($dsn);
$this->server = $url->getHost();
$this->port = $url->getPort(5667);
$this->version = $url->getParam('version', NSCA_VERSION_2);
$this->service = trim($url->getPath(), '/');
$this->host = $url->getParam('hostname', System::getProperty('host.name'));
if (FALSE !== $url->getParam('domain', FALSE)) {
$this->host .= '.' . ltrim($url->getParam('domain'), '.');
}
}
示例4: 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;
}
示例5: 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());
}
示例6: handleMethod
/**
* Handle methods
*
* @return string class method (one of doGet, doPost, doHead)
* @param string method Request-Method
* @see rfc://2518#8 Description of methods
*/
public function handleMethod($request)
{
// Check if we recognize this method
if (!isset($this->methods[$request->method])) {
throw new HttpScriptletException('Cannot handle method "' . $request->method . '"');
}
// Select implementation
$this->handlingImpl = NULL;
foreach (array_keys($this->impl) as $pattern) {
if (0 !== strpos(rtrim($request->uri->getPath(), '/') . '/', $pattern)) {
continue;
}
// Set the root URL (e.g. http://wedav.host.com/dav/)
$request->setRootURL($rootURL = new URL(sprintf('%s://%s%s', $request->uri->getScheme(), $request->uri->Host(), $pattern)));
// Set request path (e.g. /directory/file)
$request->setPath($request->decodePath(substr($request->uri->getPath(), strlen($pattern))));
$this->handlingImpl = $this->impl[$pattern];
// Set absolute Uri
$request->setAbsoluteURI($this->handlingImpl->base . $request->getPath());
break;
}
// Implementation not found
if (NULL === $this->handlingImpl) {
throw new HttpScriptletException('Cannot handle requests to ' . $request->uri->getPath());
}
// determine Useragent
$client = $request->getHeader('user-agent');
switch (substr($client, 0, 3)) {
case 'Mic':
$this->useragent = WEBDAV_CLIENT_MS;
break;
case 'gno':
$this->useragent = WEBDAV_CLIENT_NAUT;
break;
default:
$this->useragent = WEBDAV_CLIENT_UNKNOWN;
}
// Check for authorization handler
if (isset($this->auth[$rootURL->getPath()])) {
$this->handlingAuth = $this->auth[$rootURL->getPath()];
$auth = BasicAuthorization::fromValue($request->getHeader('Authorization'));
// Can not get username/password from Authorization header
if (!$auth) {
return 'doAuthorizationRequest';
}
// Use an own User object if you want to save more than username and password
if ($this->user[$rootURL->getPath()]) {
$c = XPClass::forName($this->user[$pattern]);
with($user = $c->newInstance());
$user->setUsername($auth->getUser());
$user->setUserPassword($auth->getPassword());
$request->setUser($user);
} else {
// Create a normal WebdavUser object
$request->setUser(new WebdavUser($auth->getUser(), $auth->getPassword()));
}
// Check user
if (!$this->handlingAuth->authorize($request->getUser())) {
return 'doAuthorizationRequest';
}
// Check for permissions
if (!$this->handlingAuth->isAuthorized($this->handlingImpl->base . $request->getPath(), $request->getUser(), $request)) {
return 'doAuthorizationDeny';
}
}
// Read input if we have a Content-length header,
// else get data from QUERY_STRING
if (NULL !== ($len = $request->getHeader('Content-length')) && FALSE !== ($fd = fopen('php://input', 'r'))) {
$data = fread($fd, $len);
fclose($fd);
$request->setData($data);
} else {
$request->setData(getenv('QUERY_STRING'));
}
// Check for mapping
if (($mapping = $this->mapping[$rootURL->getPath()]) !== NULL) {
$this->map = $mapping->init($request, $pattern);
}
return $this->methods[$request->method];
}
示例7: testGetPath
/**
* @covers \URLParser\URL::__construct
* @covers \URLParser\URL::getPath
*/
public function testGetPath()
{
$url = new URL($this->testUrl);
$this->assertEquals($this->path, $url->getPath());
}
示例8: getRelativePath
/**
* Convert absolute URL to relative path:
* "http://webdav.host.com/fs/dir/file.txt" -> "dir/file.txt"
*
* @param string url
* @return string
*/
public function getRelativePath($url)
{
$url = new URL($url);
return $this->decodePath(substr(rawurldecode($url->getPath()), strlen($this->rootURL->getPath())));
}
示例9: 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'));
}
示例10: atInUserAndPath
public function atInUserAndPath()
{
$u = new URL('http://user@localhost/@');
$this->assertEquals('user', $u->getUser());
$this->assertEquals('/@', $u->getPath());
}
示例11: 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);
}
}
}