📦 更新thinkphp(v5.1.37.1)
This commit is contained in:
Generated
+45
-41
@@ -21,7 +21,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -68,7 +68,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -170,7 +170,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -241,7 +241,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -285,20 +285,20 @@
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "1.5.2",
|
||||
"version": "1.6.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "9f83dded91781a01c63574e387eaa769be769115"
|
||||
"reference": "239400de7a173fe9901b9ac7c06497751f00727a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115",
|
||||
"reference": "9f83dded91781a01c63574e387eaa769be769115",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a",
|
||||
"reference": "239400de7a173fe9901b9ac7c06497751f00727a",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -306,18 +306,22 @@
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"psr/http-message": "~1.0",
|
||||
"ralouphie/getallheaders": "^2.0.5"
|
||||
"ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-zlib": "*",
|
||||
"phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8"
|
||||
},
|
||||
"suggest": {
|
||||
"zendframework/zend-httphandlerrunner": "Emit PSR-7 responses"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.5-dev"
|
||||
"dev-master": "1.6-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@@ -354,7 +358,7 @@
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"time": "2018-12-04T20:46:45+00:00"
|
||||
"time": "2019-07-01T23:21:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpmailer/phpmailer",
|
||||
@@ -371,7 +375,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -443,7 +447,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -499,7 +503,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -538,20 +542,20 @@
|
||||
},
|
||||
{
|
||||
"name": "qiniu/php-sdk",
|
||||
"version": "v7.2.7",
|
||||
"version": "v7.2.9",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/qiniu/php-sdk.git",
|
||||
"reference": "88d11a5857ebc6871204e9be6ceec54bf5f381e6"
|
||||
"reference": "afe7d8715d8a688b1d8d8cdf031240d2363dad90"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/qiniu/php-sdk/zipball/88d11a5857ebc6871204e9be6ceec54bf5f381e6",
|
||||
"reference": "88d11a5857ebc6871204e9be6ceec54bf5f381e6",
|
||||
"url": "https://api.github.com/repos/qiniu/php-sdk/zipball/afe7d8715d8a688b1d8d8cdf031240d2363dad90",
|
||||
"reference": "afe7d8715d8a688b1d8d8cdf031240d2363dad90",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -591,34 +595,34 @@
|
||||
"sdk",
|
||||
"storage"
|
||||
],
|
||||
"time": "2018-11-06T13:34:32+00:00"
|
||||
"time": "2019-07-09T07:55:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "ralouphie/getallheaders",
|
||||
"version": "2.0.5",
|
||||
"version": "3.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ralouphie/getallheaders.git",
|
||||
"reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa"
|
||||
"reference": "120b605dfeb996808c31b6477290a714d356e822"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa",
|
||||
"reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa",
|
||||
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
|
||||
"reference": "120b605dfeb996808c31b6477290a714d356e822",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~3.7.0",
|
||||
"satooshi/php-coveralls": ">=1.0"
|
||||
"php-coveralls/php-coveralls": "^2.1",
|
||||
"phpunit/phpunit": "^5 || ^6.5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@@ -637,7 +641,7 @@
|
||||
}
|
||||
],
|
||||
"description": "A polyfill for getallheaders.",
|
||||
"time": "2016-02-11T07:05:27+00:00"
|
||||
"time": "2019-03-08T08:55:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/event-dispatcher",
|
||||
@@ -654,7 +658,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -707,20 +711,20 @@
|
||||
},
|
||||
{
|
||||
"name": "topthink/framework",
|
||||
"version": "v5.1.36",
|
||||
"version": "v5.1.37.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/top-think/framework.git",
|
||||
"reference": "135eee67ce9ee0b07da201f743d7dd88ec431abb"
|
||||
"reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/135eee67ce9ee0b07da201f743d7dd88ec431abb",
|
||||
"reference": "135eee67ce9ee0b07da201f743d7dd88ec431abb",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/05eecd121d18d6705aaa10aa44fcdf7c14da4d0b",
|
||||
"reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -760,7 +764,7 @@
|
||||
"orm",
|
||||
"thinkphp"
|
||||
],
|
||||
"time": "2019-04-28T08:56:58+00:00"
|
||||
"time": "2019-05-28T06:57:29+00:00"
|
||||
},
|
||||
{
|
||||
"name": "topthink/think-captcha",
|
||||
@@ -777,7 +781,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -822,7 +826,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -868,7 +872,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -915,7 +919,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
|
||||
@@ -20,7 +20,7 @@ use think\route\Dispatch;
|
||||
*/
|
||||
class App extends Container
|
||||
{
|
||||
const VERSION = '5.1.36 LTS';
|
||||
const VERSION = '5.1.37 LTS';
|
||||
|
||||
/**
|
||||
* 当前模块路径
|
||||
|
||||
@@ -487,12 +487,17 @@ class Console
|
||||
public function getNamespaces()
|
||||
{
|
||||
$namespaces = [];
|
||||
foreach ($this->commands as $command) {
|
||||
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
|
||||
foreach ($this->commands as $name => $command) {
|
||||
if (is_string($command)) {
|
||||
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($name));
|
||||
} else {
|
||||
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
|
||||
|
||||
foreach ($command->getAliases() as $alias) {
|
||||
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
|
||||
foreach ($command->getAliases() as $alias) {
|
||||
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_filter($namespaces)));
|
||||
|
||||
@@ -571,7 +571,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$this->autoRelationUpdate();
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
} elseif ($this->autoWriteTimestamp && $this->updateTime && !isset($data[$this->updateTime])) {
|
||||
// 自动写入更新时间
|
||||
$data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);
|
||||
|
||||
@@ -519,7 +519,7 @@ class Validate
|
||||
|
||||
if (isset($this->append[$field])) {
|
||||
// 追加额外的验证规则
|
||||
$rules = array_unique(array_merge($rules, $this->append[$field]));
|
||||
$rules = array_unique(array_merge($rules, $this->append[$field]), SORT_REGULAR);
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
||||
-2
@@ -249,7 +249,6 @@ abstract class Driver
|
||||
{
|
||||
if ($this->tag) {
|
||||
$key = $this->getTagkey($this->tag);
|
||||
$prev = $this->tag;
|
||||
$this->tag = null;
|
||||
|
||||
if ($this->has($key)) {
|
||||
@@ -266,7 +265,6 @@ abstract class Driver
|
||||
}
|
||||
|
||||
$this->set($key, $value, 0);
|
||||
$this->tag = $prev;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-5
@@ -267,10 +267,6 @@ class Redis extends Driver
|
||||
protected function getTagItem($tag)
|
||||
{
|
||||
$tagName = $this->getTagKey($tag);
|
||||
$keys = $this->handler->sMembers($tagName);
|
||||
|
||||
return array_map(function ($key) {
|
||||
return $this->getCacheKey($key);
|
||||
}, $keys);
|
||||
return $this->handler->sMembers($tagName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1512,6 +1512,7 @@ class Query
|
||||
{
|
||||
if ($field instanceof $this) {
|
||||
$this->options['where'] = $field->getOptions('where');
|
||||
$this->bind($field->getBind(false));
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -2197,12 +2198,12 @@ class Query
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置需要追加输出的属性
|
||||
* 设置需要附加的输出属性
|
||||
* @access public
|
||||
* @param array $append 需要追加的属性
|
||||
* @param array $append 属性列表
|
||||
* @return $this
|
||||
*/
|
||||
public function append(array $append)
|
||||
public function append(array $append = [])
|
||||
{
|
||||
$this->options['append'] = $append;
|
||||
return $this;
|
||||
@@ -3355,13 +3356,13 @@ class Query
|
||||
|
||||
// 输出属性控制
|
||||
if (!empty($options['visible'])) {
|
||||
$result->visible($options['visible']);
|
||||
$result->visible($options['visible'], true);
|
||||
} elseif (!empty($options['hidden'])) {
|
||||
$result->hidden($options['hidden']);
|
||||
$result->hidden($options['hidden'], true);
|
||||
}
|
||||
|
||||
if (!empty($options['append'])) {
|
||||
$result->append($options['append']);
|
||||
$result->append($options['append'], true);
|
||||
}
|
||||
|
||||
// 关联查询
|
||||
|
||||
@@ -24,8 +24,10 @@ class Collection extends BaseCollection
|
||||
*/
|
||||
public function load($relation)
|
||||
{
|
||||
$item = current($this->items);
|
||||
$item->eagerlyResultSet($this->items, $relation);
|
||||
if (!$this->isEmpty()) {
|
||||
$item = current($this->items);
|
||||
$item->eagerlyResultSet($this->items, $relation);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,16 @@ abstract class Relation
|
||||
return $this->query->getModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的关联模型类的实例
|
||||
* @access public
|
||||
* @return Query
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前关联为自关联
|
||||
* @access public
|
||||
@@ -129,6 +139,17 @@ abstract class Relation
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @access public
|
||||
* @param array $data 更新数据
|
||||
* @return integer|string
|
||||
*/
|
||||
public function update(array $data = [])
|
||||
{
|
||||
return $this->query->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @access public
|
||||
|
||||
@@ -327,9 +327,13 @@ trait Attribute
|
||||
$method = 'set' . Loader::parseName($name, 1) . 'Attr';
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
$value = $this->$method($value, array_merge($this->data, $data));
|
||||
$origin = $this->data;
|
||||
$value = $this->$method($value, array_merge($this->data, $data));
|
||||
|
||||
$this->set[$name] = true;
|
||||
if (is_null($value) && $origin !== $this->data) {
|
||||
return;
|
||||
}
|
||||
} elseif (isset($this->type[$name])) {
|
||||
// 类型转换
|
||||
$value = $this->writeTransform($value, $this->type[$name]);
|
||||
|
||||
@@ -164,13 +164,15 @@ trait Conversion
|
||||
foreach ($data as $key => $val) {
|
||||
if ($val instanceof Model || $val instanceof ModelCollection) {
|
||||
// 关联模型对象
|
||||
if (isset($this->visible[$key])) {
|
||||
if (isset($this->visible[$key]) && is_array($this->visible[$key])) {
|
||||
$val->visible($this->visible[$key]);
|
||||
} elseif (isset($this->hidden[$key])) {
|
||||
} elseif (isset($this->hidden[$key]) && is_array($this->hidden[$key])) {
|
||||
$val->hidden($this->hidden[$key]);
|
||||
}
|
||||
// 关联模型对象
|
||||
$item[$key] = $val->toArray();
|
||||
if (!isset($this->hidden[$key]) || true !== $this->hidden[$key]) {
|
||||
$item[$key] = $val->toArray();
|
||||
}
|
||||
} elseif (isset($this->visible[$key])) {
|
||||
$item[$key] = $this->getAttr($key);
|
||||
} elseif (!isset($this->hidden[$key]) && !$hasVisible) {
|
||||
|
||||
@@ -204,7 +204,7 @@ trait RelationShip
|
||||
$relationResult = $this->$method();
|
||||
|
||||
if (isset($withRelationAttr[$relationName])) {
|
||||
$relationResult->withAttr($withRelationAttr[$relationName]);
|
||||
$relationResult->getQuery()->withAttr($withRelationAttr[$relationName]);
|
||||
}
|
||||
|
||||
$this->relation[$relation] = $relationResult->getRelation($subRelation, $closure);
|
||||
@@ -248,7 +248,7 @@ trait RelationShip
|
||||
$relationResult = $this->$relation();
|
||||
|
||||
if (isset($withRelationAttr[$relationName])) {
|
||||
$relationResult->withAttr($withRelationAttr[$relationName]);
|
||||
$relationResult->getQuery()->withAttr($withRelationAttr[$relationName]);
|
||||
}
|
||||
|
||||
$relationResult->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $join);
|
||||
@@ -290,7 +290,7 @@ trait RelationShip
|
||||
$relationResult = $this->$relation();
|
||||
|
||||
if (isset($withRelationAttr[$relationName])) {
|
||||
$relationResult->withAttr($withRelationAttr[$relationName]);
|
||||
$relationResult->getQuery()->withAttr($withRelationAttr[$relationName]);
|
||||
}
|
||||
|
||||
$relationResult->eagerlyResult($result, $relation, $subRelation, $closure, $join);
|
||||
|
||||
@@ -642,17 +642,26 @@ abstract class Rule
|
||||
protected function checkCrossDomain($request)
|
||||
{
|
||||
if (!empty($this->option['cross_domain'])) {
|
||||
|
||||
$header = [
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE',
|
||||
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE',
|
||||
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
|
||||
];
|
||||
|
||||
if (!empty($this->option['header'])) {
|
||||
$header = array_merge($header, $this->option['header']);
|
||||
}
|
||||
|
||||
if (!isset($header['Access-Control-Allow-Origin'])) {
|
||||
$httpOrigin = $request->header('origin');
|
||||
|
||||
if ($httpOrigin && strpos(config('cookie.domain'), $httpOrigin)) {
|
||||
$header['Access-Control-Allow-Origin'] = $httpOrigin;
|
||||
} else {
|
||||
$header['Access-Control-Allow-Origin'] = '*';
|
||||
}
|
||||
}
|
||||
|
||||
$this->option['header'] = $header;
|
||||
|
||||
if ($request->method(true) == 'OPTIONS') {
|
||||
|
||||
@@ -118,8 +118,8 @@ class RuleGroup extends Rule
|
||||
*/
|
||||
public function check($request, $url, $completeMatch = false)
|
||||
{
|
||||
// 跨域OPTIONS请求
|
||||
if ($dispatch = $this->checkCrossDomain($request)) {
|
||||
// 跨域OPTIONS请求
|
||||
return $dispatch;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,11 +149,6 @@ class RuleItem extends Rule
|
||||
*/
|
||||
public function checkRule($request, $url, $match = null, $completeMatch = false)
|
||||
{
|
||||
if ($dispatch = $this->checkCrossDomain($request)) {
|
||||
// 允许跨域
|
||||
return $dispatch;
|
||||
}
|
||||
|
||||
// 检查参数有效性
|
||||
if (!$this->checkOption($this->option, $request)) {
|
||||
return false;
|
||||
@@ -169,6 +164,15 @@ class RuleItem extends Rule
|
||||
}
|
||||
|
||||
if (false !== $match) {
|
||||
if (!empty($option['cross_domain'])) {
|
||||
if ($dispatch = $this->checkCrossDomain($request)) {
|
||||
// 允许跨域
|
||||
return $dispatch;
|
||||
}
|
||||
|
||||
$option['header'] = $this->option['header'];
|
||||
}
|
||||
|
||||
// 检查前置行为
|
||||
if (isset($option['before']) && false === $this->checkBefore($option['before'])) {
|
||||
return false;
|
||||
|
||||
Vendored
+49
-45
@@ -15,7 +15,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -64,7 +64,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -168,7 +168,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -241,7 +241,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -286,21 +286,21 @@
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "1.5.2",
|
||||
"version_normalized": "1.5.2.0",
|
||||
"version": "1.6.1",
|
||||
"version_normalized": "1.6.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "9f83dded91781a01c63574e387eaa769be769115"
|
||||
"reference": "239400de7a173fe9901b9ac7c06497751f00727a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115",
|
||||
"reference": "9f83dded91781a01c63574e387eaa769be769115",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a",
|
||||
"reference": "239400de7a173fe9901b9ac7c06497751f00727a",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -308,19 +308,23 @@
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"psr/http-message": "~1.0",
|
||||
"ralouphie/getallheaders": "^2.0.5"
|
||||
"ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-zlib": "*",
|
||||
"phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8"
|
||||
},
|
||||
"time": "2018-12-04T20:46:45+00:00",
|
||||
"suggest": {
|
||||
"zendframework/zend-httphandlerrunner": "Emit PSR-7 responses"
|
||||
},
|
||||
"time": "2019-07-01T23:21:34+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.5-dev"
|
||||
"dev-master": "1.6-dev"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
@@ -375,7 +379,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -449,7 +453,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -507,7 +511,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -547,21 +551,21 @@
|
||||
},
|
||||
{
|
||||
"name": "qiniu/php-sdk",
|
||||
"version": "v7.2.7",
|
||||
"version_normalized": "7.2.7.0",
|
||||
"version": "v7.2.9",
|
||||
"version_normalized": "7.2.9.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/qiniu/php-sdk.git",
|
||||
"reference": "88d11a5857ebc6871204e9be6ceec54bf5f381e6"
|
||||
"reference": "afe7d8715d8a688b1d8d8cdf031240d2363dad90"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/qiniu/php-sdk/zipball/88d11a5857ebc6871204e9be6ceec54bf5f381e6",
|
||||
"reference": "88d11a5857ebc6871204e9be6ceec54bf5f381e6",
|
||||
"url": "https://api.github.com/repos/qiniu/php-sdk/zipball/afe7d8715d8a688b1d8d8cdf031240d2363dad90",
|
||||
"reference": "afe7d8715d8a688b1d8d8cdf031240d2363dad90",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -573,7 +577,7 @@
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"squizlabs/php_codesniffer": "~2.3"
|
||||
},
|
||||
"time": "2018-11-06T13:34:32+00:00",
|
||||
"time": "2019-07-09T07:55:07+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
@@ -606,33 +610,33 @@
|
||||
},
|
||||
{
|
||||
"name": "ralouphie/getallheaders",
|
||||
"version": "2.0.5",
|
||||
"version_normalized": "2.0.5.0",
|
||||
"version": "3.0.3",
|
||||
"version_normalized": "3.0.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ralouphie/getallheaders.git",
|
||||
"reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa"
|
||||
"reference": "120b605dfeb996808c31b6477290a714d356e822"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa",
|
||||
"reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa",
|
||||
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
|
||||
"reference": "120b605dfeb996808c31b6477290a714d356e822",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~3.7.0",
|
||||
"satooshi/php-coveralls": ">=1.0"
|
||||
"php-coveralls/php-coveralls": "^2.1",
|
||||
"phpunit/phpunit": "^5 || ^6.5"
|
||||
},
|
||||
"time": "2016-02-11T07:05:27+00:00",
|
||||
"time": "2019-03-08T08:55:37+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
@@ -668,7 +672,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -722,21 +726,21 @@
|
||||
},
|
||||
{
|
||||
"name": "topthink/framework",
|
||||
"version": "v5.1.36",
|
||||
"version_normalized": "5.1.36.0",
|
||||
"version": "v5.1.37.1",
|
||||
"version_normalized": "5.1.37.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/top-think/framework.git",
|
||||
"reference": "135eee67ce9ee0b07da201f743d7dd88ec431abb"
|
||||
"reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/135eee67ce9ee0b07da201f743d7dd88ec431abb",
|
||||
"reference": "135eee67ce9ee0b07da201f743d7dd88ec431abb",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/05eecd121d18d6705aaa10aa44fcdf7c14da4d0b",
|
||||
"reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -754,7 +758,7 @@
|
||||
"sebastian/phpcpd": "2.*",
|
||||
"squizlabs/php_codesniffer": "2.*"
|
||||
},
|
||||
"time": "2019-04-28T08:56:58+00:00",
|
||||
"time": "2019-05-28T06:57:29+00:00",
|
||||
"type": "think-framework",
|
||||
"installation-source": "dist",
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
@@ -795,7 +799,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -842,7 +846,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -890,7 +894,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
@@ -939,7 +943,7 @@
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
|
||||
Vendored
-9
@@ -1,9 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
Vendored
+22
-1
@@ -10,6 +10,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
## [Unreleased]
|
||||
|
||||
|
||||
## [1.6.0]
|
||||
|
||||
### Added
|
||||
|
||||
- Allowed version `^3.0` of `ralouphie/getallheaders` dependency (#244)
|
||||
- Added MIME type for WEBP image format (#246)
|
||||
- Added more validation of values according to PSR-7 and RFC standards, e.g. status code range (#250, #272)
|
||||
|
||||
### Changed
|
||||
|
||||
- Tests don't pass with HHVM 4.0, so HHVM support got dropped. Other libraries like composer have done the same. (#262)
|
||||
- Accept port number 0 to be valid (#270)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed subsequent reads from `php://input` in ServerRequest (#247)
|
||||
- Fixed readable/writable detection for certain stream modes (#248)
|
||||
- Fixed encoding of special characters in the `userInfo` component of an URI (#253)
|
||||
|
||||
|
||||
## [1.5.2] - 2018-12-04
|
||||
|
||||
### Fixed
|
||||
@@ -209,7 +229,8 @@ Currently unsupported:
|
||||
|
||||
|
||||
|
||||
[Unreleased]: https://github.com/guzzle/psr7/compare/1.5.2...HEAD
|
||||
[Unreleased]: https://github.com/guzzle/psr7/compare/1.6.0...HEAD
|
||||
[1.6.0]: https://github.com/guzzle/psr7/compare/1.5.2...1.6.0
|
||||
[1.5.2]: https://github.com/guzzle/psr7/compare/1.5.1...1.5.2
|
||||
[1.5.1]: https://github.com/guzzle/psr7/compare/1.5.0...1.5.1
|
||||
[1.5.0]: https://github.com/guzzle/psr7/compare/1.4.2...1.5.0
|
||||
|
||||
Vendored
+7
-3
@@ -18,14 +18,18 @@
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"psr/http-message": "~1.0",
|
||||
"ralouphie/getallheaders": "^2.0.5"
|
||||
"ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8"
|
||||
"phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8",
|
||||
"ext-zlib": "*"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"suggest": {
|
||||
"zendframework/zend-httphandlerrunner": "Emit PSR-7 responses"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Psr7\\": "src/"
|
||||
@@ -39,7 +43,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.5-dev"
|
||||
"dev-master": "1.6-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ class LimitStream implements StreamInterface
|
||||
{
|
||||
if ($whence !== SEEK_SET || $offset < 0) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Cannot seek to offset % with whence %s',
|
||||
'Cannot seek to offset %s with whence %s',
|
||||
$offset,
|
||||
$whence
|
||||
));
|
||||
|
||||
+45
-15
@@ -66,11 +66,8 @@ trait MessageTrait
|
||||
|
||||
public function withHeader($header, $value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$this->assertHeader($header);
|
||||
$value = $this->normalizeHeaderValue($value);
|
||||
$normalized = strtolower($header);
|
||||
|
||||
$new = clone $this;
|
||||
@@ -85,11 +82,8 @@ trait MessageTrait
|
||||
|
||||
public function withAddedHeader($header, $value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$this->assertHeader($header);
|
||||
$value = $this->normalizeHeaderValue($value);
|
||||
$normalized = strtolower($header);
|
||||
|
||||
$new = clone $this;
|
||||
@@ -144,11 +138,13 @@ trait MessageTrait
|
||||
{
|
||||
$this->headerNames = $this->headers = [];
|
||||
foreach ($headers as $header => $value) {
|
||||
if (!is_array($value)) {
|
||||
$value = [$value];
|
||||
if (is_int($header)) {
|
||||
// Numeric array keys are converted to int by PHP but having a header name '123' is not forbidden by the spec
|
||||
// and also allowed in withHeader(). So we need to cast it to string again for the following assertion to pass.
|
||||
$header = (string) $header;
|
||||
}
|
||||
|
||||
$value = $this->trimHeaderValues($value);
|
||||
$this->assertHeader($header);
|
||||
$value = $this->normalizeHeaderValue($value);
|
||||
$normalized = strtolower($header);
|
||||
if (isset($this->headerNames[$normalized])) {
|
||||
$header = $this->headerNames[$normalized];
|
||||
@@ -160,6 +156,19 @@ trait MessageTrait
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeHeaderValue($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
return $this->trimHeaderValues([$value]);
|
||||
}
|
||||
|
||||
if (count($value) === 0) {
|
||||
throw new \InvalidArgumentException('Header value can not be an empty array.');
|
||||
}
|
||||
|
||||
return $this->trimHeaderValues($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims whitespace from the header values.
|
||||
*
|
||||
@@ -177,7 +186,28 @@ trait MessageTrait
|
||||
private function trimHeaderValues(array $values)
|
||||
{
|
||||
return array_map(function ($value) {
|
||||
return trim($value, " \t");
|
||||
if (!is_scalar($value) && null !== $value) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Header value must be scalar or null but %s provided.',
|
||||
is_object($value) ? get_class($value) : gettype($value)
|
||||
));
|
||||
}
|
||||
|
||||
return trim((string) $value, " \t");
|
||||
}, $values);
|
||||
}
|
||||
|
||||
private function assertHeader($header)
|
||||
{
|
||||
if (!is_string($header)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Header name must be a string but %s provided.',
|
||||
is_object($header) ? get_class($header) : gettype($header)
|
||||
));
|
||||
}
|
||||
|
||||
if ($header === '') {
|
||||
throw new \InvalidArgumentException('Header name can not be empty.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -36,6 +36,7 @@ class Request implements RequestInterface
|
||||
$body = null,
|
||||
$version = '1.1'
|
||||
) {
|
||||
$this->assertMethod($method);
|
||||
if (!($uri instanceof UriInterface)) {
|
||||
$uri = new Uri($uri);
|
||||
}
|
||||
@@ -91,6 +92,7 @@ class Request implements RequestInterface
|
||||
|
||||
public function withMethod($method)
|
||||
{
|
||||
$this->assertMethod($method);
|
||||
$new = clone $this;
|
||||
$new->method = strtoupper($method);
|
||||
return $new;
|
||||
@@ -139,4 +141,11 @@ class Request implements RequestInterface
|
||||
// See: http://tools.ietf.org/html/rfc7230#section-5.4
|
||||
$this->headers = [$header => [$host]] + $this->headers;
|
||||
}
|
||||
|
||||
private function assertMethod($method)
|
||||
{
|
||||
if (!is_string($method) || $method === '') {
|
||||
throw new \InvalidArgumentException('Method must be a non-empty string.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-5
@@ -93,11 +93,11 @@ class Response implements ResponseInterface
|
||||
$version = '1.1',
|
||||
$reason = null
|
||||
) {
|
||||
if (filter_var($status, FILTER_VALIDATE_INT) === false) {
|
||||
throw new \InvalidArgumentException('Status code must be an integer value.');
|
||||
}
|
||||
$this->assertStatusCodeIsInteger($status);
|
||||
$status = (int) $status;
|
||||
$this->assertStatusCodeRange($status);
|
||||
|
||||
$this->statusCode = (int) $status;
|
||||
$this->statusCode = $status;
|
||||
|
||||
if ($body !== '' && $body !== null) {
|
||||
$this->stream = stream_for($body);
|
||||
@@ -125,12 +125,30 @@ class Response implements ResponseInterface
|
||||
|
||||
public function withStatus($code, $reasonPhrase = '')
|
||||
{
|
||||
$this->assertStatusCodeIsInteger($code);
|
||||
$code = (int) $code;
|
||||
$this->assertStatusCodeRange($code);
|
||||
|
||||
$new = clone $this;
|
||||
$new->statusCode = (int) $code;
|
||||
$new->statusCode = $code;
|
||||
if ($reasonPhrase == '' && isset(self::$phrases[$new->statusCode])) {
|
||||
$reasonPhrase = self::$phrases[$new->statusCode];
|
||||
}
|
||||
$new->reasonPhrase = $reasonPhrase;
|
||||
return $new;
|
||||
}
|
||||
|
||||
private function assertStatusCodeIsInteger($statusCode)
|
||||
{
|
||||
if (filter_var($statusCode, FILTER_VALIDATE_INT) === false) {
|
||||
throw new \InvalidArgumentException('Status code must be an integer value.');
|
||||
}
|
||||
}
|
||||
|
||||
private function assertStatusCodeRange($statusCode)
|
||||
{
|
||||
if ($statusCode < 100 || $statusCode >= 600) {
|
||||
throw new \InvalidArgumentException('Status code must be an integer value between 1xx and 5xx.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -168,7 +168,7 @@ class ServerRequest extends Request implements ServerRequestInterface
|
||||
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
|
||||
$headers = getallheaders();
|
||||
$uri = self::getUriFromGlobals();
|
||||
$body = new LazyOpenStream('php://input', 'r+');
|
||||
$body = new CachingStream(new LazyOpenStream('php://input', 'r+'));
|
||||
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1';
|
||||
|
||||
$serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER);
|
||||
|
||||
+15
-18
@@ -10,6 +10,17 @@ use Psr\Http\Message\StreamInterface;
|
||||
*/
|
||||
class Stream implements StreamInterface
|
||||
{
|
||||
/**
|
||||
* Resource modes.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @see http://php.net/manual/function.fopen.php
|
||||
* @see http://php.net/manual/en/function.gzopen.php
|
||||
*/
|
||||
const READABLE_MODES = '/r|a\+|ab\+|w\+|wb\+|x\+|xb\+|c\+|cb\+/';
|
||||
const WRITABLE_MODES = '/a|w|r\+|rb\+|rw|x|c/';
|
||||
|
||||
private $stream;
|
||||
private $size;
|
||||
private $seekable;
|
||||
@@ -18,22 +29,6 @@ class Stream implements StreamInterface
|
||||
private $uri;
|
||||
private $customMetadata;
|
||||
|
||||
/** @var array Hash of readable and writable stream types */
|
||||
private static $readWriteHash = [
|
||||
'read' => [
|
||||
'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
|
||||
'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true,
|
||||
'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true,
|
||||
'x+t' => true, 'c+t' => true, 'a+' => true, 'rb+' => true,
|
||||
],
|
||||
'write' => [
|
||||
'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true,
|
||||
'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, 'rb+' => true,
|
||||
'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true,
|
||||
'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* This constructor accepts an associative array of options.
|
||||
*
|
||||
@@ -65,8 +60,8 @@ class Stream implements StreamInterface
|
||||
$this->stream = $stream;
|
||||
$meta = stream_get_meta_data($this->stream);
|
||||
$this->seekable = $meta['seekable'];
|
||||
$this->readable = isset(self::$readWriteHash['read'][$meta['mode']]);
|
||||
$this->writable = isset(self::$readWriteHash['write'][$meta['mode']]);
|
||||
$this->readable = (bool)preg_match(self::READABLE_MODES, $meta['mode']);
|
||||
$this->writable = (bool)preg_match(self::WRITABLE_MODES, $meta['mode']);
|
||||
$this->uri = $this->getMetadata('uri');
|
||||
}
|
||||
|
||||
@@ -197,6 +192,8 @@ class Stream implements StreamInterface
|
||||
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
$whence = (int) $whence;
|
||||
|
||||
if (!isset($this->stream)) {
|
||||
throw new \RuntimeException('Stream is detached');
|
||||
}
|
||||
|
||||
Vendored
+29
-7
@@ -437,9 +437,9 @@ class Uri implements UriInterface
|
||||
|
||||
public function withUserInfo($user, $password = null)
|
||||
{
|
||||
$info = $user;
|
||||
if ($password != '') {
|
||||
$info .= ':' . $password;
|
||||
$info = $this->filterUserInfoComponent($user);
|
||||
if ($password !== null) {
|
||||
$info .= ':' . $this->filterUserInfoComponent($password);
|
||||
}
|
||||
|
||||
if ($this->userInfo === $info) {
|
||||
@@ -537,7 +537,9 @@ class Uri implements UriInterface
|
||||
$this->scheme = isset($parts['scheme'])
|
||||
? $this->filterScheme($parts['scheme'])
|
||||
: '';
|
||||
$this->userInfo = isset($parts['user']) ? $parts['user'] : '';
|
||||
$this->userInfo = isset($parts['user'])
|
||||
? $this->filterUserInfoComponent($parts['user'])
|
||||
: '';
|
||||
$this->host = isset($parts['host'])
|
||||
? $this->filterHost($parts['host'])
|
||||
: '';
|
||||
@@ -554,7 +556,7 @@ class Uri implements UriInterface
|
||||
? $this->filterQueryAndFragment($parts['fragment'])
|
||||
: '';
|
||||
if (isset($parts['pass'])) {
|
||||
$this->userInfo .= ':' . $parts['pass'];
|
||||
$this->userInfo .= ':' . $this->filterUserInfoComponent($parts['pass']);
|
||||
}
|
||||
|
||||
$this->removeDefaultPort();
|
||||
@@ -576,6 +578,26 @@ class Uri implements UriInterface
|
||||
return strtolower($scheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $component
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException If the user info is invalid.
|
||||
*/
|
||||
private function filterUserInfoComponent($component)
|
||||
{
|
||||
if (!is_string($component)) {
|
||||
throw new \InvalidArgumentException('User info must be a string');
|
||||
}
|
||||
|
||||
return preg_replace_callback(
|
||||
'/(?:[^%' . self::$charUnreserved . self::$charSubDelims . ']+|%(?![A-Fa-f0-9]{2}))/',
|
||||
[$this, 'rawurlencodeMatchZero'],
|
||||
$component
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $host
|
||||
*
|
||||
@@ -606,9 +628,9 @@ class Uri implements UriInterface
|
||||
}
|
||||
|
||||
$port = (int) $port;
|
||||
if (1 > $port || 0xffff < $port) {
|
||||
if (0 > $port || 0xffff < $port) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('Invalid port: %d. Must be between 1 and 65535', $port)
|
||||
sprintf('Invalid port: %d. Must be between 0 and 65535', $port)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -724,6 +724,7 @@ function mimetype_from_extension($extension)
|
||||
'txt' => 'text/plain',
|
||||
'wav' => 'audio/x-wav',
|
||||
'webm' => 'video/webm',
|
||||
'webp' => 'image/webp',
|
||||
'wma' => 'audio/x-ms-wma',
|
||||
'wmv' => 'video/x-ms-wmv',
|
||||
'woff' => 'application/x-font-woff',
|
||||
|
||||
Vendored
+5
@@ -21,3 +21,8 @@ script:
|
||||
after_script:
|
||||
- wget https://scrutinizer-ci.com/ocular.phar
|
||||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
|
||||
|
||||
env:
|
||||
global:
|
||||
- secure: "V9BsntXQZwvO9EOD6itzaae2uq+GemzyTUTxMTJx1/jFoUNpCU2O2UAgjA2XSEr5sgci0KWDV4Krbzv3EBB4uplOFLMI3w32256UHbT9E0x3YjhfPJZk68MH1iS1be7X81LDHON7yveavK8987s3qzjeUcbfLSPgccT+cvf7+dc="
|
||||
- QINIU_ACCESS_KEY=vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5
|
||||
+1
-7
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
|
||||
@@ -8,14 +7,12 @@ use Qiniu\Storage\UploadManager;
|
||||
// use Qiniu\Zone;
|
||||
|
||||
// 指定zone上传
|
||||
// $zone = Zone::zoneZ0(); //华东QVM内网上传指定host
|
||||
// $zone = Zone::qvmZonez0(); //华东QVM内网上传指定host
|
||||
// $config = new Config($zone);
|
||||
|
||||
$accessKey = getenv('QINIU_ACCESS_KEY');
|
||||
$secretKey = getenv('QINIU_SECRET_KEY');
|
||||
$bucket = getenv('QINIU_TEST_BUCKET');
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
|
||||
// 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器.
|
||||
// 可参考文档: http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html
|
||||
$policy = array(
|
||||
@@ -23,14 +20,11 @@ $policy = array(
|
||||
'callbackBody' => 'filename=$(fname)&filesize=$(fsize)'
|
||||
);
|
||||
$uptoken = $auth->uploadToken($bucket, null, 3600, $policy);
|
||||
|
||||
//上传文件的本地路径
|
||||
$filePath = './php-logo.png';
|
||||
|
||||
//指定 config
|
||||
// $uploadMgr = new UploadManager($config);
|
||||
$uploadMgr = new UploadManager();
|
||||
|
||||
list($ret, $err) = $uploadMgr->putFile($uptoken, null, $filePath);
|
||||
echo "\n====> putFile result: \n";
|
||||
if ($err !== null) {
|
||||
|
||||
-1
@@ -8,7 +8,6 @@
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Qiniu SDK Tests">
|
||||
|
||||
+5
-4
@@ -169,21 +169,22 @@ final class CdnManager
|
||||
*/
|
||||
public static function createTimestampAntiLeechUrl($rawUrl, $encryptKey, $durationInSeconds)
|
||||
{
|
||||
|
||||
$parsedUrl = parse_url($rawUrl);
|
||||
|
||||
$deadline = time() + $durationInSeconds;
|
||||
$expireHex = dechex($deadline);
|
||||
|
||||
$path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
|
||||
$path = implode('/', array_map('rawurlencode', explode('/', $path)));
|
||||
|
||||
$strToSign = $encryptKey . $path . $expireHex;
|
||||
$signStr = md5($strToSign);
|
||||
|
||||
$url = $parsedUrl['scheme'].'://'.$parsedUrl['host'].$path;
|
||||
|
||||
if (isset($parsedUrl['query'])) {
|
||||
$signedUrl = $rawUrl . '&sign=' . $signStr . '&t=' . $expireHex;
|
||||
$signedUrl = $url . '&sign=' . $signStr . '&t=' . $expireHex;
|
||||
} else {
|
||||
$signedUrl = $rawUrl . '?sign=' . $signStr . '&t=' . $expireHex;
|
||||
$signedUrl = $url . '?sign=' . $signStr . '&t=' . $expireHex;
|
||||
}
|
||||
|
||||
return $signedUrl;
|
||||
|
||||
+32
-29
@@ -3,48 +3,51 @@ namespace Qiniu;
|
||||
|
||||
final class Config
|
||||
{
|
||||
const SDK_VER = '7.2.7';
|
||||
const SDK_VER = '7.2.9';
|
||||
|
||||
const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改
|
||||
|
||||
const RSF_HOST = 'rsf.qiniu.com';
|
||||
const API_HOST = 'api.qiniu.com';
|
||||
const RS_HOST = 'rs.qiniu.com'; //RS Host
|
||||
const UC_HOST = 'https://api.qiniu.com'; //UC Host
|
||||
const UC_HOST = 'uc.qbox.me'; //UC Host
|
||||
const RTCAPI_HOST = 'http://rtc.qiniuapi.com';
|
||||
const ARGUS_HOST = 'argus.atlab.ai';
|
||||
const CASTER_HOST = 'pili-caster.qiniuapi.com';
|
||||
const SMS_HOST="https://sms.qiniuapi.com";
|
||||
const RTCAPI_VERSION = 'v3';
|
||||
const SMS_VERSION='v1';
|
||||
|
||||
// Zone 空间对应的机房
|
||||
public $zone;
|
||||
// Zone 空间对应的存储区域
|
||||
public $region;
|
||||
//BOOL 是否使用https域名
|
||||
public $useHTTPS;
|
||||
//BOOL 是否使用CDN加速上传域名
|
||||
public $useCdnDomains;
|
||||
// Zone Cache
|
||||
private $zoneCache;
|
||||
private $regionCache;
|
||||
|
||||
// 构造函数
|
||||
public function __construct(Zone $z = null)
|
||||
public function __construct(Region $z = null)
|
||||
{
|
||||
$this->zone = $z;
|
||||
$this->useHTTPS = false;
|
||||
$this->useCdnDomains = false;
|
||||
$this->zoneCache = array();
|
||||
$this->regionCache = array();
|
||||
}
|
||||
|
||||
public function getUpHost($accessKey, $bucket)
|
||||
{
|
||||
$zone = $this->getZone($accessKey, $bucket);
|
||||
$region = $this->getRegion($accessKey, $bucket);
|
||||
if ($this->useHTTPS === true) {
|
||||
$scheme = "https://";
|
||||
} else {
|
||||
$scheme = "http://";
|
||||
}
|
||||
|
||||
$host = $zone->srcUpHosts[0];
|
||||
$host = $region->srcUpHosts[0];
|
||||
if ($this->useCdnDomains === true) {
|
||||
$host = $zone->cdnUpHosts[0];
|
||||
$host = $region->cdnUpHosts[0];
|
||||
}
|
||||
|
||||
return $scheme . $host;
|
||||
@@ -52,16 +55,16 @@ final class Config
|
||||
|
||||
public function getUpBackupHost($accessKey, $bucket)
|
||||
{
|
||||
$zone = $this->getZone($accessKey, $bucket);
|
||||
$region = $this->getRegion($accessKey, $bucket);
|
||||
if ($this->useHTTPS === true) {
|
||||
$scheme = "https://";
|
||||
} else {
|
||||
$scheme = "http://";
|
||||
}
|
||||
|
||||
$host = $zone->cdnUpHosts[0];
|
||||
$host = $region->cdnUpHosts[0];
|
||||
if ($this->useCdnDomains === true) {
|
||||
$host = $zone->srcUpHosts[0];
|
||||
$host = $region->srcUpHosts[0];
|
||||
}
|
||||
|
||||
return $scheme . $host;
|
||||
@@ -69,7 +72,7 @@ final class Config
|
||||
|
||||
public function getRsHost($accessKey, $bucket)
|
||||
{
|
||||
$zone = $this->getZone($accessKey, $bucket);
|
||||
$region = $this->getRegion($accessKey, $bucket);
|
||||
|
||||
if ($this->useHTTPS === true) {
|
||||
$scheme = "https://";
|
||||
@@ -77,12 +80,12 @@ final class Config
|
||||
$scheme = "http://";
|
||||
}
|
||||
|
||||
return $scheme . $zone->rsHost;
|
||||
return $scheme . $region->rsHost;
|
||||
}
|
||||
|
||||
public function getRsfHost($accessKey, $bucket)
|
||||
{
|
||||
$zone = $this->getZone($accessKey, $bucket);
|
||||
$region = $this->getRegion($accessKey, $bucket);
|
||||
|
||||
if ($this->useHTTPS === true) {
|
||||
$scheme = "https://";
|
||||
@@ -90,12 +93,12 @@ final class Config
|
||||
$scheme = "http://";
|
||||
}
|
||||
|
||||
return $scheme . $zone->rsfHost;
|
||||
return $scheme . $region->rsfHost;
|
||||
}
|
||||
|
||||
public function getIovipHost($accessKey, $bucket)
|
||||
{
|
||||
$zone = $this->getZone($accessKey, $bucket);
|
||||
$region = $this->getRegion($accessKey, $bucket);
|
||||
|
||||
if ($this->useHTTPS === true) {
|
||||
$scheme = "https://";
|
||||
@@ -103,12 +106,12 @@ final class Config
|
||||
$scheme = "http://";
|
||||
}
|
||||
|
||||
return $scheme . $zone->iovipHost;
|
||||
return $scheme . $region->iovipHost;
|
||||
}
|
||||
|
||||
public function getApiHost($accessKey, $bucket)
|
||||
{
|
||||
$zone = $this->getZone($accessKey, $bucket);
|
||||
$region = $this->getRegion($accessKey, $bucket);
|
||||
|
||||
if ($this->useHTTPS === true) {
|
||||
$scheme = "https://";
|
||||
@@ -116,22 +119,22 @@ final class Config
|
||||
$scheme = "http://";
|
||||
}
|
||||
|
||||
return $scheme . $zone->apiHost;
|
||||
return $scheme . $region->apiHost;
|
||||
}
|
||||
|
||||
private function getZone($accessKey, $bucket)
|
||||
private function getRegion($accessKey, $bucket)
|
||||
{
|
||||
$cacheId = "$accessKey:$bucket";
|
||||
|
||||
if (isset($this->zoneCache[$cacheId])) {
|
||||
$zone = $this->zoneCache[$cacheId];
|
||||
if (isset($this->regionCache[$cacheId])) {
|
||||
$region = $this->regionCache[$cacheId];
|
||||
} elseif (isset($this->zone)) {
|
||||
$zone = $this->zone;
|
||||
$this->zoneCache[$cacheId] = $zone;
|
||||
$region = $this->zone;
|
||||
$this->regionCache[$cacheId] = $region;
|
||||
} else {
|
||||
$zone = Zone::queryZone($accessKey, $bucket);
|
||||
$this->zoneCache[$cacheId] = $zone;
|
||||
$region = Zone::queryZone($accessKey, $bucket);
|
||||
$this->regionCache[$cacheId] = $region;
|
||||
}
|
||||
return $zone;
|
||||
return $region;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -25,6 +25,12 @@ final class Client
|
||||
return self::sendRequest($request);
|
||||
}
|
||||
|
||||
public static function PUT($url, $body, array $headers = array())
|
||||
{
|
||||
$request = new Request('PUT', $url, $headers, $body);
|
||||
return self::sendRequest($request);
|
||||
}
|
||||
|
||||
public static function multipartPost(
|
||||
$url,
|
||||
$fields,
|
||||
@@ -56,6 +62,7 @@ final class Client
|
||||
array_push($data, '');
|
||||
|
||||
$body = implode("\r\n", $data);
|
||||
// var_dump($data);exit;
|
||||
$contentType = 'multipart/form-data; boundary=' . $mimeBoundary;
|
||||
$headers['Content-Type'] = $contentType;
|
||||
$request = new Request('POST', $url, $headers, $body);
|
||||
@@ -91,12 +98,10 @@ final class Client
|
||||
CURLOPT_CUSTOMREQUEST => $request->method,
|
||||
CURLOPT_URL => $request->url,
|
||||
);
|
||||
|
||||
// Handle open_basedir & safe mode
|
||||
if (!ini_get('safe_mode') && !ini_get('open_basedir')) {
|
||||
$options[CURLOPT_FOLLOWLOCATION] = true;
|
||||
}
|
||||
|
||||
if (!empty($request->headers)) {
|
||||
$headers = array();
|
||||
foreach ($request->headers as $key => $val) {
|
||||
@@ -105,7 +110,6 @@ final class Client
|
||||
$options[CURLOPT_HTTPHEADER] = $headers;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
|
||||
|
||||
if (!empty($request->body)) {
|
||||
$options[CURLOPT_POSTFIELDS] = $request->body;
|
||||
}
|
||||
|
||||
+8
-3
@@ -19,6 +19,7 @@ class AppClient
|
||||
}
|
||||
|
||||
/*
|
||||
* 创建应用
|
||||
* hub: 直播空间名
|
||||
* title: app 的名称 注意,Title 不是唯一标识,重复 create 动作将生成多个 app
|
||||
* maxUsers:人数限制
|
||||
@@ -41,6 +42,7 @@ class AppClient
|
||||
}
|
||||
|
||||
/*
|
||||
* 更新应用
|
||||
* appId: app 的唯一标识,创建的时候由系统生成。
|
||||
* Title: app 的名称, 可选。
|
||||
* Hub: 绑定的直播 hub,可选,用于合流后 rtmp 推流。
|
||||
@@ -75,6 +77,7 @@ class AppClient
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取应用信息
|
||||
* appId: app 的唯一标识,创建的时候由系统生成。
|
||||
*/
|
||||
public function getApp($appId)
|
||||
@@ -85,6 +88,7 @@ class AppClient
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除应用
|
||||
* appId: app 的唯一标识,创建的时候由系统生成
|
||||
*/
|
||||
public function deleteApp($appId)
|
||||
@@ -95,7 +99,7 @@ class AppClient
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取房间的人数
|
||||
* 获取房间内用户列表
|
||||
* appId: app 的唯一标识,创建的时候由系统生成。
|
||||
* roomName: 操作所查询的连麦房间。
|
||||
*/
|
||||
@@ -107,7 +111,7 @@ class AppClient
|
||||
}
|
||||
|
||||
/*
|
||||
* 踢出玩家
|
||||
* 踢出用户
|
||||
* appId: app 的唯一标识,创建的时候由系统生成。
|
||||
* roomName: 连麦房间
|
||||
* userId: 请求加入房间的用户ID
|
||||
@@ -120,7 +124,7 @@ class AppClient
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取房间的人数
|
||||
* 获取应用中活跃房间
|
||||
* appId: app 的唯一标识,创建的时候由系统生成。
|
||||
* prefix: 所查询房间名的前缀索引,可以为空。
|
||||
* offset: int 类型,分页查询的位移标记。
|
||||
@@ -149,6 +153,7 @@ class AppClient
|
||||
}
|
||||
|
||||
/*
|
||||
* 生成加入房间的令牌
|
||||
* appId: app 的唯一标识,创建的时候由系统生成。
|
||||
* roomName: 房间名称,需满足规格 ^[a-zA-Z0-9_-]{3,64}$
|
||||
* userId: 请求加入房间的用户 ID,需满足规格 ^[a-zA-Z0-9_-]{3,50}$
|
||||
|
||||
+634
-19
@@ -41,6 +41,56 @@ final class BucketManager
|
||||
return $this->rsGet('/buckets?shared=' . $includeShared);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列举空间,返回bucket列表
|
||||
* region 指定区域,global 指定全局空间。
|
||||
* 在指定了 region 参数时,
|
||||
* 如果指定 global 为 true,那么忽略 region 参数指定的区域,返回所有区域的全局空间。
|
||||
* 如果没有指定 global 为 true,那么返回指定区域中非全局空间。
|
||||
* 在没有指定 region 参数时(包括指定为空""),
|
||||
* 如果指定 global 为 true,那么返回所有区域的全局空间。
|
||||
* 如果没有指定 global 为 true,那么返回指定区域中所有的空间,包括全局空间。
|
||||
* 在指定了line为 true 时,只返回 Line 空间;否则,只返回非 Line 空间。
|
||||
* share 参数用于指定共享空间。
|
||||
*/
|
||||
|
||||
public function listbuckets(
|
||||
$region = null,
|
||||
$line = 'false',
|
||||
$shared = 'false'
|
||||
) {
|
||||
$path = '/v3/buckets?region=' . $region . '&line=' . $line . '&shared=' . $share;
|
||||
$info = $this->ucPost($path);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建空间
|
||||
*
|
||||
* @param $name 创建的空间名
|
||||
* @param $region 创建的区域,默认华东
|
||||
*
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function createBucket($name, $region = 'z0')
|
||||
{
|
||||
$path = '/mkbucketv2/'.$name.'/region/' . $region;
|
||||
return $this->rsPost($path, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除空间
|
||||
*
|
||||
* @param $name 删除的空间名
|
||||
*
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function deleteBucket($name)
|
||||
{
|
||||
$path = '/drop/'.$name;
|
||||
return $this->rsPost($path, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定空间绑定的所有的域名
|
||||
*
|
||||
@@ -51,6 +101,34 @@ final class BucketManager
|
||||
return $this->apiGet('/v6/domain/list?tbl=' . $bucket);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定空间的相关信息
|
||||
*
|
||||
* @return string[] 包含空间信息
|
||||
*/
|
||||
public function bucketInfo($bucket)
|
||||
{
|
||||
$path = '/v2/bucketInfo?bucket=' . $bucket;
|
||||
$info = $this->ucPost($path);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定zone的空间信息列表
|
||||
* 在Region 未指定且Global 不为 true 时(包含未指定的情况,下同),返回用户的所有空间。
|
||||
* 在指定了 region 参数且 global 不为 true 时,只列举非全局空间。
|
||||
* shared 不指定shared参数或指定shared为rw或false时,返回包含具有读写权限空间,
|
||||
* 指定shared为rd或true时,返回包含具有读权限空间。
|
||||
* fs:如果为 true,会返回每个空间当前的文件数和存储量(实时数据)。
|
||||
* @return string[] 包含空间信息
|
||||
*/
|
||||
public function bucketInfos($region = null, $shared = 'false', $fs = 'false')
|
||||
{
|
||||
$path = '/v2/bucketInfos?region=' . $region . '&shared=' . $shared . '&fs=' . $fs;
|
||||
$info = $this->ucPost($path);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取空间绑定的域名列表
|
||||
* @return string[] 包含空间绑定的所有域名
|
||||
@@ -66,18 +144,23 @@ final class BucketManager
|
||||
* @param $delimiter 指定目录分隔符
|
||||
*
|
||||
* @return array 包含文件信息的数组,类似:[
|
||||
* {
|
||||
* "hash" => "<Hash string>",
|
||||
* "key" => "<Key string>",
|
||||
* "fsize" => "<file size>",
|
||||
* "putTime" => "<file modify time>"
|
||||
* },
|
||||
* ...
|
||||
* ]
|
||||
* {
|
||||
* "hash" => "<Hash string>",
|
||||
* "key" => "<Key string>",
|
||||
* "fsize" => "<file size>",
|
||||
* "putTime" => "<file modify time>"
|
||||
* },
|
||||
* ...
|
||||
* ]
|
||||
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html
|
||||
*/
|
||||
public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000, $delimiter = null)
|
||||
{
|
||||
public function listFiles(
|
||||
$bucket,
|
||||
$prefix = null,
|
||||
$marker = null,
|
||||
$limit = 1000,
|
||||
$delimiter = null
|
||||
) {
|
||||
$query = array('bucket' => $bucket);
|
||||
\Qiniu\setWithoutEmpty($query, 'prefix', $prefix);
|
||||
\Qiniu\setWithoutEmpty($query, 'marker', $marker);
|
||||
@@ -87,6 +170,493 @@ final class BucketManager
|
||||
return $this->get($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列取空间的文件列表
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @param $prefix 列举前缀
|
||||
* @param $marker 列举标识符
|
||||
* @param $limit 单次列举个数限制
|
||||
* @param $delimiter 指定目录分隔符
|
||||
* @param $skipconfirm 是否跳过已删除条目的确认机制
|
||||
*
|
||||
* @return array 包含文件信息的数组,类似:[
|
||||
* {
|
||||
* "hash" => "<Hash string>",
|
||||
* "key" => "<Key string>",
|
||||
* "fsize" => "<file size>",
|
||||
* "putTime" => "<file modify time>"
|
||||
* },
|
||||
* ...
|
||||
* ]
|
||||
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html
|
||||
*/
|
||||
public function listFilesv2(
|
||||
$bucket,
|
||||
$prefix = null,
|
||||
$marker = null,
|
||||
$limit = 1000,
|
||||
$delimiter = null,
|
||||
$skipconfirm = true
|
||||
) {
|
||||
$query = array('bucket' => $bucket);
|
||||
\Qiniu\setWithoutEmpty($query, 'prefix', $prefix);
|
||||
\Qiniu\setWithoutEmpty($query, 'marker', $marker);
|
||||
\Qiniu\setWithoutEmpty($query, 'limit', $limit);
|
||||
\Qiniu\setWithoutEmpty($query, 'delimiter', $delimiter);
|
||||
\Qiniu\setWithoutEmpty($query, 'skipconfirm', $skipconfirm);
|
||||
$path = '/v2/list?' . http_build_query($query);
|
||||
$url = $this->getRsfHost() . $path;
|
||||
$headers = $this->auth->authorization($url, null, 'application/x-www-form-urlencoded');
|
||||
$ret = Client::post($url, null, $headers);
|
||||
if (!$ret->ok()) {
|
||||
return array(null, new Error($url, $ret));
|
||||
}
|
||||
$r = explode("\n", $ret->body);
|
||||
$pop = array_pop($r);
|
||||
return array($r, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Referer防盗链
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @param $mode 0: 表示关闭Referer(使用此选项将会忽略以下参数并将恢复默认值);
|
||||
* 1: 表示设置Referer白名单; 2:表示设置Referer黑名单
|
||||
* @param $norefer 0: 表示不允许空 Refer 访问; 1: 表示允许空 Refer 访问
|
||||
* @param $pattern 规则字符串, 当前允许格式分为三种: 一种为空主机头域名,
|
||||
* 比如 foo.com; 一种是泛域名,比如 *.bar.com; 一种是完全通配符,
|
||||
* 即一个 *; 多个规则之间用;隔开, 比如: foo.com;*.bar.com;sub.foo.com;*.sub.bar.com
|
||||
* @param $source_enabled 源站是否支持,默认为0只给CDN配置, 设置为1表示开启源站防盗链
|
||||
*
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
// public function referAntiLeech(){
|
||||
|
||||
// }
|
||||
|
||||
/**
|
||||
* 增加bucket生命规则
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为
|
||||
* 字母、数字、下划线
|
||||
* @param $prefix 同一个 bucket 里面前缀不能重复
|
||||
* @param $delete_after_days 指定上传文件多少天后删除,指定为0表示不删除,
|
||||
* 大于0表示多少天后删除,需大于 to_line_after_days
|
||||
* @param $to_line_after_days 指定文件上传多少天后转低频存储。指定为0表示
|
||||
* 不转低频存储,小于0表示上传的文件立即变低频存储
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function bucketLifecycleRule(
|
||||
$bucket,
|
||||
$name,
|
||||
$prefix,
|
||||
$delete_after_days,
|
||||
$to_line_after_days
|
||||
) {
|
||||
$path = '/rules/add';
|
||||
if ($bucket) {
|
||||
$params['bucket'] = $bucket;
|
||||
}
|
||||
if ($name) {
|
||||
$params['name'] = $name;
|
||||
}
|
||||
if ($prefix) {
|
||||
$params['prefix'] = $prefix;
|
||||
}
|
||||
if ($delete_after_days) {
|
||||
$params['delete_after_days'] = $delete_after_days;
|
||||
}
|
||||
if ($to_line_after_days) {
|
||||
$params['to_line_after_days'] = $to_line_after_days;
|
||||
}
|
||||
$data = http_build_query($params);
|
||||
$info = $this->ucPost($path, $data);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新bucket生命规则
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、
|
||||
* 数字、下划线
|
||||
* @param $prefix 同一个 bucket 里面前缀不能重复
|
||||
* @param $delete_after_days 指定上传文件多少天后删除,指定为0表示不删除,
|
||||
* 大于0表示多少天后删除,需大于 to_line_after_days
|
||||
* @param $to_line_after_days 指定文件上传多少天后转低频存储。指定为0表示不
|
||||
* 转低频存储,小于0表示上传的文件立即变低频存储
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function updateBucketLifecycleRule(
|
||||
$bucket,
|
||||
$name,
|
||||
$prefix,
|
||||
$delete_after_days,
|
||||
$to_line_after_days
|
||||
) {
|
||||
$path = '/rules/update';
|
||||
if ($bucket) {
|
||||
$params['bucket'] = $bucket;
|
||||
}
|
||||
if ($name) {
|
||||
$params['name'] = $name;
|
||||
}
|
||||
if ($prefix) {
|
||||
$params['prefix'] = $prefix;
|
||||
}
|
||||
if ($delete_after_days) {
|
||||
$params['delete_after_days'] = $delete_after_days;
|
||||
}
|
||||
if ($to_line_after_days) {
|
||||
$params['to_line_after_days'] = $to_line_after_days;
|
||||
}
|
||||
$data = http_build_query($params);
|
||||
$info = $this->ucPost($path, $data);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bucket生命规则
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function getBucketLifecycleRules($bucket)
|
||||
{
|
||||
$path = '/rules/get?bucket=' . $bucket;
|
||||
$info = $this->ucGet($path);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除bucket生命规则
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,
|
||||
* 只能为字母、数字、下划线()
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function deleteBucketLifecycleRule($bucket, $name)
|
||||
{
|
||||
$path = '/rules/delete';
|
||||
if ($bucket) {
|
||||
$params['bucket'] = $bucket;
|
||||
}
|
||||
if ($name) {
|
||||
$params['name'] = $name;
|
||||
}
|
||||
$data = http_build_query($params);
|
||||
$info = $this->ucPost($path, $data);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加bucket事件通知规则
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,
|
||||
* 只能为字母、数字、下划线()
|
||||
* @param $prefix 同一个 bucket 里面前缀不能重复
|
||||
* @param $suffix 可选,文件配置的后缀
|
||||
* @param $event 事件类型,可以指定多个,包括 put,mkfile,delete,copy,move,append,
|
||||
* disable,enable,deleteMarkerCreate
|
||||
* @param $callbackURL 通知URL,可以指定多个,失败依次重试
|
||||
* @param $access_key 可选,设置的话会对通知请求用对应的ak、sk进行签名
|
||||
* @param $host 可选,通知请求的host
|
||||
*
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function putBucketEvent(
|
||||
$bucket,
|
||||
$name,
|
||||
$prefix,
|
||||
$suffix,
|
||||
$event,
|
||||
$callbackURL,
|
||||
$access_key = null,
|
||||
$host = null
|
||||
) {
|
||||
$path = '/events/add';
|
||||
if ($bucket) {
|
||||
$params['bucket'] = $bucket;
|
||||
}
|
||||
if ($name) {
|
||||
$params['name'] = $name;
|
||||
}
|
||||
if ($prefix) {
|
||||
$params['prefix'] = $prefix;
|
||||
}
|
||||
if ($suffix) {
|
||||
$params['suffix'] = $suffix;
|
||||
}
|
||||
if ($callbackURL) {
|
||||
$params['callbackURL'] = $callbackURL;
|
||||
}
|
||||
if ($access_key) {
|
||||
$params['access_key'] = $access_key;
|
||||
}
|
||||
if ($host) {
|
||||
$params['host'] = $host;
|
||||
}
|
||||
$data = http_build_query($params);
|
||||
if ($event) {
|
||||
$eventpath = "";
|
||||
foreach ($event as $key => $value) {
|
||||
$eventpath .= "&event=$value";
|
||||
}
|
||||
$data .= $eventpath;
|
||||
}
|
||||
$info = $this->ucPost($path, $data);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新bucket事件通知规则
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,
|
||||
* 只能为字母、数字、下划线()
|
||||
* @param $prefix 同一个 bucket 里面前缀不能重复
|
||||
* @param $suffix 可选,文件配置的后缀
|
||||
* @param $event 事件类型,可以指定多个,包括 put,mkfile,delete,copy,move,append,disable,
|
||||
* enable,deleteMarkerCreate
|
||||
* @param $callbackURL 通知URL,可以指定多个,失败依次重试
|
||||
* @param $access_key 可选,设置的话会对通知请求用对应的ak、sk进行签名
|
||||
* @param $host 可选,通知请求的host
|
||||
*
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function updateBucketEvent(
|
||||
$bucket,
|
||||
$name,
|
||||
$prefix,
|
||||
$suffix,
|
||||
$event,
|
||||
$callbackURL,
|
||||
$access_key = null,
|
||||
$host = null
|
||||
) {
|
||||
$path = '/events/update';
|
||||
if ($bucket) {
|
||||
$params['bucket'] = $bucket;
|
||||
}
|
||||
if ($name) {
|
||||
$params['name'] = $name;
|
||||
}
|
||||
if ($prefix) {
|
||||
$params['prefix'] = $prefix;
|
||||
}
|
||||
if ($suffix) {
|
||||
$params['suffix'] = $suffix;
|
||||
}
|
||||
if ($event) {
|
||||
$params['event'] = $event;
|
||||
}
|
||||
if ($callbackURL) {
|
||||
$params['callbackURL'] = $callbackURL;
|
||||
}
|
||||
if ($access_key) {
|
||||
$params['access_key'] = $access_key;
|
||||
}
|
||||
if ($host) {
|
||||
$params['host'] = $host;
|
||||
}
|
||||
$data = http_build_query($params);
|
||||
$info = $this->ucPost($path, $data);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bucket事件通知规则
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function getBucketEvents($bucket)
|
||||
{
|
||||
$path = '/events/get?bucket=' . $bucket;
|
||||
$info = $this->ucGet($path);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除bucket事件通知规则
|
||||
*
|
||||
* @param $bucket 空间名
|
||||
* @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,
|
||||
* 只能为字母、数字、下划线
|
||||
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
|
||||
*/
|
||||
public function deleteBucketEvent($bucket, $name)
|
||||
{
|
||||
$path = '/events/delete';
|
||||
if ($bucket) {
|
||||
$params['bucket'] = $bucket;
|
||||
}
|
||||
if ($name) {
|
||||
$params['name'] = $name;
|
||||
}
|
||||
$data = http_build_query($params);
|
||||
$info = $this->ucPost($path, $data);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置bucket的跨域信息,最多允许设置10条跨域规则。
|
||||
* 对于同一个域名如果设置了多条规则,那么按顺序使用第一条匹配的规则去生成返回值。
|
||||
* 对于简单跨域请求,只匹配 Origin;
|
||||
* allowed_orgin: 允许的域名。必填;支持通配符*;*表示全部匹配;只有第一个*生效;
|
||||
* 需要设置"Scheme";大小写敏感。例如
|
||||
* 规则:http://*.abc.*.com 请求:"http://test.abc.test.com" 结果:不通过
|
||||
* 规则:"http://abc.com" 请求:"https://abc.com"/"abc.com" 结果:不通过
|
||||
* 规则:"abc.com" 请求:"http://abc.com" 结果:不通过
|
||||
* allowed_method: 允许的方法。必填;不支持通配符;大小写不敏感;
|
||||
* allowed_header: 允许的header。选填;支持通配符*,
|
||||
* 但只能是单独的*,表示允许全部header,其他*不生效;
|
||||
* 空则不允许任何header;大小写不敏感;
|
||||
* exposed_header: 暴露的header。选填;不支持通配符;
|
||||
* X-Log, X-Reqid是默认会暴露的两个header;
|
||||
* 其他的header如果没有设置,则不会暴露;大小写不敏感;
|
||||
* max_age: 结果可以缓存的时间。选填;空则不缓存;
|
||||
* allowed_credentials:该配置不支持设置,默认为true。
|
||||
* 备注:如果没有设置任何corsRules,那么默认允许所有的跨域请求
|
||||
*/
|
||||
// public function putCorsRules(string $bucket, array $params)
|
||||
// {
|
||||
// $path = '/corsRules/set/' . $bucket;
|
||||
// $data = json_encode($params);
|
||||
// $info = $this->ucPost($path, $data);
|
||||
// return $info;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取bucket的跨域信息
|
||||
* $bucket 空间名
|
||||
*/
|
||||
public function getCorsRules($bucket)
|
||||
{
|
||||
$path = '/corsRules/get/' . $bucket;
|
||||
$info = $this->ucGet($path);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置回源规则
|
||||
* 使用该API设置源站优先级高于/image设置的源站,即IO优先读取source接口设置的源站配置,
|
||||
* 如果存在会忽略/image设置的源站
|
||||
* Bucket 空间名
|
||||
* Host(可选)回源Host
|
||||
* RetryCodes(可选),镜像回源时源站返回Code可以重试,最多指定3个,当前只支持4xx错误码重试
|
||||
* SourceQiniuAK,SourceQiniuSK(可选)如果存在将在回源时对URL进行签名,客户源站可以验证
|
||||
* 以保证请求来自Qiniu服务器
|
||||
* Expires(可选) 签名过期时间,如果不设置默认为1小时
|
||||
* Addr 回源地址,不可重复。
|
||||
* Weight 权重,范围限制1-100,不填默认为1,回源时会根据所有源的权重值进行源站选择,
|
||||
* 主备源会分开计算.
|
||||
* Backup 是否备用回源,回源优先尝试主源
|
||||
*/
|
||||
// public function putBucktSourceConfig(array $params)
|
||||
// {
|
||||
// $path = '/mirrorConfig/set';
|
||||
// $data = json_encode($params);
|
||||
// $info = $this->ucPostV2($path, $data);
|
||||
// return $info;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取空间回源配置
|
||||
*/
|
||||
public function getBucktSourceConfig(array $params)
|
||||
{
|
||||
$path = '/mirrorConfig/get';
|
||||
$data = json_encode($params);
|
||||
$info = $this->ucPostV2($path, $data);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关原图保护
|
||||
* mode 为1表示开启原图保护,0表示关闭
|
||||
*/
|
||||
public function putBucketAccessStyleMode($bucket, $mode)
|
||||
{
|
||||
$path = '/accessMode/' . $bucket . '/mode/' . $mode;
|
||||
$info = $this->ucPost($path, null);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置私有属性
|
||||
* private为0表示公开,为1表示私有
|
||||
*/
|
||||
public function putBucketAccessMode($bucket, $private)
|
||||
{
|
||||
$path = '/bucket/' . $bucket . '/private/' . $private;
|
||||
$info = $this->ucPost($path, null);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置referer防盗链
|
||||
* bucket=<BucketName>: bucket 名
|
||||
* mode=<AntiLeechMode>:
|
||||
* 0: 表示关闭Referer(使用此选项将会忽略以下参数并将恢复默认值);
|
||||
* 1: 表示设置Referer白名单; 2: 表示设置Referer黑名单
|
||||
* norefer=<NoRefer>: 0: 表示不允许空 Refer 访问;
|
||||
* 1: 表示允许空 Refer 访问
|
||||
* pattern=<Pattern>: 规则字符串, 当前允许格式分为三种:
|
||||
* 一种为空主机头域名, 比如 foo.com;
|
||||
* 一种是泛域名, 比如 *.bar.com; 一种是完全通配符, 即一个 *;
|
||||
* 多个规则之间用;隔开, 比如: foo.com;*.bar.com;sub.foo.com;*.sub.bar.com
|
||||
* 空主机头域名可以是多级域名,比如 foo.bar.com。
|
||||
* 多个域名之间不允许夹带空白字符。
|
||||
* source_enabled=:1
|
||||
*/
|
||||
public function putReferAntiLeech($bucket, $mode, $norefer, $pattern, $enabled = 1)
|
||||
{
|
||||
$path = "/referAntiLeech?bucket=$bucket&mode=$mode&norefer=$norefer&pattern=$pattern&source_enabled=$enabled";
|
||||
$info = $this->ucPost($path, null);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Bucket的maxAge
|
||||
* maxAge为0或者负数表示为默认值(31536000)
|
||||
*/
|
||||
public function putBucketMaxAge($bucket, $maxAge)
|
||||
{
|
||||
$path = '/maxAge?bucket=' . $bucket . '&maxAge=' . $maxAge;
|
||||
$info = $this->ucPost($path, null);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置配额
|
||||
* <bucket>: 空间名称,不支持授权空间
|
||||
* <size>: 空间存储量配额,参数传入0或不传表示不更改当前配置,传入-1表示取消限额,
|
||||
* 新创建的空间默认没有限额。
|
||||
* <count>: 空间文件数配额,参数含义同<size>
|
||||
*/
|
||||
public function putBucketQuota($bucket, $size, $count)
|
||||
{
|
||||
$path = '/setbucketquota/' . $bucket . '/size/' . $size . '/count/' . $count;
|
||||
$info = $this->apiPost($path, null);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配额
|
||||
* bucket 空间名称
|
||||
*/
|
||||
public function getBucketQuota($bucket)
|
||||
{
|
||||
$path = '/getbucketquota/' . $bucket;
|
||||
$info = $this->apiPost($path, null);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源的元信息,但不返回文件内容
|
||||
*
|
||||
@@ -94,13 +664,13 @@ final class BucketManager
|
||||
* @param $key 待获取资源的文件名
|
||||
*
|
||||
* @return array 包含文件信息的数组,类似:
|
||||
* [
|
||||
* "hash" => "<Hash string>",
|
||||
* "key" => "<Key string>",
|
||||
* "fsize" => <file size>,
|
||||
* "putTime" => "<file modify time>"
|
||||
* "fileType" => <file type>
|
||||
* ]
|
||||
* [
|
||||
* "hash" => "<Hash string>",
|
||||
* "key" => "<Key string>",
|
||||
* "fsize" => <file size>,
|
||||
* "putTime" => "<file modify time>"
|
||||
* "fileType" => <file type>
|
||||
* ]
|
||||
*
|
||||
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/stat.html
|
||||
*/
|
||||
@@ -142,7 +712,7 @@ final class BucketManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 给资源进行重命名,本质为move操作。
|
||||
* 对资源进行复制。
|
||||
*
|
||||
* @param $from_bucket 待操作资源所在空间
|
||||
* @param $from_key 待操作资源文件名
|
||||
@@ -188,7 +758,7 @@ final class BucketManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动修改指定资源的文件类型
|
||||
* 主动修改指定资源的文件元信息
|
||||
*
|
||||
* @param $bucket 待操作资源所在空间
|
||||
* @param $key 待操作资源文件名
|
||||
@@ -368,12 +938,39 @@ final class BucketManager
|
||||
return $scheme . Config::API_HOST;
|
||||
}
|
||||
|
||||
private function getUcHost()
|
||||
{
|
||||
$scheme = "http://";
|
||||
if ($this->config->useHTTPS == true) {
|
||||
$scheme = "https://";
|
||||
}
|
||||
return $scheme . Config::UC_HOST;
|
||||
}
|
||||
|
||||
private function rsPost($path, $body = null)
|
||||
{
|
||||
$url = $this->getRsHost() . $path;
|
||||
return $this->post($url, $body);
|
||||
}
|
||||
|
||||
private function apiPost($path, $body = null)
|
||||
{
|
||||
$url = $this->getApiHost() . $path;
|
||||
return $this->post($url, $body);
|
||||
}
|
||||
|
||||
private function ucPost($path, $body = null)
|
||||
{
|
||||
$url = $this->getUcHost() . $path;
|
||||
return $this->post($url, $body);
|
||||
}
|
||||
|
||||
private function ucGet($path)
|
||||
{
|
||||
$url = $this->getUcHost() . $path;
|
||||
return $this->get($url);
|
||||
}
|
||||
|
||||
private function apiGet($path)
|
||||
{
|
||||
$url = $this->getApiHost() . $path;
|
||||
@@ -407,6 +1004,24 @@ final class BucketManager
|
||||
return array($r, null);
|
||||
}
|
||||
|
||||
private function ucPostV2($path, $body)
|
||||
{
|
||||
$url = $this->getUcHost() . $path;
|
||||
return $this->postV2($url, $body);
|
||||
}
|
||||
|
||||
private function postV2($url, $body)
|
||||
{
|
||||
$headers = $this->auth->authorizationV2($url, 'POST', $body, 'application/json');
|
||||
$headers["Content-Type"] = 'application/json';
|
||||
$ret = Client::post($url, $body, $headers);
|
||||
if (!$ret->ok()) {
|
||||
return array(null, new Error($url, $ret));
|
||||
}
|
||||
$r = ($ret->body === null) ? array() : $ret->json();
|
||||
return array($r, null);
|
||||
}
|
||||
|
||||
public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket, $force)
|
||||
{
|
||||
return self::twoKeyBatch('/copy', $source_bucket, $key_pairs, $target_bucket, $force);
|
||||
|
||||
@@ -33,10 +33,8 @@ final class FormUploader
|
||||
$mime,
|
||||
$fname
|
||||
) {
|
||||
|
||||
$fields = array('token' => $upToken);
|
||||
if ($key === null) {
|
||||
$fname='nullkey';
|
||||
} else {
|
||||
$fields['key'] = $key;
|
||||
}
|
||||
|
||||
+25
-175
@@ -1,197 +1,47 @@
|
||||
<?php
|
||||
namespace Qiniu;
|
||||
|
||||
use Qiniu\Http\Client;
|
||||
use Qiniu\Http\Error;
|
||||
use Qiniu\Region;
|
||||
|
||||
final class Zone
|
||||
class Zone extends Region
|
||||
{
|
||||
|
||||
//源站上传域名
|
||||
public $srcUpHosts;
|
||||
//CDN加速上传域名
|
||||
public $cdnUpHosts;
|
||||
//资源管理域名
|
||||
public $rsHost;
|
||||
//资源列举域名
|
||||
public $rsfHost;
|
||||
//资源处理域名
|
||||
public $apiHost;
|
||||
//IOVIP域名
|
||||
public $iovipHost;
|
||||
|
||||
//构造一个Zone对象
|
||||
public function __construct(
|
||||
$srcUpHosts = array(),
|
||||
$cdnUpHosts = array(),
|
||||
$rsHost = "rs.qiniu.com",
|
||||
$rsfHost = "rsf.qiniu.com",
|
||||
$apiHost = "api.qiniu.com",
|
||||
$iovipHost = null
|
||||
) {
|
||||
|
||||
$this->srcUpHosts = $srcUpHosts;
|
||||
$this->cdnUpHosts = $cdnUpHosts;
|
||||
$this->rsHost = $rsHost;
|
||||
$this->rsfHost = $rsfHost;
|
||||
$this->apiHost = $apiHost;
|
||||
$this->iovipHost = $iovipHost;
|
||||
}
|
||||
|
||||
//华东机房
|
||||
public static function zone0()
|
||||
public static function zonez0()
|
||||
{
|
||||
$Zone_z0 = new Zone(
|
||||
array("up.qiniup.com", 'up-jjh.qiniup.com', 'up-xs.qiniup.com'),
|
||||
array('upload.qiniup.com', 'upload-jjh.qiniup.com', 'upload-xs.qiniup.com'),
|
||||
'rs.qbox.me',
|
||||
'rsf.qbox.me',
|
||||
'api.qiniu.com',
|
||||
'iovip.qbox.me'
|
||||
);
|
||||
return $Zone_z0;
|
||||
return parent::regionHuadong();
|
||||
}
|
||||
|
||||
//华东机房内网上传
|
||||
public static function zoneZ0()
|
||||
public static function zonez1()
|
||||
{
|
||||
$Zone_z01 = new Zone(
|
||||
array("free-qvm-z0-xs.qiniup.com"),
|
||||
'rs.qbox.me',
|
||||
'rsf.qbox.me',
|
||||
'api.qiniu.com',
|
||||
'iovip.qbox.me'
|
||||
);
|
||||
return $Zone_z01;
|
||||
return parent::regionHuabei();
|
||||
}
|
||||
|
||||
//华北机房内网上传
|
||||
public static function zoneZ1()
|
||||
public static function zonez2()
|
||||
{
|
||||
$Zone_z12 = new Zone(
|
||||
array("free-qvm-z1-zz.qiniup.com"),
|
||||
"rs-z1.qbox.me",
|
||||
"rsf-z1.qbox.me",
|
||||
"api-z1.qiniu.com",
|
||||
"iovip-z1.qbox.me"
|
||||
);
|
||||
return $Zone_z12;
|
||||
return parent::regionHuanan();
|
||||
}
|
||||
|
||||
//华北机房
|
||||
public static function zone1()
|
||||
{
|
||||
$Zone_z1 = new Zone(
|
||||
array('up-z1.qiniup.com'),
|
||||
array('upload-z1.qiniup.com'),
|
||||
"rs-z1.qbox.me",
|
||||
"rsf-z1.qbox.me",
|
||||
"api-z1.qiniu.com",
|
||||
"iovip-z1.qbox.me"
|
||||
);
|
||||
|
||||
return $Zone_z1;
|
||||
}
|
||||
|
||||
//华南机房
|
||||
public static function zone2()
|
||||
{
|
||||
$Zone_z2 = new Zone(
|
||||
array('up-z2.qiniup.com', 'up-dg.qiniup.com', 'up-fs.qiniup.com'),
|
||||
array('upload-z2.qiniup.com', 'upload-dg.qiniup.com', 'upload-fs.qiniup.com'),
|
||||
"rs-z2.qbox.me",
|
||||
"rsf-z2.qbox.me",
|
||||
"api-z2.qiniu.com",
|
||||
"iovip-z2.qbox.me"
|
||||
);
|
||||
return $Zone_z2;
|
||||
}
|
||||
|
||||
//北美机房
|
||||
public static function zoneNa0()
|
||||
{
|
||||
//北美机房
|
||||
$Zone_na0 = new Zone(
|
||||
array('up-na0.qiniup.com'),
|
||||
array('upload-na0.qiniup.com'),
|
||||
"rs-na0.qbox.me",
|
||||
"rsf-na0.qbox.me",
|
||||
"api-na0.qiniu.com",
|
||||
"iovip-na0.qbox.me"
|
||||
);
|
||||
return $Zone_na0;
|
||||
}
|
||||
|
||||
//新加坡机房
|
||||
public static function zoneAs0()
|
||||
{
|
||||
//新加坡机房
|
||||
$Zone_as0 = new Zone(
|
||||
array('up-as0.qiniup.com'),
|
||||
array('upload-as0.qiniup.com'),
|
||||
"rs-as0.qbox.me",
|
||||
"rsf-as0.qbox.me",
|
||||
"api-as0.qiniu.com",
|
||||
"iovip-as0.qbox.me"
|
||||
);
|
||||
return $Zone_as0;
|
||||
return parent::regionSingapore();
|
||||
}
|
||||
|
||||
public static function zoneNa0()
|
||||
{
|
||||
return parent::regionNorthAmerica();
|
||||
}
|
||||
|
||||
public static function qvmZonez0()
|
||||
{
|
||||
return parent::qvmRegionHuadong();
|
||||
}
|
||||
|
||||
public static function qvmZonez1()
|
||||
{
|
||||
return parent::qvmRegionHuabei();
|
||||
}
|
||||
|
||||
/*
|
||||
* GET /v2/query?ak=<ak>&&bucket=<bucket>
|
||||
**/
|
||||
public static function queryZone($ak, $bucket)
|
||||
{
|
||||
$zone = new Zone();
|
||||
$url = Config::UC_HOST . '/v2/query' . "?ak=$ak&bucket=$bucket";
|
||||
$ret = Client::Get($url);
|
||||
if (!$ret->ok()) {
|
||||
return array(null, new Error($url, $ret));
|
||||
}
|
||||
$r = ($ret->body === null) ? array() : $ret->json();
|
||||
//print_r($ret);
|
||||
//parse zone;
|
||||
|
||||
$iovipHost = $r['io']['src']['main'][0];
|
||||
$zone->iovipHost = $iovipHost;
|
||||
$accMain = $r['up']['acc']['main'][0];
|
||||
array_push($zone->cdnUpHosts, $accMain);
|
||||
if (isset($r['up']['acc']['backup'])) {
|
||||
foreach ($r['up']['acc']['backup'] as $key => $value) {
|
||||
array_push($zone->cdnUpHosts, $value);
|
||||
}
|
||||
}
|
||||
$srcMain = $r['up']['src']['main'][0];
|
||||
array_push($zone->srcUpHosts, $srcMain);
|
||||
if (isset($r['up']['src']['backup'])) {
|
||||
foreach ($r['up']['src']['backup'] as $key => $value) {
|
||||
array_push($zone->srcUpHosts, $value);
|
||||
}
|
||||
}
|
||||
|
||||
//set specific hosts
|
||||
if (strstr($zone->iovipHost, "z1") !== false) {
|
||||
$zone->rsHost = "rs-z1.qbox.me";
|
||||
$zone->rsfHost = "rsf-z1.qbox.me";
|
||||
$zone->apiHost = "api-z1.qiniu.com";
|
||||
} elseif (strstr($zone->iovipHost, "z2") !== false) {
|
||||
$zone->rsHost = "rs-z2.qbox.me";
|
||||
$zone->rsfHost = "rsf-z2.qbox.me";
|
||||
$zone->apiHost = "api-z2.qiniu.com";
|
||||
} elseif (strstr($zone->iovipHost, "na0") !== false) {
|
||||
$zone->rsHost = "rs-na0.qbox.me";
|
||||
$zone->rsfHost = "rsf-na0.qbox.me";
|
||||
$zone->apiHost = "api-na0.qiniu.com";
|
||||
} elseif (strstr($zone->iovipHost, "as0") !== false) {
|
||||
$zone->rsHost = "rs-as0.qbox.me";
|
||||
$zone->rsfHost = "rsf-as0.qbox.me";
|
||||
$zone->apiHost = "api-as0.qiniu.com";
|
||||
} else {
|
||||
$zone->rsHost = "rs.qbox.me";
|
||||
$zone->rsfHost = "rsf.qbox.me";
|
||||
$zone->apiHost = "api.qiniu.com";
|
||||
}
|
||||
|
||||
return $zone;
|
||||
return parent::queryRegion($ak, $bucket);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-10
@@ -34,17 +34,8 @@ class CdnManagerTest extends \PHPUnit_Framework_TestCase
|
||||
$signUrl = $this->cdnManager->createTimestampAntiLeechUrl($this->imgUrl, $this->encryptKey, 3600);
|
||||
|
||||
$response = Client::get($signUrl);
|
||||
|
||||
$this->assertEquals($response->statusCode, 200);
|
||||
$this->assertNull($response->error);
|
||||
|
||||
$url2 = $this->imgUrl . '?imageInfo';
|
||||
$signUrl2 = $this->cdnManager->createTimestampAntiLeechUrl($url2, $this->encryptKey, 3600);
|
||||
|
||||
$response = Client::get($signUrl2);
|
||||
$imgInfo = $response->json();
|
||||
|
||||
$this->assertEquals($response->statusCode, 200);
|
||||
$this->assertEquals($imgInfo['size'], 2196145);
|
||||
$this->assertNull($response->error);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class ResumeUpTest extends \PHPUnit_Framework_TestCase
|
||||
public function test4ML2()
|
||||
{
|
||||
$key = 'resumePutFile4ML';
|
||||
$zone = new Zone(array('up.qiniup.com'));
|
||||
$zone = new Zone(array('up.fake.qiniu.com'), array('up.qiniup.com'));
|
||||
$cfg = new Config($zone);
|
||||
$upManager = new UploadManager($cfg);
|
||||
$token = $this->auth->uploadToken($this->bucketName, $key);
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ $dummyAuth = new Auth($dummyAccessKey, $dummySecretKey);
|
||||
|
||||
//cdn
|
||||
$timestampAntiLeechEncryptKey = getenv('QINIU_TIMESTAMP_ENCRPTKEY');
|
||||
$customDomain = "http://phpsdk.qiniuts.com";
|
||||
$customDomain = "http://phpsdk.peterpy.cn";
|
||||
|
||||
$tid = getenv('TRAVIS_JOB_NUMBER');
|
||||
if (!empty($tid)) {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
.idea
|
||||
.DS_store
|
||||
/vendor/
|
||||
composer.phar
|
||||
composer.lock
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
|
||||
before_script:
|
||||
- composer install
|
||||
|
||||
script:
|
||||
- mkdir -p build/logs
|
||||
- php vendor/bin/phpunit -c phpunit.xml
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls -v
|
||||
+8
@@ -14,6 +14,14 @@ This is a simple polyfill for [`getallheaders()`](http://www.php.net/manual/en/f
|
||||
|
||||
## Install
|
||||
|
||||
For PHP version **`>= 5.6`**:
|
||||
|
||||
```
|
||||
composer require ralouphie/getallheaders
|
||||
```
|
||||
|
||||
For PHP version **`< 5.6`**:
|
||||
|
||||
```
|
||||
composer require ralouphie/getallheaders "^2"
|
||||
```
|
||||
|
||||
+9
-4
@@ -9,13 +9,18 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~3.7.0",
|
||||
"satooshi/php-coveralls": ">=1.0"
|
||||
"phpunit/phpunit": "^5 || ^6.5",
|
||||
"php-coveralls/php-coveralls": "^2.1"
|
||||
},
|
||||
"autoload": {
|
||||
"files": ["src/getallheaders.php"]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"getallheaders\\Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
<phpunit
|
||||
bootstrap="vendor/autoload.php"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
strict="true">
|
||||
|
||||
<testsuite>
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||
</logging>
|
||||
|
||||
</phpunit>
|
||||
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
class GetAllHeadersTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @dataProvider testWorksData
|
||||
*/
|
||||
public function testWorks($test_type, $expected, $server)
|
||||
{
|
||||
foreach ($server as $key => $val) {
|
||||
$_SERVER[$key] = $val;
|
||||
}
|
||||
$result = getallheaders();
|
||||
$this->assertEquals($expected, $result, "Error testing $test_type works.");
|
||||
}
|
||||
|
||||
public function testWorksData()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'normal case',
|
||||
array(
|
||||
'Key-One' => 'foo',
|
||||
'Key-Two' => 'bar',
|
||||
'Another-Key-For-Testing' => 'baz'
|
||||
),
|
||||
array(
|
||||
'HTTP_KEY_ONE' => 'foo',
|
||||
'HTTP_KEY_TWO' => 'bar',
|
||||
'HTTP_ANOTHER_KEY_FOR_TESTING' => 'baz'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Content-Type',
|
||||
array(
|
||||
'Content-Type' => 'two'
|
||||
),
|
||||
array(
|
||||
'HTTP_CONTENT_TYPE' => 'one',
|
||||
'CONTENT_TYPE' => 'two'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Content-Length',
|
||||
array(
|
||||
'Content-Length' => '222'
|
||||
),
|
||||
array(
|
||||
'CONTENT_LENGTH' => '222',
|
||||
'HTTP_CONTENT_LENGTH' => '111'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Content-Length (HTTP_CONTENT_LENGTH only)',
|
||||
array(
|
||||
'Content-Length' => '111'
|
||||
),
|
||||
array(
|
||||
'HTTP_CONTENT_LENGTH' => '111'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Content-MD5',
|
||||
array(
|
||||
'Content-Md5' => 'aef123'
|
||||
),
|
||||
array(
|
||||
'CONTENT_MD5' => 'aef123',
|
||||
'HTTP_CONTENT_MD5' => 'fea321'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Content-MD5 (HTTP_CONTENT_MD5 only)',
|
||||
array(
|
||||
'Content-Md5' => 'f123'
|
||||
),
|
||||
array(
|
||||
'HTTP_CONTENT_MD5' => 'f123'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Authorization (normal)',
|
||||
array(
|
||||
'Authorization' => 'testing'
|
||||
),
|
||||
array(
|
||||
'HTTP_AUTHORIZATION' => 'testing',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Authorization (redirect)',
|
||||
array(
|
||||
'Authorization' => 'testing redirect'
|
||||
),
|
||||
array(
|
||||
'REDIRECT_HTTP_AUTHORIZATION' => 'testing redirect',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Authorization (PHP_AUTH_USER + PHP_AUTH_PW)',
|
||||
array(
|
||||
'Authorization' => 'Basic ' . base64_encode('foo:bar')
|
||||
),
|
||||
array(
|
||||
'PHP_AUTH_USER' => 'foo',
|
||||
'PHP_AUTH_PW' => 'bar'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Authorization (PHP_AUTH_DIGEST)',
|
||||
array(
|
||||
'Authorization' => 'example-digest'
|
||||
),
|
||||
array(
|
||||
'PHP_AUTH_DIGEST' => 'example-digest'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user