本文整理汇总了PHP中IP::combineHostAndPort方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::combineHostAndPort方法的具体用法?PHP IP::combineHostAndPort怎么用?PHP IP::combineHostAndPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::combineHostAndPort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: detectServer
/**
* Work out an appropriate URL prefix containing scheme and host, based on
* information detected from $_SERVER
*
* @return string
*/
public static function detectServer()
{
list($proto, $stdPort) = self::detectProtocolAndStdPort();
$varNames = array('HTTP_HOST', 'SERVER_NAME', 'HOSTNAME', 'SERVER_ADDR');
$host = 'localhost';
$port = $stdPort;
foreach ($varNames as $varName) {
if (!isset($_SERVER[$varName])) {
continue;
}
$parts = IP::splitHostAndPort($_SERVER[$varName]);
if (!$parts) {
// Invalid, do not use
continue;
}
$host = $parts[0];
if ($parts[1] === false) {
if (isset($_SERVER['SERVER_PORT'])) {
$port = $_SERVER['SERVER_PORT'];
}
// else leave it as $stdPort
} else {
$port = $parts[1];
}
break;
}
return $proto . '://' . IP::combineHostAndPort($host, $port, $stdPort);
}
示例2: detectServer
/**
* Work out an appropriate URL prefix containing scheme and host, based on
* information detected from $_SERVER
*
* @return string
*/
public static function detectServer()
{
global $wgAssumeProxiesUseDefaultProtocolPorts;
$proto = self::detectProtocol();
$stdPort = $proto === 'https' ? 443 : 80;
$varNames = array('HTTP_HOST', 'SERVER_NAME', 'HOSTNAME', 'SERVER_ADDR');
$host = 'localhost';
$port = $stdPort;
foreach ($varNames as $varName) {
if (!isset($_SERVER[$varName])) {
continue;
}
$parts = IP::splitHostAndPort($_SERVER[$varName]);
if (!$parts) {
// Invalid, do not use
continue;
}
$host = $parts[0];
if ($wgAssumeProxiesUseDefaultProtocolPorts && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
// Bug 70021: Assume that upstream proxy is running on the default
// port based on the protocol. We have no reliable way to determine
// the actual port in use upstream.
$port = $stdPort;
} elseif ($parts[1] === false) {
if (isset($_SERVER['SERVER_PORT'])) {
$port = $_SERVER['SERVER_PORT'];
}
// else leave it as $stdPort
} else {
$port = $parts[1];
}
break;
}
return $proto . '://' . IP::combineHostAndPort($host, $port, $stdPort);
}
示例3: testCombineHostAndPort
/**
* Test for IP::combineHostAndPort()
* @dataProvider provideCombineHostAndPort
*/
function testCombineHostAndPort($expected, $input, $description)
{
list($host, $port, $defaultPort) = $input;
$this->assertEquals($expected, IP::combineHostAndPort($host, $port, $defaultPort), $description);
}
示例4: streamThumbnail
//.........这里部分代码省略.........
if ( is_null( $wgVipsThumbnailerHost ) || $request->getBool( 'noproxy' ) ) {
# No remote scaler, need to do it ourselves.
# Emulate the BitmapHandlerTransform hook
$dstPath = VipsCommand::makeTemp( $file->getExtension() );
$dstUrl = '';
wfDebug( __METHOD__ . ": Creating vips thumbnail at $dstPath\n" );
$scalerParams = array(
# The size to which the image will be resized
'physicalWidth' => $params['physicalWidth'],
'physicalHeight' => $params['physicalHeight'],
'physicalDimensions' => "{$params['physicalWidth']}x{$params['physicalHeight']}",
# The size of the image on the page
'clientWidth' => $params['width'],
'clientHeight' => $params['height'],
# Comment as will be added to the EXIF of the thumbnail
'comment' => isset( $params['descriptionUrl'] ) ?
"File source: {$params['descriptionUrl']}" : '',
# Properties of the original image
'srcWidth' => $file->getWidth(),
'srcHeight' => $file->getHeight(),
'mimeType' => $file->getMimeType(),
'srcPath' => $file->getPath(),
'dstPath' => $dstPath,
'dstUrl' => $dstUrl,
);
$options = array();
if ( $request->getBool( 'bilinear' ) ) {
$options['bilinear'] = true;
wfDebug( __METHOD__ . ": using bilinear scaling\n" );
}
if ( $request->getVal( 'sharpen' ) && $request->getVal( 'sharpen' ) < 5 ) {
# Limit sharpen sigma to 5, otherwise we have to write huge convolution matrices
$options['sharpen'] = array( 'sigma' => floatval( $request->getVal( 'sharpen' ) ) );
wfDebug( __METHOD__ . ": sharpening with radius {$options['sharpen']}\n" );
}
# Call the hook
$mto = null;
VipsScaler::doTransform( $handler, $file, $scalerParams, $options, $mto );
if ( $mto && !$mto->isError() ) {
wfDebug( __METHOD__ . ": streaming thumbnail...\n" );
$this->getOutput()->disable();
StreamFile::stream( $dstPath, array(
"Cache-Control: public, max-age=$wgVipsTestExpiry, s-maxage=$wgVipsTestExpiry",
'Expires: ' . gmdate( 'r ', time() + $wgVipsTestExpiry )
) );
} else {
$this->streamError( 500, $mto->getHtmlMsg() );
}
# Cleanup the temporary file
wfSuppressWarnings();
unlink( $dstPath );
wfRestoreWarnings();
} else {
# Request the thumbnail at a remote scaler
$url = wfExpandUrl( $request->getRequestURL(), PROTO_INTERNAL );
$url = wfAppendQuery( $url, array( 'noproxy' => '1' ) );
wfDebug( __METHOD__ . ": Getting vips thumb from remote url $url\n" );
$bits = IP::splitHostAndPort( $wgVipsThumbnailerHost );
if ( !$bits ) {
throw new MWException( __METHOD__.': $wgVipsThumbnailerHost is not set to a valid host' );
}
list( $host, $port ) = $bits;
if ( $port === false ) {
$port = 80;
}
$proxy = IP::combineHostAndPort( $host, $port );
$options = array(
'method' => 'GET',
'proxy' => $proxy,
);
$req = MWHttpRequest::factory( $url, $options );
$status = $req->execute();
if ( $status->isOk() ) {
# Disable output and stream the file
$this->getOutput()->disable();
wfResetOutputBuffers();
header( 'Content-Type: ' . $file->getMimeType() );
header( 'Content-Length: ' . strlen( $req->getContent() ) );
header( "Cache-Control: public, max-age=$wgVipsTestExpiry, s-maxage=$wgVipsTestExpiry" );
header( 'Expires: ' . gmdate( 'r ', time() + $wgVipsTestExpiry ) );
print $req->getContent();
} elseif ( $status->hasMessage( 'http-bad-status' ) ) {
$this->streamError( 500, $req->getContent() );
return;
} else {
global $wgOut;
$this->streamError( 500, $wgOut->parse( $status->getWikiText() ) );
return;
}
}
}