Skip to content

Commit

Permalink
Merge pull request #241 from jemygraw/master
Browse files Browse the repository at this point in the history
use `phpcs --standard=PSR2` to fix the code style
  • Loading branch information
jemygraw authored Aug 22, 2017
2 parents 66381af + fb9dc1a commit 80de39b
Show file tree
Hide file tree
Showing 30 changed files with 119 additions and 114 deletions.
10 changes: 8 additions & 2 deletions examples/cdn_get_bandwidth.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@
$granularity = "day";

//获取带宽数据
list($bandwidthData, $getBandwidthErr) = $cdnManager->getBandwidthData($domains, $startDate, $endDate, $granularity);
list($bandwidthData, $getBandwidthErr) = $cdnManager->getBandwidthData(
$domains,
$startDate,
$endDate,
$granularity
);

if ($getBandwidthErr != null) {
var_dump($getBandwidthErr);
} else {
echo "get bandwidth data success\n";
print_r($bandwidthData);
}
}
2 changes: 1 addition & 1 deletion examples/cdn_get_log_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"phpsdk.qiniudn.com"
);

$logDate='2017-08-20';
$logDate = '2017-08-20';

//获取日志下载链接
//参考文档:http://developer.qiniu.com/article/fusion/api/log.html
Expand Down
1 change: 0 additions & 1 deletion examples/cdn_refresh_urls_dirs.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@
echo "refresh request sent\n";
print_r($refreshResult);
}

7 changes: 4 additions & 3 deletions examples/pfop_vframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
$notifyUrl = 'http://375dec79.ngrok.com/notify.php';
$force = false;

$config =new \Qiniu\Config();
$config->useHTTPS=true;
$config = new \Qiniu\Config();
$config->useHTTPS = true;
$pfop = new PersistentFop($auth, $config);

//要进行视频截图操作
$fops = "vframe/jpg/offset/1/w/480/h/360/rotate/90|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_480x360.jpg");
$fops = "vframe/jpg/offset/1/w/480/h/360/rotate/90|saveas/" .
\Qiniu\base64_urlSafeEncode($bucket . ":qiniu_480x360.jpg");

list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
echo "\n====> pfop avthumb result: \n";
Expand Down
3 changes: 2 additions & 1 deletion examples/pfop_watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
$base64URL = Qiniu\base64_urlSafeEncode('http://devtools.qiniu.com/qiniu.png');

//水印参数
$fops = "avthumb/mp4/s/640x360/vb/1.4m/image/" . $base64URL . "|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_wm.mp4");
$fops = "avthumb/mp4/s/640x360/vb/1.4m/image/" . $base64URL . "|saveas/"
. \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_wm.mp4");

list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
echo "\n====> pfop avthumb result: \n";
Expand Down
4 changes: 2 additions & 2 deletions examples/qetag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require_once __DIR__ . '/../autoload.php';
use Qiniu\Etag;

$localFile="/Users/jemy/Documents/qiniu.mp4";
$localFile = "/Users/jemy/Documents/qiniu.mp4";
list($etag, $err) = Etag::sum($localFile);
if ($err == null) {
echo "Etag: $etag";
echo "Etag: $etag";
} else {
var_dump($err);
}
4 changes: 2 additions & 2 deletions examples/rs_change_mime.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
$bucket = getenv('QINIU_TEST_BUCKET');

$key = 'qiniu.mp4';
$newMime='video/x-mp4';
$newMime = 'video/x-mp4';

$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);

$err = $bucketManager->changeMime($bucket,$key,$newMime);
$err = $bucketManager->changeMime($bucket, $key, $newMime);
if ($err) {
print_r($err);
}
2 changes: 1 addition & 1 deletion examples/rs_delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
$err = $bucketManager->delete($bucket, $key);
if ($err) {
print_r($err);
}
}
4 changes: 2 additions & 2 deletions examples/rs_stat.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
$secretKey = getenv('QINIU_SECRET_KEY');
$bucket = getenv('QINIU_TEST_BUCKET');

$key="qiniu.mp4";
$key = "qiniu.mp4";
$auth = new Auth($accessKey, $secretKey);
$config = new \Qiniu\Config();
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
list($fileInfo,$err)=$bucketManager->stat($bucket, $key);
list($fileInfo, $err) = $bucketManager->stat($bucket, $key);
if ($err) {
print_r($err);
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/rsf_list_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
echo "\n====> list file err: \n";
var_dump($err);
} else {
if(array_key_exists('marker',$ret)) {
if (array_key_exists('marker', $ret)) {
echo "Marker:" . $ret["marker"] . "\n";
}
echo "\nList Iterms====>\n";
Expand Down
8 changes: 4 additions & 4 deletions examples/saveas.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
$secretKey = 'Secret_Key';

//生成EncodedEntryURI的值
$entry='<bucket>:<Key>';//<Key>为生成缩略图的文件名
$entry = '<bucket>:<Key>';//<Key>为生成缩略图的文件名
//生成的值
$encodedEntryURI=\Qiniu\base64_urlSafeEncode($entry);
$encodedEntryURI = \Qiniu\base64_urlSafeEncode($entry);

//使用SecretKey对新的下载URL进行HMAC1-SHA1签名
$newurl = "78re52.com1.z0.glb.clouddn.com/resource/Ship.jpg?imageView2/2/w/200/h/200|saveas/".$encodedEntryURI;
$newurl = "78re52.com1.z0.glb.clouddn.com/resource/Ship.jpg?imageView2/2/w/200/h/200|saveas/" . $encodedEntryURI;

$sign = hash_hmac("sha1", $newurl, $secretKey, true);

//对签名进行URL安全的Base64编码
$encodedSign = \Qiniu\base64_urlSafeEncode($sign);
//最终得到的完整下载URL
$finalURL = "http://".$newurl."/sign/".$accessKey.":".$encodedSign;
$finalURL = "http://" . $newurl . "/sign/" . $accessKey . ":" . $encodedSign;

$callbackBody = file_get_contents("$finalURL");

Expand Down
2 changes: 1 addition & 1 deletion examples/upload_and_pfop.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();

$pfop = "imageMogr2/rotate/90|saveas/".\Qiniu\base64_urlSafeEncode($bucket.":php-logo-rotate.png");
$pfop = "imageMogr2/rotate/90|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":php-logo-rotate.png");

//转码完成后通知到你的业务服务器。(公网可以访问,并相应200 OK)
$notifyUrl = 'http://notify.fake.com';
Expand Down
2 changes: 1 addition & 1 deletion examples/upload_tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
'persistentNotifyUrl' => "http://api.example.com/qiniu/pfop/notify",
);
$upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
print($upToken . "\n");
print($upToken . "\n");
6 changes: 3 additions & 3 deletions src/Qiniu/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function uploadToken(
$args = self::copyPolicy($args, $policy, $strictPolicy);
$args['scope'] = $scope;
$args['deadline'] = $deadline;

$b = json_encode($args);
return $this->signWithData($b);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public function uploadToken(
'persistentOps',
'persistentNotifyUrl',
'persistentPipeline',

'deleteAfterDays',
'fileType',
'isPrefixalScope',
Expand All @@ -130,7 +130,7 @@ private static function copyPolicy(&$policy, $originPolicy, $strictPolicy)
return array();
}
foreach ($originPolicy as $key => $value) {
if (!$strictPolicy || in_array((string) $key, self::$policyFields, true)) {
if (!$strictPolicy || in_array((string)$key, self::$policyFields, true)) {
$policy[$key] = $value;
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/Qiniu/Cdn/CdnManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(Auth $auth)
}

/**
* @param array $urls 待刷新的文件链接数组
* @param array $urls 待刷新的文件链接数组
* @return array
*/
public function refreshUrls(array $urls)
Expand All @@ -28,7 +28,7 @@ public function refreshUrls(array $urls)
}

/**
* @param array $dirs 待刷新的文件链接数组
* @param array $dirs 待刷新的文件链接数组
* @return array
* 目前客户默认没有目录刷新权限,刷新会有400038报错,参考:https://developer.qiniu.com/fusion/api/1229/cache-refresh
* 需要刷新目录请工单联系技术支持 https://support.qiniu.com/tickets/category
Expand Down Expand Up @@ -82,9 +82,9 @@ public function prefetchUrls(array $urls)
}

/**
* @param array $domains 待获取带宽数据的域名数组
* @param string $startDate 开始的日期,格式类似 2017-01-01
* @param string $endDate 结束的日期,格式类似 2017-01-01
* @param array $domains 待获取带宽数据的域名数组
* @param string $startDate 开始的日期,格式类似 2017-01-01
* @param string $endDate 结束的日期,格式类似 2017-01-01
* @param string $granularity 获取数据的时间间隔,可以是 5min, hour 或者 day
*
* @return array 带宽数据和错误信息,参考 examples/cdn_manager.php 代码
Expand All @@ -105,9 +105,9 @@ public function getBandwidthData(array $domains, $startDate, $endDate, $granular
}

/**
* @param array $domains 待获取流量数据的域名数组
* @param string $startDate 开始的日期,格式类似 2017-01-01
* @param string $endDate 结束的日期,格式类似 2017-01-01
* @param array $domains 待获取流量数据的域名数组
* @param string $startDate 开始的日期,格式类似 2017-01-01
* @param string $endDate 结束的日期,格式类似 2017-01-01
* @param string $granularity 获取数据的时间间隔,可以是 5min, hour 或者 day
*
* @return array 流量数据和错误信息,参考 examples/cdn_manager.php 代码
Expand All @@ -128,7 +128,7 @@ public function getFluxData(array $domains, $startDate, $endDate, $granularity)
}

/**
* @param array $domains 待获取日志下载链接的域名数组
* @param array $domains 待获取日志下载链接的域名数组
* @param string $logDate 获取指定日期的日志下载链接,格式类似 2017-01-01
*
* @return array 日志下载链接数据和错误信息,参考 examples/cdn_manager.php 代码
Expand Down Expand Up @@ -161,9 +161,9 @@ private function post($url, $body)
/**
* 构建时间戳防盗链鉴权的访问外链
*
* @param string $rawUrl 需要签名的资源url
* @param string $encryptKey 时间戳防盗链密钥
* @param string $durationInSeconds 链接的有效期(以秒为单位)
* @param string $rawUrl 需要签名的资源url
* @param string $encryptKey 时间戳防盗链密钥
* @param string $durationInSeconds 链接的有效期(以秒为单位)
*
* @return string 带鉴权信息的资源外链,参考 examples/cdn_timestamp_antileech.php 代码
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Qiniu/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getUpHost($accessKey, $bucket)

public function getUpBackupHost($accessKey, $bucket)
{
$zone=$this->getZone($accessKey, $bucket);
$zone = $this->getZone($accessKey, $bucket);
if ($this->useHTTPS === true) {
$scheme = "https://";
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/Qiniu/Etag.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function sum($filename)

$fstat = fstat($fhandler);
$fsize = $fstat['size'];
if ((int) $fsize === 0) {
if ((int)$fsize === 0) {
fclose($fhandler);
return array('Fto5o-5ea0sNMlW_75VgGJCv2AcJ', null);
}
Expand All @@ -52,12 +52,12 @@ public static function sum($filename)
fclose($fhandler);
return array(null, $err);
}
list($sha1Code, ) = self::calcSha1($fdata);
list($sha1Code,) = self::calcSha1($fdata);
$sha1Buf = array_merge($sha1Buf, $sha1Code);
} else {
array_push($sha1Buf, 0x96);
$sha1BlockBuf = array();
for ($i=0; $i < $blockCnt; $i++) {
for ($i = 0; $i < $blockCnt; $i++) {
$fdata = fread($fhandler, Config::BLOCK_SIZE);
list($sha1Code, $err) = self::calcSha1($fdata);
if ($err !== null) {
Expand All @@ -67,7 +67,7 @@ public static function sum($filename)
$sha1BlockBuf = array_merge($sha1BlockBuf, $sha1Code);
}
$tmpData = self::packArray('C*', $sha1BlockBuf);
list($sha1Final, ) = self::calcSha1($tmpData);
list($sha1Final,) = self::calcSha1($tmpData);
$sha1Buf = array_merge($sha1Buf, $sha1Final);
}
$etag = \Qiniu\base64_urlSafeEncode(self::packArray('C*', $sha1Buf));
Expand Down
6 changes: 3 additions & 3 deletions src/Qiniu/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function sendRequest($request)
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HEADER => true,
CURLOPT_NOBODY => false,
CURLOPT_CUSTOMREQUEST => $request->method,
CURLOPT_CUSTOMREQUEST => $request->method,
CURLOPT_URL => $request->url
);

Expand All @@ -106,7 +106,7 @@ public static function sendRequest($request)
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$t2 = microtime(true);
$duration = round($t2-$t1, 3);
$duration = round($t2 - $t1, 3);
$ret = curl_errno($ch);
if ($ret !== 0) {
$r = new Response(-1, $duration, array(), null, curl_error($ch));
Expand All @@ -128,7 +128,7 @@ private static function parseHeaders($raw)
foreach ($headerLines as $line) {
$headerLine = trim($line);
$kv = explode(':', $headerLine);
if (count($kv) >1) {
if (count($kv) > 1) {
$headers[$kv[0]] = trim($kv[1]);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Qiniu/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function __construct($code, $duration, array $headers = array(), $body =
if (self::isJson($headers)) {
try {
$jsonData = self::bodyJson($body);
if ($code >=400) {
if ($code >= 400) {
$this->error = $body;
if ($jsonData['error'] !== null) {
$this->error = $jsonData['error'];
Expand All @@ -117,7 +117,7 @@ public function __construct($code, $duration, array $headers = array(), $body =
$this->error = $e->getMessage();
}
}
} elseif ($code >=400) {
} elseif ($code >= 400) {
$this->error = $body;
}
return;
Expand All @@ -130,7 +130,7 @@ public function json()

private static function bodyJson($body)
{
return \Qiniu\json_decode((string) $body, true, 512);
return \Qiniu\json_decode((string)$body, true, 512);
}

public function xVia()
Expand Down Expand Up @@ -163,7 +163,7 @@ public function ok()
public function needRetry()
{
$code = $this->statusCode;
if ($code< 0 || ($code / 100 === 5 and $code !== 579) || $code === 996) {
if ($code < 0 || ($code / 100 === 5 and $code !== 579) || $code === 996) {
return true;
}
}
Expand Down
Loading

0 comments on commit 80de39b

Please sign in to comment.