本文整理汇总了PHP中S3::hasAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::hasAuth方法的具体用法?PHP S3::hasAuth怎么用?PHP S3::hasAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类S3
的用法示例。
在下文中一共展示了S3::hasAuth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getResponse
public function _getResponse(S3 $s3, $url, $headers, $amz)
{
$req = new HTTP_Request2($url, $this->verb);
if (!$s3->useSSLValidation) {
$req->setConfig('ssl_verify_host', false);
$req->setConfig('ssl_verify_peer', false);
}
if ($s3->proxy != null && isset($s3->proxy['host'])) {
$req->setConfig('proxy_host');
$req->setConfig('proxy_host', $s3->proxy['host']);
if (isset($s3->proxy['user'], $s3->proxy['pass']) && $proxy['user'] != null && $proxy['pass'] != null) {
$req->setConfig('proxy_user', $s3->proxy['user']);
$req->setConfig('proxy_password', $s3->proxy['pass']);
}
}
if ($s3->hasAuth()) {
// Authorization string (CloudFront stringToSign should only contain a date)
$headers[] = 'Authorization: ' . $s3->__getSignature($this->headers['Host'] == 'cloudfront.amazonaws.com' ? $this->headers['Date'] : $this->verb . "\n" . $this->headers['Content-MD5'] . "\n" . $this->headers['Content-Type'] . "\n" . $this->headers['Date'] . $amz . "\n" . $this->resource);
}
$req->setHeader($headers);
$req->setConfig('follow_redirects', true);
// Request types
switch ($this->verb) {
case 'GET':
break;
case 'PUT':
case 'POST':
// POST only used for CloudFront
if ($this->fp !== false) {
$req->setBody($this->fp);
} elseif ($this->data !== false) {
$req->setBody($this->data);
}
break;
}
try {
$res = $req->send();
} catch (HTTP_Request2_Exception $e) {
$this->response->error = array('code' => $e->getCode(), 'message' => $e->getMessage(), 'resource' => $this->resource);
}
$this->response->code = $res->getStatus();
$this->response->body = $res->getBody();
$this->response->headers = $this->modHeaders($res->getHeader());
return $this->response;
}
示例2: getResponse
/**
* Get the S3 response
*
* @return object | false
*/
public function getResponse()
{
$query = '';
if (sizeof($this->parameters) > 0) {
$query = substr($this->uri, -1) !== '?' ? '?' : '&';
foreach ($this->parameters as $var => $value) {
if ($value == null || $value == '') {
$query .= $var . '&';
} else {
$query .= $var . '=' . rawurlencode($value) . '&';
}
}
$query = substr($query, 0, -1);
$this->uri .= $query;
if (array_key_exists('acl', $this->parameters) || array_key_exists('location', $this->parameters) || array_key_exists('torrent', $this->parameters) || array_key_exists('website', $this->parameters) || array_key_exists('logging', $this->parameters)) {
$this->resource .= $query;
}
}
$url = (S3::$useSSL ? 'https://' : 'http://') . ($this->headers['Host'] !== '' ? $this->headers['Host'] : $this->endpoint) . $this->uri;
//var_dump('bucket: ' . $this->bucket, 'uri: ' . $this->uri, 'resource: ' . $this->resource, 'url: ' . $url);
// Basic setup
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERAGENT, 'S3/php');
if (S3::$useSSL) {
// Set protocol version
curl_setopt($curl, CURLOPT_SSLVERSION, S3::$useSSLVersion);
// SSL Validation can now be optional for those with broken OpenSSL installations
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, S3::$useSSLValidation ? 2 : 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, S3::$useSSLValidation ? 1 : 0);
if (S3::$sslKey !== null) {
curl_setopt($curl, CURLOPT_SSLKEY, S3::$sslKey);
}
if (S3::$sslCert !== null) {
curl_setopt($curl, CURLOPT_SSLCERT, S3::$sslCert);
}
if (S3::$sslCACert !== null) {
curl_setopt($curl, CURLOPT_CAINFO, S3::$sslCACert);
}
}
curl_setopt($curl, CURLOPT_URL, $url);
if (S3::$proxy != null && isset(S3::$proxy['host'])) {
curl_setopt($curl, CURLOPT_PROXY, S3::$proxy['host']);
curl_setopt($curl, CURLOPT_PROXYTYPE, S3::$proxy['type']);
if (isset(S3::$proxy['user'], S3::$proxy['pass']) && S3::$proxy['user'] != null && S3::$proxy['pass'] != null) {
curl_setopt($curl, CURLOPT_PROXYUSERPWD, sprintf('%s:%s', S3::$proxy['user'], S3::$proxy['pass']));
}
}
// Headers
$headers = array();
$amz = array();
foreach ($this->amzHeaders as $header => $value) {
if (strlen($value) > 0) {
$headers[] = $header . ': ' . $value;
}
}
foreach ($this->headers as $header => $value) {
if (strlen($value) > 0) {
$headers[] = $header . ': ' . $value;
}
}
// Collect AMZ headers for signature
foreach ($this->amzHeaders as $header => $value) {
if (strlen($value) > 0) {
$amz[] = strtolower($header) . ':' . $value;
}
}
// AMZ headers must be sorted
if (sizeof($amz) > 0) {
//sort($amz);
usort($amz, array(&$this, '__sortMetaHeadersCmp'));
$amz = "\n" . implode("\n", $amz);
} else {
$amz = '';
}
if (S3::hasAuth()) {
// Authorization string (CloudFront stringToSign should only contain a date)
if ($this->headers['Host'] == 'cloudfront.amazonaws.com') {
$headers[] = 'Authorization: ' . S3::__getSignature($this->headers['Date']);
} else {
$headers[] = 'Authorization: ' . S3::__getSignature($this->verb . "\n" . $this->headers['Content-MD5'] . "\n" . $this->headers['Content-Type'] . "\n" . $this->headers['Date'] . $amz . "\n" . $this->resource);
}
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, CURLOPT_WRITEFUNCTION, array(&$this, '__responseWriteCallback'));
curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this, '__responseHeaderCallback'));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
// Request types
switch ($this->verb) {
case 'GET':
break;
case 'PUT':
case 'POST':
// POST only used for CloudFront
//.........这里部分代码省略.........
示例3: _getResponse
public function _getResponse(S3 $s3, $url, $headers, $amz)
{
$req = new HTTP_Request2($url, $this->verb);
if (!$s3->useSSLValidation) {
$req->setConfig('ssl_verify_host', false);
$req->setConfig('ssl_verify_peer', false);
}
if ($s3->proxy != null && isset($s3->proxy['host'])) {
$req->setConfig('proxy_host');
$req->setConfig('proxy_host', $s3->proxy['host']);
if (isset($s3->proxy['user'], $s3->proxy['pass']) && $proxy['user'] != null && $proxy['pass'] != null) {
$req->setConfig('proxy_user', $s3->proxy['user']);
$req->setConfig('proxy_password', $s3->proxy['pass']);
}
}
if ($s3->hasAuth()) {
$headers = http_parse_headers(implode("\n", $headers) . $amz . "\n");
$headers = $this->signRequest($s3, $headers);
$req->setHeader($headers);
}
$req->setConfig('follow_redirects', true);
// Request types
switch ($this->verb) {
case 'GET':
break;
case 'PUT':
case 'POST':
// POST only used for CloudFront
if ($this->fp !== false) {
$req->setBody($this->fp);
} elseif ($this->data !== false) {
$req->setBody($this->data);
}
break;
}
try {
$res = $req->send();
$this->response->code = $res->getStatus();
$this->response->body = $res->getBody();
$this->response->headers = $this->modHeaders($res->getHeader());
} catch (HTTP_Request2_Exception $e) {
$this->response->error = array('code' => $e->getCode(), 'message' => $e->getMessage(), 'resource' => $this->resource);
}
return $this->response;
}