本文整理汇总了PHP中Zend\Uri\Uri::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::getPath方法的具体用法?PHP Uri::getPath怎么用?PHP Uri::getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Uri\Uri
的用法示例。
在下文中一共展示了Uri::getPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
/**
* Method call overload
*
* Allows calling REST actions as object methods; however, you must
* follow-up by chaining the request with a request to an HTTP request
* method (post, get, delete, put):
* <code>
* $response = $rest->sayHello('Foo', 'Manchu')->get();
* </code>
*
* Or use them together, but in sequential calls:
* <code>
* $rest->sayHello('Foo', 'Manchu');
* $response = $rest->get();
* </code>
*
* @param string $method Method name
* @param array $args Method args
* @return \Zend\Rest\Client\RestClient_Result|\Zend\Rest\Client\RestClient \Zend\Rest\Client\RestClient if using
* a remote method, Zend_Rest_Client_Result if using an HTTP request method
*/
public function __call($method, $args)
{
$methods = array('post', 'get', 'delete', 'put');
if (in_array(strtolower($method), $methods)) {
if (!isset($args[0])) {
$args[0] = $this->_uri->getPath();
}
$this->_data['rest'] = 1;
$data = array_slice($args, 1) + $this->_data;
$response = $this->{'rest' . $method}($args[0], $data);
$this->_data = array();
//Initializes for next Rest method.
return new Result($response->getBody());
} else {
// More than one arg means it's definitely a Zend_Rest_Server
if (count($args) == 1) {
// Uses first called function name as method name
if (!isset($this->_data['method'])) {
$this->_data['method'] = $method;
$this->_data['arg1'] = $args[0];
}
$this->_data[$method] = $args[0];
} else {
$this->_data['method'] = $method;
if (count($args) > 0) {
foreach ($args as $key => $arg) {
$key = 'arg' . $key;
$this->_data[$key] = $arg;
}
}
}
return $this;
}
}
示例2: parse
/**
* @param \Zend\Uri\Uri $uri
*/
public function parse(Uri $uri)
{
$this->url = $uri->toString();
$html = \OpenGraph::fetch($uri->toString());
// open graph
$this->id = basename($uri->getPath());
$this->title = $html->title;
$this->description = $html->description;
$this->image = urlencode($html->image);
}
示例3: configureUri
/**
* {@inheritdoc}
*/
public function configureUri(Uri $baseUri, $name, $id = null)
{
$basePath = $baseUri->getPath();
$resourcePath = rtrim($basePath, '/') . '/' . $name;
if ($id) {
$resourcePath .= '/' . $id;
}
$baseUri->setPath($resourcePath);
return $baseUri;
}
示例4: getFirstSegmentInPath
protected function getFirstSegmentInPath(Uri $uri, $base = null)
{
$path = $uri->getPath();
if ($base) {
$path = substr($path, strlen($base));
}
$parts = explode('/', trim($path, '/'));
$locale = array_shift($parts);
return $locale;
}
示例5: write
/**
* Send request to the remote server with streaming support.
*
* @param string $method
* @param \Zend\Uri\Uri $uri
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(),
$body = '')
{
// Make sure we're properly connected
if (! $this->socket) {
throw new Adapter\Exception(
'Trying to write but we are not connected');
}
$host = $uri->getHost();
$host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
throw new Adapter\Exception(
'Trying to write but we are connected to the wrong host');
}
// Save request method for later
$this->method = $method;
// Build request headers
$path = $uri->getPath();
if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) $v = ucfirst($k) . ": $v";
$request .= "$v\r\n";
}
// Send the headers over
$request .= "\r\n";
if (! @fwrite($this->socket, $request)) {
throw new Adapter\Exception(
'Error writing request to server');
}
//read from $body, write to socket
$chunk = $body->read(self::CHUNK_SIZE);
while ($chunk !== FALSE) {
if (! @fwrite($this->socket, $chunk)) {
throw new Adapter\Exception(
'Error writing request to server');
}
$chunk = $body->read(self::CHUNK_SIZE);
}
$body->closeFileHandle();
return 'Large upload, request is not cached.';
}
示例6: clearUri
/**
* Get clear uri.
*
* @static
*
* @param \Zend\Uri\Uri $uri
*
* @return boolean|\Zend\Uri\Uri False if uri is not auhorized
*/
public static function clearUri(Uri $uri)
{
if ($uri->getScheme() !== 'http') {
return false;
}
$paths = explode('/', $uri->getPath());
$pathsCount = count($paths);
if ($pathsCount < 2) {
return false;
}
$type = $paths[$pathsCount - 2];
if (!in_array($type, self::$typesAuthorized)) {
return false;
}
$uri->setHost('www.deezer.com');
// clear
$uri->setPort(0);
$uri->setUserInfo('');
$uri->setQuery('');
$uri->setFragment('');
return $uri;
}
示例7: write
/**
* Send request to the remote server
*
* @param string $method
* @param \Zend\Uri\Uri $uri
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
{
$host = $uri->getHost();
$host = strtolower($uri->getScheme()) == 'https' ? 'sslv2://' . $host : $host;
// Build request headers
$path = $uri->getPath();
if (empty($path)) {
$path = '/';
}
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = ucfirst($k) . ": {$v}";
}
$request .= "{$v}\r\n";
}
// Add the request body
$request .= "\r\n" . $body;
// Do nothing - just return the request as string
return $request;
}
示例8: write
/**
* Send request to the remote server
*
* @param string $method
* @param \Zend\Uri\Uri $uri
* @param string $httpVer
* @param array $headers
* @param string $body
* @throws AdapterException\RuntimeException
* @return string Request as string
*/
public function write($method, $uri, $httpVer = '1.1', $headers = array(), $body = '')
{
// Make sure we're properly connected
if (!$this->socket) {
throw new AdapterException\RuntimeException('Trying to write but we are not connected');
}
$host = $uri->getHost();
$host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
if ($this->connectedTo[0] != $host || $this->connectedTo[1] != $uri->getPort()) {
throw new AdapterException\RuntimeException('Trying to write but we are connected to the wrong host');
}
// Save request method for later
$this->method = $method;
// Build request headers
$path = $uri->getPath();
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "{$method} {$path} HTTP/{$httpVer}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = ucfirst($k) . ": {$v}";
}
$request .= "{$v}\r\n";
}
if (is_resource($body)) {
$request .= "\r\n";
} else {
// Add the request body
$request .= "\r\n" . $body;
}
// Send the request
ErrorHandler::start();
$test = fwrite($this->socket, $request);
$error = ErrorHandler::stop();
if (false === $test) {
throw new AdapterException\RuntimeException('Error writing request to server', 0, $error);
}
if (is_resource($body)) {
if (stream_copy_to_stream($body, $this->socket) == 0) {
throw new AdapterException\RuntimeException('Error writing request to server');
}
}
return $request;
}
示例9: initiateHandshake
public function initiateHandshake(Uri $uri)
{
$challenge = self::randHybiKey();
$request = new Request();
$requestUri = $uri->getPath();
if ($uri->getQuery()) {
$requestUri .= "?" . $uri->getQuery();
}
$request->setUri($requestUri);
$request->getHeaders()->addHeaderLine("Connection", "Upgrade");
$request->getHeaders()->addHeaderLine("Host", $uri->getHost());
$request->getHeaders()->addHeaderLine("Sec-WebSocket-Key", $challenge);
$request->getHeaders()->addHeaderLine("Sec-WebSocket-Version", 13);
$request->getHeaders()->addHeaderLine("Upgrade", "websocket");
$this->setRequest($request);
$this->emit("request", array($request));
$this->_socket->write($request->toString());
return $request;
}
示例10: testGetPath
/**
* Test that we can get the path out of a parsed Uri
*
* @param string $uriString
* @param array $parts
* @dataProvider uriWithPartsProvider
*/
public function testGetPath($uriString, $parts)
{
$uri = new Uri($uriString);
if (isset($parts['path'])) {
$this->assertEquals($parts['path'], $uri->getPath());
} else {
$this->assertNull($uri->getPath());
}
}
示例11: parse
/**
* @inheritdoc
*/
public function parse($uri)
{
$uri = new Uri($uri);
return $this->formatResults(['scheme' => $uri->getScheme(), 'userinfo' => $uri->getUserInfo(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'query' => $uri->getQuery(), 'fragment' => $uri->getFragment()]);
}
示例12: enforceScheme
/**
* Enforce the defined scheme on the URI
*
* This will also adjust the host and path parts of the URI as expected in
* the case of scheme-less network URIs
*
* @param Uri $uri
*/
protected function enforceScheme(Uri $uri)
{
$path = $uri->getPath();
if (strpos($path, '/') !== false) {
list($host, $path) = explode('/', $path, 2);
$path = '/' . $path;
} else {
$host = $path;
$path = '';
}
// We have nothing to do if we have no host
if (!$host) {
return;
}
$uri->setScheme($this->enforcedScheme)->setHost($host)->setPath($path);
}
示例13: write
/**
* Send request to the remote server
*
* @param string $method
* @param \Zend\Uri\Uri $uri
* @param string $httpVer
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $httpVer = '1.1', $headers = [], $body = '')
{
// Build request headers
$path = $uri->getPath();
if (empty($path)) {
$path = '/';
}
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "{$method} {$path} HTTP/{$httpVer}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = ucfirst($k) . ": {$v}";
}
$request .= "{$v}\r\n";
}
// Add the request body
$request .= "\r\n" . $body;
// Do nothing - just return the request as string
return $request;
}
示例14: testGetPathInRefUrl
/**
* Make sure we get the correct path when it's set a reference URL
*
* @dataProvider refUrlProvider
*/
public function testGetPathInRefUrl(Uri\Uri $uri)
{
$path = $uri->getPath();
if (substr($path, -1, 1) == '/') {
$path .= 'x';
}
$path = dirname($path);
if ($path == DIRECTORY_SEPARATOR || empty($path)) {
$path = '/';
}
$cookie = Http\Cookie::fromString('foo=bar', (string) $uri);
if (!$cookie instanceof Http\Cookie) {
$this->fail("Failed creating a cookie object with URL '{$uri}'");
}
$this->assertEquals($path, $cookie->getPath());
}
示例15: getPath
/**
* Get the URI path
*
* @return string|null
*/
public function getPath()
{
return $this->uri->getPath();
}