本文整理汇总了PHP中Zend\Uri\Http::getHost方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::getHost方法的具体用法?PHP Http::getHost怎么用?PHP Http::getHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Uri\Http
的用法示例。
在下文中一共展示了Http::getHost方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setData
public function setData($data)
{
if ($data instanceof Traversable) {
$data = ArrayUtils::iteratorToArray($data);
}
$isAts = isset($data['atsEnabled']) && $data['atsEnabled'];
$isUri = isset($data['uriApply']) && !empty($data['uriApply']);
$email = isset($data['contactEmail']) ? $data['contactEmail'] : '';
if ($isAts && $isUri) {
$data['atsMode']['mode'] = 'uri';
$data['atsMode']['uri'] = $data['uriApply'];
$uri = new Http($data['uriApply']);
if ($uri->getHost() == $this->host) {
$data['atsMode']['mode'] = 'intern';
}
} elseif ($isAts && !$isUri) {
$data['atsMode']['mode'] = 'intern';
} elseif (!$isAts && !empty($email)) {
$data['atsMode']['mode'] = 'email';
$data['atsMode']['email'] = $email;
} else {
$data['atsMode']['mode'] = 'none';
}
if (!array_key_exists('job', $data)) {
$data = array('job' => $data);
}
return parent::setData($data);
}
示例2: appendCdn
protected function appendCdn($href)
{
$uri = new Http($href);
if ($uri->getHost()) {
return $href;
}
$servers = $this->cdnOptions['servers'];
if (1 == count($servers)) {
$server = $servers[0];
} else {
switch ($this->cdnOptions['method']) {
case 'respective':
if (!isset($servers[static::$serverId])) {
static::$serverId = 0;
}
$server = $servers[static::$serverId];
static::$serverId++;
break;
// Get a random CDN server
// Get a random CDN server
case 'random':
default:
$server = $servers[array_rand($servers)];
break;
}
}
$href = rtrim($server, '/') . '/' . ltrim($href, '/');
return $href;
}
示例3: testAssembling
/**
* @dataProvider routeProvider
* @param Hostname $route
* @param string $hostname
* @param array $params
*/
public function testAssembling(Hostname $route, $hostname, array $params = null)
{
if ($params === null) {
// Data which will not match are not tested for assembling.
return;
}
$uri = new HttpUri();
$path = $route->assemble($params, array('uri' => $uri));
$this->assertEquals('', $path);
$this->assertEquals($hostname, $uri->getHost());
}
示例4: check
/**
* Check if ssl is forced or not
*
* @param EventInterface $event Mvc event
*
* @return null|Zend\Http\PhpEnvironment\Response
*/
public function check(EventInterface $event)
{
$coreConfig = $event->getApplication()->getServiceManager()->get('CoreConfig');
$matchedRouteName = $event->getRouteMatch()->getMatchedRouteName();
$request = $event->getRequest();
$uri = $request->getUri();
if ($matchedRouteName === 'cms') {
if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_frontend_ssl')) {
$newUri = new Uri($coreConfig->getValue('secure_frontend_base_path'));
$newUri->setScheme('https');
} else {
$newUri = new Uri($coreConfig->getValue('unsecure_frontend_base_path'));
}
} else {
if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_backend_ssl')) {
$newUri = new Uri($coreConfig->getValue('secure_backend_base_path'));
$newUri->setScheme('https');
} else {
$newUri = new Uri($coreConfig->getValue('unsecure_backend_base_path'));
}
}
if (!empty($newUri) and $newUri->isValid() and ($newUri->getHost() != '' and $uri->getHost() != $newUri->getHost()) or $newUri->getScheme() != '' and $uri->getScheme() != $newUri->getScheme()) {
$uri->setPort($newUri->getPort());
if ($newUri->getHost() != '') {
$uri->setHost($newUri->getHost());
}
if ($newUri->getScheme() != '') {
$uri->setScheme($newUri->getScheme());
}
$response = $event->getResponse();
$response->setStatusCode(302);
$response->getHeaders()->addHeaderLine('Location', $request->getUri());
$event->stopPropagation();
return $response;
}
}
示例5: write
/**
* Send request to the proxy server with streaming support
*
* @param string $method
* @param \Zend\Uri\Http $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 = '')
{
// If no proxy is set, throw an error
if (!$this->config['proxy_host']) {
throw new Adapter\Exception('No proxy host set!');
}
// Make sure we're properly connected
if (!$this->socket) {
throw new Adapter\Exception('Trying to write but we are not connected');
}
$host = $this->config['proxy_host'];
$port = $this->config['proxy_port'];
if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) {
throw new Adapter\Exception('Trying to write but we are connected to the wrong proxy ' . 'server');
}
// Add Proxy-Authorization header
if ($this->config['proxy_user'] && !isset($headers['proxy-authorization'])) {
$headers['proxy-authorization'] = \Zend\Http\Client::encodeAuthHeader($this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']);
}
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
if ($uri->getScheme() == 'https' && !$this->negotiated) {
$this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
$this->negotiated = true;
}
// Save request method for later
$this->method = $method;
// Build request headers
$request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n";
// Add all headers to the request string
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = "{$k}: {$v}";
}
$request .= "{$v}\r\n";
}
$request .= "\r\n";
// Send the request headers
if (!@fwrite($this->socket, $request)) {
throw new Adapter\Exception('Error writing request to proxy server');
}
//read from $body, write to socket
while ($body->hasData()) {
if (!@fwrite($this->socket, $body->read(self::CHUNK_SIZE))) {
throw new Adapter\Exception('Error writing request to server');
}
}
return 'Large upload, request is not cached.';
}
示例6: ingest
public function ingest(Media $media, Request $request, ErrorStore $errorStore)
{
$data = $request->getContent();
if (!isset($data['o:source'])) {
$errorStore->addError('o:source', 'No YouTube URL specified');
return;
}
$uri = new HttpUri($data['o:source']);
if (!($uri->isValid() && $uri->isAbsolute())) {
$errorStore->addError('o:source', 'Invalid YouTube URL specified');
return;
}
switch ($uri->getHost()) {
case 'www.youtube.com':
if ('/watch' !== $uri->getPath()) {
$errorStore->addError('o:source', 'Invalid YouTube URL specified, missing "/watch" path');
return;
}
$query = $uri->getQueryAsArray();
if (!isset($query['v'])) {
$errorStore->addError('o:source', 'Invalid YouTube URL specified, missing "v" parameter');
return;
}
$youtubeId = $query['v'];
break;
case 'youtu.be':
$youtubeId = substr($uri->getPath(), 1);
break;
default:
$errorStore->addError('o:source', 'Invalid YouTube URL specified, not a YouTube URL');
return;
}
$fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
$file = $this->getServiceLocator()->get('Omeka\\File');
$url = sprintf('http://img.youtube.com/vi/%s/0.jpg', $youtubeId);
$this->downloadFile($url, $file->getTempPath());
$hasThumbnails = $fileManager->storeThumbnails($file);
$media->setData(['id' => $youtubeId, 'start' => $request->getValue('start'), 'end' => $request->getValue('end')]);
if ($hasThumbnails) {
$media->setFilename($file->getStorageName());
$media->setHasThumbnails(true);
}
}
示例7: _doRequest
/**
* Do request proxy method.
*
* @param CommonClient $client Actual SOAP client.
* @param string $request The request body.
* @param string $location The SOAP URI.
* @param string $action The SOAP action to call.
* @param integer $version The SOAP version to use.
* @param integer $one_way (Optional) The number 1 if a response is not expected.
* @return string The XML SOAP response.
*/
public function _doRequest(CommonClient $client, $request, $location, $action, $version, $one_way = null)
{
if (!$this->useNtlm) {
return parent::_doRequest($client, $request, $location, $action, $version, $one_way);
}
$curlClient = $this->getCurlClient();
$headers = array('Content-Type' => 'text/xml; charset=utf-8', 'Method' => 'POST', 'SOAPAction' => '"' . $action . '"', 'User-Agent' => 'PHP-SOAP-CURL');
$uri = new HttpUri($location);
$curlClient->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_NTLM)->setCurlOption(CURLOPT_SSL_VERIFYHOST, false)->setCurlOption(CURLOPT_SSL_VERIFYPEER, false)->setCurlOption(CURLOPT_USERPWD, $this->options['login'] . ':' . $this->options['password']);
// Perform the cURL request and get the response
$curlClient->connect($uri->getHost(), $uri->getPort());
$curlClient->write('POST', $uri, 1.1, $headers, $request);
$response = HttpResponse::fromString($curlClient->read());
$curlClient->close();
// Save headers
$this->lastRequestHeaders = $this->flattenHeaders($headers);
$this->lastResponseHeaders = $response->getHeaders()->toString();
// Return only the XML body
return $response->getBody();
}
示例8: write
/**
* Send request to the remote server with streaming support.
*
* @param string $method
* @param \Zend\Uri\Http $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.';
}
示例9: testUserInfoCanOmitPassword
public function testUserInfoCanOmitPassword()
{
$uri = new HttpUri('http://user@example.com@example.com/');
$uri->normalize();
$this->assertEquals('user@example.com', $uri->getUser());
$this->assertNull($uri->getPassword());
$this->assertEquals('example.com', $uri->getHost());
}
示例10: assemble
/**
* assemble(): defined by Route interface.
*
* @see Route::assemble()
*
* @param array $params
* @param array $options
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @return string
*/
public function assemble(array $params = array(), array $options = array())
{
if (!isset($options['name'])) {
throw new Exception\InvalidArgumentException('Missing "name" option');
}
$names = explode('/', $options['name'], 2);
$route = $this->routes->get($names[0]);
/**#@+
* Load extra routes if called route not found in current route list
*/
if (!$route) {
$route = $this->extraRoute($names[0]);
}
/**#@-**/
if (!$route) {
throw new Exception\RuntimeException(sprintf('Route with name "%s" not found', $names[0]));
}
if (isset($names[1])) {
if (!$route instanceof TreeRouteStack) {
throw new Exception\RuntimeException(sprintf('Route with name "%s" does not have child routes', $names[0]));
}
$options['name'] = $names[1];
} else {
unset($options['name']);
}
if (isset($options['only_return_path']) && $options['only_return_path']) {
return $this->baseUrl . $route->assemble(array_merge($this->defaultParams, $params), $options);
}
if (!isset($options['uri'])) {
$uri = new HttpUri();
if (isset($options['force_canonical']) && $options['force_canonical']) {
if ($this->requestUri === null) {
throw new Exception\RuntimeException('Request URI has not been set');
}
$uri->setScheme($this->requestUri->getScheme())->setHost($this->requestUri->getHost())->setPort($this->requestUri->getPort());
}
$options['uri'] = $uri;
} else {
$uri = $options['uri'];
}
$path = $this->baseUrl . $route->assemble(array_merge($this->defaultParams, $params), $options);
if (isset($options['query'])) {
$uri->setQuery($options['query']);
}
if (isset($options['fragment'])) {
$uri->setFragment($options['fragment']);
}
if (isset($options['force_canonical']) && $options['force_canonical'] || $uri->getHost() !== null || $uri->getScheme() !== null) {
if (($uri->getHost() === null || $uri->getScheme() === null) && $this->requestUri === null) {
throw new Exception\RuntimeException('Request URI has not been set');
}
if ($uri->getHost() === null) {
$uri->setHost($this->requestUri->getHost());
}
if ($uri->getScheme() === null) {
$uri->setScheme($this->requestUri->getScheme());
}
return $uri->setPath($path)->normalize()->toString();
} elseif (!$uri->isAbsolute() && $uri->isValidRelative()) {
return $uri->setPath($path)->normalize()->toString();
}
return $path;
}
示例11: doRequest
/**
* Separating this from send method allows subclasses to wrap
* the interaction with the adapter
*
* @param Http $uri
* @param string $method
* @param bool $secure
* @param array $headers
* @param string $body
* @return string the raw response
* @throws Exception\RuntimeException
*/
protected function doRequest(Http $uri, $method, $secure = false, $headers = array(), $body = '')
{
// Open the connection, send the request and read the response
$this->adapter->connect($uri->getHost(), $uri->getPort(), $secure);
if ($this->config['outputstream']) {
if ($this->adapter instanceof Client\Adapter\StreamInterface) {
$stream = $this->openTempStream();
$this->adapter->setOutputStream($stream);
} else {
throw new Exception\RuntimeException('Adapter does not support streaming');
}
}
// HTTP connection
$this->lastRawRequest = $this->adapter->write($method, $uri, $this->config['httpversion'], $headers, $body);
return $this->adapter->read();
}
示例12: assemble
/**
* assemble(): defined by Route interface.
*
* @see BaseRoute::assemble()
* @param array $params
* @param array $options
* @return mixed
*/
public function assemble(array $params = array(), array $options = array())
{
if (!isset($options['name'])) {
throw new Exception\InvalidArgumentException('Missing "name" option');
}
$names = explode('/', $options['name'], 2);
$route = $this->routes->get($names[0]);
if (!$route) {
throw new Exception\RuntimeException(sprintf('Route with name "%s" not found', $names[0]));
}
if (isset($names[1])) {
$options['name'] = $names[1];
} else {
unset($options['name']);
}
if (!isset($options['uri'])) {
$uri = new HttpUri();
if (isset($options['absolute']) && $options['absolute']) {
if ($this->requestUri === null) {
throw new Exception\RuntimeException('Request URI has not been set');
}
$uri->setScheme($this->requestUri->getScheme())->setHost($this->requestUri->getHost())->setPort($this->requestUri->getPort());
}
$options['uri'] = $uri;
}
$path = $this->baseUrl . $route->assemble($params, $options);
if (isset($uri)) {
if (isset($options['absolute']) && $options['absolute']) {
return $uri->setPath($path)->toString();
} elseif ($uri->getHost() !== null) {
if ($uri->scheme !== null) {
if ($this->requestUri === null) {
throw new Exception\RuntimeException('Request URI has not been set');
}
$uri->setScheme($this->requestUri->getScheme());
}
return $uri->setPath($path)->toString();
}
}
return $path;
}
示例13: doRequest
/**
* Separating this from send method allows subclasses to wrap
* the interaction with the adapter
*
* @param Http $uri
* @param string $method
* @param bool $secure
* @param array $headers
* @param string $body
* @return string the raw response
* @throws Exception\RuntimeException
*/
protected function doRequest(Http $uri, $method, $secure = false, $headers = array(), $body = '')
{
// Open the connection, send the request and read the response
$this->adapter->connect($uri->getHost(), $uri->getPort(), $secure);
if ($this->config['outputstream']) {
if ($this->adapter instanceof ZendClient\Adapter\StreamInterface) {
$stream = $this->openTempStream();
$this->adapter->setOutputStream($stream);
} else {
throw new Exception\RuntimeException('Adapter does not support streaming');
}
}
// HTTP connection
$uri->setPath('/ZendServer/test.php');
$headers['Content-Length'] = strlen($body) + $this->filesContentLength();
$this->lastRawRequest = $this->adapter->write($method, $uri, $this->config['httpversion'], $headers, '');
$this->writeChunk($body);
// Encode files
foreach ($this->getRequest()->getFiles()->toArray() as $key => $file) {
$this->writeFile($key, $file['formname']);
}
$this->writeChunk("--" . $this->boundary . "--\r\n");
$this->writeChunk('');
return $this->adapter->read();
}