Commit 081c404a authored by wolfcode's avatar wolfcode

Adapt to PHP 8.2

parent 439ccd17
......@@ -10,11 +10,11 @@
namespace app\admin\controller;
use app\common\controller\AdminBase;
use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;
use Webman\Captcha\CaptchaBuilder;
use support\Request;
use support\Response;
use think\facade\Cache;
use Webman\Captcha\PhraseBuilder;
class Out extends AdminBase
{
......
This diff is collapsed.
......@@ -16,8 +16,8 @@ use Dotenv\Dotenv;
use support\Log;
use Webman\Bootstrap;
use Webman\Config;
use Webman\Route;
use Webman\Middleware;
use Webman\Route;
use Webman\Util;
$worker = $worker ?? null;
......@@ -29,16 +29,16 @@ set_error_handler(function ($level, $message, $file = '', $line = 0) {
});
if ($worker) {
register_shutdown_function(function ($start_time) {
if (time() - $start_time <= 1) {
register_shutdown_function(function ($startTime) {
if (time() - $startTime <= 0.1) {
sleep(1);
}
}, time());
}
if (class_exists('Dotenv\Dotenv') && file_exists(base_path() . '/.env')) {
if (method_exists('Dotenv\Dotenv', 'createUnsafeImmutable')) {
Dotenv::createUnsafeImmutable(base_path())->load();
if (method_exists('Dotenv\Dotenv', 'createUnsafeMutable')) {
Dotenv::createUnsafeMutable(base_path())->load();
} else {
Dotenv::createMutable(base_path())->load();
}
......@@ -67,30 +67,30 @@ foreach (config('plugin', []) as $firm => $projects) {
}
}
Middleware::load(config('middleware', []), '');
Middleware::load(config('middleware', []));
foreach (config('plugin', []) as $firm => $projects) {
foreach ($projects as $name => $project) {
if (!is_array($project) || $name === 'static') {
continue;
}
Middleware::load($project['middleware'] ?? [], '');
Middleware::load($project['middleware'] ?? []);
}
Middleware::load($projects['middleware'] ?? [], $firm);
if ($static_middlewares = config("plugin.$firm.static.middleware")) {
Middleware::load(['__static__' => $static_middlewares], $firm);
if ($staticMiddlewares = config("plugin.$firm.static.middleware")) {
Middleware::load(['__static__' => $staticMiddlewares], $firm);
}
}
Middleware::load(['__static__' => config('static.middleware', [])], '');
Middleware::load(['__static__' => config('static.middleware', [])]);
foreach (config('bootstrap', []) as $class_name) {
if (!class_exists($class_name)) {
$log = "Warning: Class $class_name setting in config/bootstrap.php not found\r\n";
foreach (config('bootstrap', []) as $className) {
if (!class_exists($className)) {
$log = "Warning: Class $className setting in config/bootstrap.php not found\r\n";
echo $log;
Log::error($log);
continue;
}
/** @var Bootstrap $class_name */
$class_name::start($worker);
/** @var Bootstrap $className */
$className::start($worker);
}
foreach (config('plugin', []) as $firm => $projects) {
......@@ -98,26 +98,27 @@ foreach (config('plugin', []) as $firm => $projects) {
if (!is_array($project)) {
continue;
}
foreach ($project['bootstrap'] ?? [] as $class_name) {
if (!class_exists($class_name)) {
$log = "Warning: Class $class_name setting in config/plugin/$firm/$name/bootstrap.php not found\r\n";
foreach ($project['bootstrap'] ?? [] as $className) {
if (!class_exists($className)) {
$log = "Warning: Class $className setting in config/plugin/$firm/$name/bootstrap.php not found\r\n";
echo $log;
Log::error($log);
continue;
}
/** @var Bootstrap $class_name */
$class_name::start($worker);
/** @var Bootstrap $className */
$className::start($worker);
}
}
foreach ($projects['bootstrap'] ?? [] as $class_name) {
if (!class_exists($class_name)) {
$log = "Warning: Class $class_name setting in plugin/$firm/config/bootstrap.php not found\r\n";
foreach ($projects['bootstrap'] ?? [] as $className) {
/** @var string $className */
if (!class_exists($className)) {
$log = "Warning: Class $className setting in plugin/$firm/config/bootstrap.php not found\r\n";
echo $log;
Log::error($log);
continue;
}
/** @var Bootstrap $class_name */
$class_name::start($worker);
/** @var Bootstrap $className */
$className::start($worker);
}
}
......
This diff is collapsed.
# ChangeLog - Aliyun OSS SDK for PHP
## v2.6.0 / 2022-08-03
* Added: support credentials provider.
* Fixed: compatible with swoole curl handler.
* Added: support more bucket stat info.
## v2.5.0 / 2022-05-13
* Added: support bucket transfer acceleration.
* Added: support bucket cname token.
* Added: support listobjectsV2.
## v2.4.3 / 2021-08-25
* Fixed: integer overflow in PHP5.x.
......
......@@ -18,6 +18,24 @@ Common::println("bucket $bucket created");
$doesExist = $ossClient->doesBucketExist($bucket);
Common::println("bucket $bucket exist? " . ($doesExist ? "yes" : "no"));
// Get the region of bucket
$regions = $ossClient->getBucketLocation($bucket);
Common::println("bucket $bucket region: " .print_r($regions,true));
// Get the meta of a bucket
$metas = $ossClient->getBucketMeta($bucket);
Common::println("bucket $bucket meta: " .print_r($metas,true));
// Get the info of bucket
$info = $ossClient->getBucketInfo($bucket);
Common::println("bucket name:".$info->getName()."\n");
Common::println("bucket location:". $info->getLocation()."\n");
Common::println("bucket creation time:".$info->getCreateDate()."\n");
Common::println("bucket storage class:".$info->getStorageClass()."\n");
Common::println("bucket extranet endpoint:".$info->getExtranetEndpoint()."\n");
Common::println("bucket intranet endpoint:".$info->getIntranetEndpoint()."\n");
// Get the bucket list
$bucketListInfo = $ossClient->listBuckets();
......@@ -33,6 +51,9 @@ Common::println("bucket $bucket acl get: " . $acl);
createBucket($ossClient, $bucket);
doesBucketExist($ossClient, $bucket);
getBucketLocation($ossClient, $bucket);
getBucketMeta($ossClient,$bucket);
getBucketInfo($ossClient, $bucket);
deleteBucket($ossClient, $bucket);
putBucketAcl($ossClient, $bucket);
getBucketAcl($ossClient, $bucket);
......@@ -82,6 +103,71 @@ function doesBucketExist($ossClient, $bucket)
}
}
/**
* Get the info of bucket
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
*/
function getBucketInfo($ossClient, $bucket)
{
try {
$info = $ossClient->getBucketInfo($bucket);
printf("bucket name:%s\n", $info->getName());
printf("bucket location:%s\n", $info->getLocation());
printf("bucket creation time:%s\n", $info->getCreateDate());
printf("bucket storage class:%s\n", $info->getStorageClass());
printf("bucket extranet endpoint:%s\n", $info->getExtranetEndpoint());
printf("bucket intranet endpoint:%s\n", $info->getIntranetEndpoint());
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Get the meta of a bucket
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
*/
function getBucketLocation($ossClient, $bucket)
{
try {
$regions = $ossClient->getBucketLocation($bucket);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print("bucket $bucket region: " .print_r($regions,true));
}
/**
* Get the bucket's meta
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
*/
function getBucketMeta($ossClient, $bucket)
{
try {
$metas = $ossClient->getBucketMeta($bucket);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
print("bucket $bucket meta: " .print_r($metas,true));
}
/**
* Delete a bucket. If the bucket is not empty, the deletion fails.
* A bucket which is not empty indicates that it does not contain any objects or parts that are not completely uploaded during multipart upload
......
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
$bucket = Common::getBucketName();
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
//*******************************Simple Usage ***************************************************************
// Add Canme record
$myDomain = '<yourDomainName>';
$ossClient->addBucketCname($bucket, $myDomain);
// View cname records
$cnameConfig = $ossClient->getBucketCname($bucket);
Common::println("bucket $bucket cname:" . $cnameConfig->serializeToXml());
// Delete bucket cname
$myDomain = '<yourDomainName>';
$ossClient->deleteBucketCname($bucket,$myDomain);
Common::println("bucket $bucket cname deleted");
//******************************* For complete usage, see the following functions ****************************************************
addBucketCname($ossClient, $bucket);
getBucketCname($ossClient, $bucket);
deleteBucketCname($ossClient, $bucket);
/**
* Set bucket cname
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function addBucketCname($ossClient, $bucket)
{
// Set up a custom domain name.
$myDomain = '<yourDomainName>';
try {
$ossClient->addBucketCname($bucket, $myDomain);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Get bucket cname
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function getBucketCname($ossClient, $bucket)
{
try {
$cnameConfig = $ossClient->getBucketCname($bucket);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
print($cnameConfig->serializeToXml() . "\n");
}
/**
* Delete bucket cname
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function deleteBucketCname($ossClient, $bucket)
{
$myDomain = '<yourDomainName>';
try {
$ossClient->deleteBucketCname($bucket, $myDomain);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Model\ServerSideEncryptionConfig;
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
$bucket = Common::getBucketName();
//******************************* Simple Usage****************************************************************
// Configure Bucket encryption
// Set Bucket's default server-side encryption method to OSS fully managed encryption (SSE-OSS).
$config = new ServerSideEncryptionConfig("AES256");
// Set Bucket's default server-side encryption method to KMS, and do not specify a CMK ID.
//$config = new ServerSideEncryptionConfig("KMS");
// Set Bucket's default server-side encryption method to KMS, and specify the CMK ID.
//$config = new ServerSideEncryptionConfig("KMS", "your kms id");
$ossClient->putBucketEncryption($bucket, $config);
Common::println("bucket $bucket encryoption created");
$config = $ossClient->getBucketEncryption($bucket);
Common::println("bucket $bucket encryoption:".$config->serializeToXml());
$config = $ossClient->deleteBucketEncryption($bucket);
Common::println("bucket $bucket encryoption has deleted");
//******************************* For complete usage, see the following functions ****************************************************
putBucketEncryption($ossClient, $bucket);
getBucketEncryption($ossClient, $bucket);
deleteBucketEncryption($ossClient, $bucket);
/**
* Configure Bucket encryption
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function putBucketEncryption($ossClient,$bucket){
try {
// Set Bucket's default server-side encryption method to OSS fully managed encryption (SSE-OSS).
$config = new ServerSideEncryptionConfig("AES256");
// Set Bucket's default server-side encryption method to KMS, and do not specify a CMK ID.
//$config = new ServerSideEncryptionConfig("KMS");
// Set Bucket's default server-side encryption method to KMS, and specify the CMK ID.
//$config = new ServerSideEncryptionConfig("KMS", "your kms id");
$ossClient->putBucketEncryption($bucket, $config);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Get Bucket encryption
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function getBucketEncryption($ossClient,$bucket){
try {
$config = $ossClient->getBucketEncryption($bucket);
print($config->getSSEAlgorithm());
print($config->getKMSMasterKeyID());
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Delete Bucket encryption
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function deleteBucketEncryption($ossClient,$bucket){
try {
$ossClient->deleteBucketEncryption($bucket);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
$bucket = Common::getBucketName();
//******************************* Simple Usage****************************************************************
//Set requester payment mode
$ossClient->putBucketRequestPayment($bucket, "Requester");
//Get requester payment mode configuration
$payer = $ossClient->getBucketRequestPayment($bucket);
Common::println("bucket $bucket Payer:".$payer.PHP_EOL);
//Third-party paid access to Object
$options = array(
OssClient::OSS_HEADERS => array(
OssClient::OSS_REQUEST_PAYER => 'requester',
));
$content = "hello";
$object = "object";
//PutObject interface to specify the payer
$ossClient->putObject($bucket, $object, $content, $options);
// GetObject interface to specify the payer
$ossClient->getObject($bucket, $object, $options);
// DeleteObject interface to specify the payer
$ossClient->deleteObject($bucket, $object, $options);
//******************************* For complete usage, see the following functions ****************************************************
putBucketRequestPayment($ossClient,$bucket);
getBucketRequestPayment($ossClient,$bucket);
setObjectPayment($ossClient,$bucket);
/**
* Set requester payment mode
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function putBucketRequestPayment($ossClient, $bucket)
{
try {
$ossClient->putBucketRequestPayment($bucket, "Requester");
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Get payment mode of bucket
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function getBucketRequestPayment($ossClient, $bucket)
{
try {
$payer = $ossClient->getBucketRequestPayment($bucket);
print("bucket $bucket Payer:".$payer.PHP_EOL);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Set payment mode of object
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function setObjectPayment($ossClient,$bucket){
// Specify the payment model for the requester.
$options = array(
OssClient::OSS_HEADERS => array(
OssClient::OSS_REQUEST_PAYER => 'requester',
));
try {
$content = "hello";
$object = "object";
//PutObject interface to specify the payer
$ossClient->putObject($bucket, $object, $content, $options);
// GetObject interface to specify the payer
$ossClient->getObject($bucket, $object, $options);
// DeleteObject interface to specify the payer
$ossClient->deleteObject($bucket, $object, $options);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
$bucket = Common::getBucketName();
//******************************* Simple Usage****************************************************************
// Set Bucket Policy
// Authorization strategy.
$policy = <<< BBBB
{
"Version":"1",
"Statement":[
{
"Action":[
"oss:PutObject",
"oss:GetObject"
],
"Effect":"Allow",
"Resource":["acs:oss:*:*:*/user1/*"]
}
]
}
BBBB;
$ossClient->putBucketPolicy($bucket, $policy);
// Get bucket pllicy
$policy = $ossClient->getBucketPolicy($bucket);
Common::println("bucket $bucket policy: " . $policy);
// Delete bucket pllicy
$policy = $ossClient->deleteBucketPolicy($bucket);
//******************************* For complete usage, see the following functions ****************************************************
putBucketPolicy($ossClient, $bucket);
getBucketPolicy($ossClient, $bucket);
deleteBucketPolicy($ossClient, $bucket);
/**
* Set Bucket Policy
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function putBucketPolicy($ossClient, $bucket)
{
$policy = <<< BBBB
{
"Version":"1",
"Statement":[
{
"Action":[
"oss:PutObject",
"oss:GetObject"
],
"Effect":"Allow",
"Resource":["acs:oss:*:*:*/user1/*"]
}
]
}
BBBB;
try {
$ossClient->putBucketPolicy($bucket, $policy);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Get Bucket Policy
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function getBucketPolicy($ossClient, $bucket)
{
try {
$policy = $ossClient->getBucketPolicy($bucket);
print($policy);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Delete Bucket Policy
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function deleteBucketPolicy($ossClient, $bucket)
{
try {
$ossClient->deleteBucketPolicy($bucket);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
$bucket = Common::getBucketName();
//******************************* Simple Usage****************************************************************
// Get Bucket Stat
$stat = $ossClient->getBucketStat($bucket);
Common::println("Bucket ".$bucket." current storage is:".$stat->getStorage().PHP_EOL);
Common::println("Bucket ".$bucket." object count is:".$stat->getObjectCount().PHP_EOL);
Common::println("Bucket ".$bucket." multipart upload count is:".$stat->getMultipartUploadCount().PHP_EOL);
Common::println("Bucket ".$bucket." live channel count is:".$stat->getLiveChannelCount().PHP_EOL);
Common::println("Bucket ".$bucket." last modified time is:".$stat->getLastModifiedTime().PHP_EOL);
Common::println("Bucket ".$bucket." standard storage is:".$stat->getStandardStorage().PHP_EOL);
Common::println("Bucket ".$bucket." standard object count is:".$stat->getStandardObjectCount().PHP_EOL);
Common::println("Bucket ".$bucket." infrequent access storage is:".$stat->getInfrequentAccessStorage().PHP_EOL);
Common::println("Bucket ".$bucket." infrequent access real storage is:".$stat->getInfrequentAccessRealStorage().PHP_EOL);
Common::println("Bucket ".$bucket." infrequent access object count is:".$stat->getInfrequentAccessObjectCount().PHP_EOL);
Common::println("Bucket ".$bucket." archive storage is:".$stat->getArchiveStorage().PHP_EOL);
Common::println("Bucket ".$bucket." archive real storage is:".$stat->getArchiveRealStorage().PHP_EOL);
Common::println("Bucket ".$bucket." archive object count is:".$stat->getArchiveObjectCount().PHP_EOL);
Common::println("Bucket ".$bucket." cold archive storage is:".$stat->getColdArchiveStorage().PHP_EOL);
Common::println("Bucket ".$bucket." cold archive real storage is:".$stat->getColdArchiveRealStorage().PHP_EOL);
Common::println("Bucket ".$bucket." cold archive object count is:".$stat->getColdArchiveObjectCount().PHP_EOL);
//******************************* For complete usage, see the following functions ****************************************************
getBucketStat($ossClient,$bucket);
/**
* get bucket stat
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function getBucketStat($ossClient, $bucket)
{
try {
$stat = $ossClient->getBucketStat($bucket);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
printf("Bucket ".$bucket." current storage is:".$stat->getStorage().PHP_EOL);
printf("Bucket ".$bucket." object count is:".$stat->getObjectCount().PHP_EOL);
printf("Bucket ".$bucket." multipart upload count is:".$stat->getMultipartUploadCount().PHP_EOL);
printf("Bucket ".$bucket." live channel count is:".$stat->getLiveChannelCount().PHP_EOL);
printf("Bucket ".$bucket." last modified time is:".$stat->getLastModifiedTime().PHP_EOL);
printf("Bucket ".$bucket." standard storage is:".$stat->getStandardStorage().PHP_EOL);
printf("Bucket ".$bucket." standard object count is:".$stat->getStandardObjectCount().PHP_EOL);
printf("Bucket ".$bucket." infrequent access storage is:".$stat->getInfrequentAccessStorage().PHP_EOL);
printf("Bucket ".$bucket." infrequent access real storage is:".$stat->getInfrequentAccessRealStorage().PHP_EOL);
printf("Bucket ".$bucket." infrequent access object count is:".$stat->getInfrequentAccessObjectCount().PHP_EOL);
printf("Bucket ".$bucket." archive storage is:".$stat->getArchiveStorage().PHP_EOL);
printf("Bucket ".$bucket." archive real storage is:".$stat->getArchiveRealStorage().PHP_EOL);
printf("Bucket ".$bucket." archive object count is:".$stat->getArchiveObjectCount().PHP_EOL);
printf("Bucket ".$bucket." cold archive storage is:".$stat->getColdArchiveStorage().PHP_EOL);
printf("Bucket ".$bucket." cold archive real storage is:".$stat->getColdArchiveRealStorage().PHP_EOL);
printf("Bucket ".$bucket." cold archive object count is:".$stat->getColdArchiveObjectCount().PHP_EOL);
print(__FUNCTION__ . ": OK" . "\n");
}
\ No newline at end of file
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Model\TaggingConfig;
use OSS\Model\Tag;
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
$bucket = Common::getBucketName();
//******************************* Simple Usage****************************************************************
// Set bucket tag
$config = new TaggingConfig();
$config->addTag(new Tag("key1", "value1"));
$config->addTag(new Tag("key2", "value2"));
$ossClient->putBucketTags($bucket, $config);
// Get bucket tags
$config = $ossClient->getBucketTags($bucket);
Common::println("bucket $bucket tags: ".$config->serializeToXml());
// Delete bucket tags
// Delete the specified tag of the bucket.
$tags = array();
$tags[] = new Tag("key1", "value1");
$tags[] = new Tag("key2", "value2");
$ossClient->deleteBucketTags($bucket, $tags);
// Delete all tags in the bucket.
$ossClient->deleteBucketTags($bucket);
//******************************* For complete usage, see the following functions ****************************************************
putBucketTags($ossClient, $bucket);
getBucketTags($ossClient, $bucket);
deleteBucketTags($ossClient, $bucket);
/**
* Create bucket tag
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function putBucketTags($ossClient, $bucket)
{
try {
// 设置Bucket标签。
$config = new TaggingConfig();
$config->addTag(new Tag("key1", "value1"));
$config->addTag(new Tag("key2", "value2"));
$ossClient->putBucketTags($bucket, $config);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* get bucket tag
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function getBucketTags($ossClient, $bucket)
{
try {
$config = $ossClient->getBucketTags($bucket);
print_r($config->getTags());
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* delete bucket tag
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function deleteBucketTags($ossClient, $bucket)
{
try {
// Delete the specified tag of the bucket.
$tags = array();
$tags[] = new Tag("key1", "value1");
$tags[] = new Tag("key2", "value2");
$ossClient->deleteBucketTags($bucket, $tags);
// Delete all tags in the bucket.
//$ossClient->deleteBucketTags($bucket);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
$bucket = Common::getBucketName();
//******************************* Simple Usage****************************************************************
// set <tran></tran>sfer acceleration
$enabled = true; // set true to enable transfer acceleration; set false to disalbe transfer acceleration
$ossClient->putBucketTransferAcceleration($bucket, $enabled);
printf('putBucketTransferAcceleration SUCCESS' . "\n");
// get transfer acceleration
$result = $ossClient->getBucketTransferAcceleration($bucket);
printf('getBucketTransferAcceleration Status:%s'."\n",$result);
//******************************* For complete usage, see the following functions ****************************************************
putBucketTransferAcceleration($ossClient,$bucket);
getBucketTransferAcceleration($bucket);
/**
* @param $ossClient OssClient
* @param $bucket bucket_name string
* @param $enabled string
*/
function putBucketTransferAcceleration($ossClient, $bucket, $enabled)
{
try{
$enabled = true; // set true to enable transfer acceleration; set false to disalbe transfer acceleration
$ossClient->putBucketTransferAcceleration($bucket,$enabled);
printf('putBucketTransferAcceleration SUCCESS' . "\n");
} catch(OssException $e) {
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* @param $ossClient OssClient
* @param $bucket bucket_name string
*/
function getBucketTransferAcceleration($ossClient, $bucket)
{
try{
$result = $ossClient->getBucketTransferAcceleration($bucket);
printf('getBucketTransferAcceleration Status:%s'."\n",$result);
} catch(OssException $e) {
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
$bucket = Common::getBucketName();
//******************************* Simple Usage****************************************************************
//Set Bucket version control status
//Set the storage space version control to enable version control (Enabled) or suspend version control (Suspended).
$ossClient->putBucketVersioning($bucket, "Enabled");
Common::println("bucket $bucket version Enabled");
// show all object list
$option = array(
OssClient::OSS_KEY_MARKER => null,
OssClient::OSS_VERSION_ID_MARKER => null
);
$bool = true;
while ($bool) {
$result = $ossClient->listObjectVersions($bucket, $option);
## View the version information of the listed object.
foreach ($result->getObjectVersionList() as $key => $info) {
Common::println("key name: " . $info->getKey());
Common::println("versionid: " . $info->getVersionId());
Common::println("Is latest: " . $info->getIsLatest());
}
## View the version information that lists the deletion flags.
foreach ($result->getDeleteMarkerList() as $key => $info) {
Common::println("del_maker key name: " . $info->getKey());
Common::println("del_maker versionid: " . $info->getVersionId());
Common::println("del_maker Is latest: " . $info->getIsLatest());
}
if ($result->getIsTruncated() === 'true') {
$option = array(
OssClient::OSS_KEY_MARKER => $result->getNextKeyMarker(),
OssClient::OSS_VERSION_ID_MARKER => $result->getNextVersionIdMarker()
);
} else {
$bool = false;
}
}
// show the prefix object
$option = array(
OssClient::OSS_KEY_MARKER => null,
OssClient::OSS_VERSION_ID_MARKER => null,
OssClient::OSS_PREFIX => "test"
);
$bool = true;
while ($bool) {
$result = $ossClient->listObjectVersions($bucket, $option);
## View the version information of the listed object.
foreach ($result->getObjectVersionList() as $key => $info) {
Common::println("key name: " . $info->getKey());
Common::println("versionid: " . $info->getVersionId());
Common::println("Is latest: " . $info->getIsLatest());
}
## View the version information that lists the deletion flags.
foreach ($result->getDeleteMarkerList() as $key => $info) {
Common::println("del_maker key name: " . $info->getKey());
Common::println("del_maker versionid: " . $info->getVersionId());
Common::println("del_maker Is latest: " . $info->getIsLatest());
}
if ($result->getIsTruncated() === 'true') {
$option[OssClient::OSS_KEY_MARKER] = $result->getNextKeyMarker();
$option[OssClient::OSS_VERSION_ID_MARKER] = $result->getNextVersionIdMarker();
} else {
$bool = false;
}
}
// list the number of objects
$option = array(
OssClient::OSS_KEY_MARKER => null,
OssClient::OSS_VERSION_ID_MARKER => null,
OssClient::OSS_MAX_KEYS => 200
);
$result = $ossClient->listObjectVersions($bucket, $option);
## View the version information of the listed object.
foreach ($result->getObjectVersionList() as $key => $info) {
Common::println("key name: " . $info->getKey());
Common::println("versionid: " . $info->getVersionId());
Common::println("Is latest: " . $info->getIsLatest());
}
## View the version information that lists the deletion flags.
foreach ($result->getDeleteMarkerList() as $key => $info) {
Common::println("del_maker key name: " . $info->getKey());
Common::println("del_maker versionid: " . $info->getVersionId());
Common::println("del_maker Is latest: " . $info->getIsLatest());
}
// show root folder list
$option = array(
OssClient::OSS_KEY_MARKER => null,
OssClient::OSS_VERSION_ID_MARKER => null,
OssClient::OSS_DELIMITER => "/",
);
$bool = true;
while ($bool) {
$result = $ossClient->listObjectVersions($bucket, $option);
## View the version information of the listed object.
foreach ($result->getObjectVersionList() as $key => $info) {
Common::println("key name: " . $info->getKey());
Common::println("versionid: " . $info->getVersionId());
Common::println("Is latest: " . $info->getIsLatest());
}
## View the version information that lists the deletion flags.
foreach ($result->getDeleteMarkerList() as $key => $info) {
Common::println("del_maker key name: " . $info->getKey());
Common::println("del_maker versionid: " . $info->getVersionId());
Common::println("del_maker Is latest: " . $info->getIsLatest());
}
if ($result->getIsTruncated() === 'true') {
$option[OssClient::OSS_KEY_MARKER] = $result->getNextKeyMarker();
$option[OssClient::OSS_VERSION_ID_MARKER] = $result->getNextVersionIdMarker();
} else {
$bool = false;
}
}
// Show subfolder objects list
$option = array(
OssClient::OSS_KEY_MARKER => null,
OssClient::OSS_VERSION_ID_MARKER => null,
OssClient::OSS_DELIMITER => "/",
OssClient::OSS_PREFIX => "test/",
);
$bool = true;
while ($bool) {
$result = $ossClient->listObjectVersions($bucket, $option);
## View the version information of the listed object.
foreach ($result->getObjectVersionList() as $key => $info) {
Common::println("key name: " . $info->getKey());
Common::println("versionid: " . $info->getVersionId());
Common::println("Is latest: " . $info->getIsLatest());
}
## View the version information that lists the deletion flags.
foreach ($result->getDeleteMarkerList() as $key => $info) {
Common::println("del_maker key name: " . $info->getKey());
Common::println("del_maker versionid: " . $info->getVersionId());
Common::println("del_maker Is latest: " . $info->getIsLatest());
}
if ($result->getIsTruncated() === 'true') {
$option[OssClient::OSS_KEY_MARKER] = $result->getNextKeyMarker();
$option[OssClient::OSS_VERSION_ID_MARKER] = $result->getNextVersionIdMarker();
} else {
$bool = false;
}
}
//******************************* For complete usage, see the following functions ****************************************************
listObjectVersions($ossClient, $bucket);
putBucketVersioning($ossClient, $bucket);
/**
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function listObjectVersions($ossClient, $bucket)
{
try {
$option = array(
OssClient::OSS_KEY_MARKER => null,
OssClient::OSS_VERSION_ID_MARKER => null,
);
$bool = true;
while ($bool) {
$result = $ossClient->listObjectVersions($bucket, $option);
## View the version information of the listed object.
foreach ($result->getObjectVersionList() as $key => $info) {
Common::println("key name: " . $info->getKey());
Common::println("versionid: " . $info->getVersionId());
Common::println("Is latest: " . $info->getIsLatest());
}
## View the version information that lists the deletion flags.
foreach ($result->getDeleteMarkerList() as $key => $info) {
Common::println("del_maker key name: " . $info->getKey());
Common::println("del_maker versionid: " . $info->getVersionId());
Common::println("del_maker Is latest: " . $info->getIsLatest());
}
if ($result->getIsTruncated() === 'true') {
$option[OssClient::OSS_KEY_MARKER] = $result->getNextKeyMarker();
$option[OssClient::OSS_VERSION_ID_MARKER] = $result->getNextVersionIdMarker();
} else {
$bool = false;
}
}
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Enabled or Suspended bucket version
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function putBucketVersioning($ossClient, $bucket)
{
try {
//Set the storage space version control to enable version control (Enabled) or suspend version control (Suspended).
$ossClient->putBucketVersioning($bucket, "Enabled");
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
\ No newline at end of file
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
$ossClient = Common::getOssClient();
if (is_null($ossClient)) exit(1);
$bucket = Common::getBucketName();
//******************************* Simple Usage****************************************************************
// Create a new compliance retention policy:
// The specified object protection days are 30 days.
$wormId = $ossClient->initiateBucketWorm($bucket, 30);
Common::println("bucket $bucket wormId: " . $wormId.PHP_EOL);
// Cancel an unlocked compliance retention policy
$ossClient->abortBucketWorm($bucket);
//Lock compliant retention policy
$wormId = $ossClient->initiateBucketWorm($bucket, 30);
$ossClient->completeBucketWorm($bucket, $wormId);
// Get compliant retention policy
$config = $ossClient->getBucketWorm($bucket);
Common::println("WormId:".$config->getWormId().PHP_EOL);
Common::println("State:". $config->getState().PHP_EOL);
Common::println("Day:". $config->getDay().PHP_EOL);
// Extend the retention days of objects
$wormId = "<yourWormId>";
// Extend the retention days of objects in the locked compliance retention policy to 120 days.
$ossClient->extendBucketWorm($bucket, $wormId, 120);
//******************************* For complete usage, see the following functions ****************************************************
initiateBucketWorm($ossClient, $bucket);
abortBucketWorm($ossClient, $bucket);
completeBucketWorm($ossClient, $bucket);
getBucketWorm($ossClient, $bucket);
extendBucketWorm($ossClient, $bucket);
/**
* Set Bucket Worm Ploicy
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function initiateBucketWorm($ossClient, $bucket)
{
try {
$wormId = $ossClient->initiateBucketWorm($bucket,30);
print("bucket $bucket wormId: " . $wormId.PHP_EOL);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Cancel an unlocked compliance retention policy
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket Name of the bucket to create
* @return null
*/
function abortBucketWorm($ossClient, $bucket)
{
try {
$ossClient->abortBucketWorm($bucket);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Complete Bucket Worm
* @param $ossClient $ossClient OssClient instance
* @param $bucket $bucket Name of the bucket to create
*/
function completeBucketWorm($ossClient, $bucket)
{
try {
$wormId = $ossClient->initiateBucketWorm($bucket, 30);
$ossClient->completeBucketWorm($bucket, $wormId);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Get Bucket Worm
* @param $ossClient $ossClient OssClient instance
* @param $bucket $bucket Name of the bucket to create
*/
function getBucketWorm($ossClient, $bucket)
{
try {
$config = $ossClient->getBucketWorm($bucket);
printf("WormId:%s\n", $config->getWormId());
printf("State:%s\n", $config->getState());
printf("Day:%d\n", $config->getDay());
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Extend the retention days of objects
* @param $ossClient $ossClient OssClient instance
* @param $bucket $bucket Name of the bucket to create
*/
function extendBucketWorm($ossClient, $bucket)
{
$wormId = "<yourWormId>";
try {
$ossClient->ExtendBucketWorm($bucket, $wormId, 120);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
\ No newline at end of file
<?php
//=============================================================================
//How to use credentials-php to access oss
// step 1:Install credentials-php composer require alibabacloud/credentials
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Credentials\CredentialsProvider;
use AlibabaCloud\Credentials\Credential;
use OSS\Credentials\StaticCredentialsProvider;
// public provider conversion class
class AlibabaCloudCredentialsWrapper implements CredentialsProvider{
/**
* @var Credential
*/
private $warpper;
public function __construct($credential){
$this->warpper = $credential;
}
public function getCredentials(){
$ak = $this->warpper->getAccessKeyId();
$sk = $this->warpper->getAccessKeySecret();
$token = $this->warpper->getSecurityToken();
return new StaticCredentialsProvider($ak, $sk, $token);
}
}
$bucket = Common::getBucketName();
//AccessKey Credentials demo
$credential = new Credential(array(
'type' => 'access_key',
'access_key_id' => '<access_key_id>',
'access_key_secret' => '<accessKey_secret>',
));
$providerWarpper = new AlibabaCloudCredentialsWrapper($credential);
$config = array(
'provider' => $providerWarpper,
'endpoint'=> '<endpoint>'
);
try {
$ossClient = new OssClient($config);
$ossClient->putObject($bucket,'c.file','hi oss,this is credentials test of access key');
$result = $ossClient->getObject($bucket,'c.file');
var_dump($result);
} catch (OssException $e) {
printf($e->getMessage() . "\n");
return;
}
// EcsRamRole Credentials demo
$ecsRamRole = new Credential(array(
'type' => 'ecs_ram_role',
'role_name' => 'EcsRamRoleOssTest',
));
$providerWarpper = new AlibabaCloudCredentialsWrapper($ecsRamRole);
$bucket = 'oss-bucket-cd-yp-test';
$config = array(
'provider' => $providerWarpper,
'endpoint'=> '<endpoint>'
);
try {
$ossClient = new OssClient($config);
$ossClient->putObject($bucket,'c.file','hi oss,this is credentials test of EcsRamRole');
$result = $ossClient->getObject($bucket,'c.file');
var_dump($result);
} catch (OssException $e) {
printf($e->getMessage() . "\n");
return;
}
<?php
require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Credentials\StaticCredentialsProvider;
$bucket = Common::getBucketName();
// Access Key Provider demo
$id = '<access_key_id>';
$secret = '<accessKey_secret>';
$provider = new StaticCredentialsProvider($id,$secret);
$config = array(
'provider' => $provider,
'endpoint'=>'<endpoint>'
);
try {
$ossClient = new OssClient($config);
$ossClient->putObject($bucket,'c.file','hi oss,this is credentials test of access key provider');
$result = $ossClient->getObject($bucket,'c.file');
var_dump($result);
} catch (OssException $e) {
printf($e->getMessage() . "\n");
return;
}
// Sts provider demo
$id = '<access_key_id>';
$secret = '<accessKey_secret>';
$token = '<security_token>';
$provider = new StaticCredentialsProvider($id,$secret,$token);
$config = array(
'provider' => $provider,
'endpoint'=> "<endpoint>"
);
try {
$ossClient = new OssClient($config);
$ossClient->putObject($bucket,'c.file','hi oss,this is credentials test of sts provider');
$result = $ossClient->getObject($bucket,'c.file');
var_dump($result);
} catch (OssException $e) {
printf($e->getMessage() . "\n");
return;
}
......@@ -3,6 +3,7 @@ require_once __DIR__ . '/Common.php';
use OSS\OssClient;
use OSS\Core\OssException;
use OSS\Model\RestoreConfig;
$bucket = Common::getBucketName();
$ossClient = Common::getOssClient();
......@@ -48,6 +49,17 @@ $ossClient->getObject($bucket, "c.file", $options);
Common::println("b.file is fetched to the local file: c.file.localcopy");
Common::println("b.file is created");
// Restore Object
$day = 3;
$tier = 'Expedited';
$config = new RestoreConfig($day,$tier);
$options = array(
OssClient::OSS_RESTORE_CONFIG => $config
);
$ossClient->restoreObject($bucket, 'b.file',$options);
// Copy an object
$result = $ossClient->copyObject($bucket, "c.file", $bucket, "c.file.copy");
Common::println("lastModifiedTime: " . $result[0]);
......@@ -75,9 +87,37 @@ foreach($result as $object)
sleep(2);
unlink("c.file.localcopy");
// Normal upload and download speed limit
$object= "b.file";
$content = "hello world";
// The speed limit is 100 KB/s, which is 819200 bit/s.
$options = array(
OssClient::OSS_HEADERS => array(
OssClient::OSS_TRAFFIC_LIMIT => 819200,
));
// Speed limit upload.
$ossClient->putObject($bucket, $object, $content, $options);
// Speed limit download.
$ossClient->getObject($bucket, $object, $options);
// Signed URL upload and download speed limit
// Create a URL for uploading with a limited rate, and the validity period is 60s.
$timeout = 60;
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT", $options);
Common::println("b.file speed limit upload url:".$signedUrl.PHP_EOL);
// Create a URL for speed-limited downloads, with a validity period of 120s.
$timeout = 120;
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET", $options);
Common::println("b.file speed limit download url:".$signedUrl.PHP_EOL);
//******************************* For complete usage, see the following functions ****************************************************
listObjects($ossClient, $bucket);
listObjectsV2($ossClient, $bucket);
listAllObjects($ossClient, $bucket);
createObjectDir($ossClient, $bucket);
putObject($ossClient, $bucket);
......@@ -92,6 +132,11 @@ deleteObjects($ossClient, $bucket);
doesObjectExist($ossClient, $bucket);
getSymlink($ossClient, $bucket);
putSymlink($ossClient, $bucket);
putObjectSpeed($ossClient, $bucket);
getObjectSpeed($ossClient, $bucket);
signUrlSpeedUpload($ossClient, $bucket);
signUrlSpeedDownload($ossClient, $bucket);
restoreObject($ossClient,$bucket);
/**
* Create a 'virtual' folder
*
......@@ -194,6 +239,10 @@ function listObjects($ossClient, $bucket)
print("objectList:\n");
foreach ($objectList as $objectInfo) {
print($objectInfo->getKey() . "\n");
if($objectInfo->getOwner() != null){
printf("owner id:".$objectInfo->getOwner()->getId() . "\n");
printf("owner name:".$objectInfo->getOwner()->getDisplayName() . "\n");
}
}
}
if (!empty($prefixList)) {
......@@ -204,6 +253,55 @@ function listObjects($ossClient, $bucket)
}
}
/**
* Lists all files and folders in the bucket.
* Note if there's more items than the max-keys specified, the caller needs to use the nextMarker returned as the value for the next call's maker paramter.
* Loop through all the items returned from ListObjects.
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function listObjectsV2($ossClient, $bucket)
{
$prefix = 'oss-php-sdk-test/';
$delimiter = '/';
$maxkeys = 1000;
$options = array(
'delimiter' => $delimiter,
'prefix' => $prefix,
'max-keys' => $maxkeys,
'start-after' =>'test-object',
'fetch-owner' =>'true',
);
try {
$listObjectInfo = $ossClient->listObjectsV2($bucket, $options);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
$objectList = $listObjectInfo->getObjectList(); // object list
$prefixList = $listObjectInfo->getPrefixList(); // directory list
if (!empty($objectList)) {
print("objectList:\n");
foreach ($objectList as $objectInfo) {
print($objectInfo->getKey() . "\n");
if($objectInfo->getOwner() != null){
printf("owner id:".$objectInfo->getOwner()->getId() . "\n");
printf("owner name:".$objectInfo->getOwner()->getDisplayName() . "\n");
}
}
}
if (!empty($prefixList)) {
print("prefixList: \n");
foreach ($prefixList as $prefixInfo) {
print($prefixInfo->getPrefix() . "\n");
}
}
}
/**
* Lists all folders and files under the bucket. Use nextMarker repeatedly to get all objects.
*
......@@ -516,3 +614,116 @@ function doesObjectExist($ossClient, $bucket)
var_dump($exist);
}
/**
* Speed limit upload.
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function putObjectSpeed($ossClient, $bucket)
{
$object = "upload-test-object-name.txt";
$content = file_get_contents(__FILE__);
$options = array(
OssClient::OSS_HEADERS => array(
OssClient::OSS_TRAFFIC_LIMIT => 819200,
));
try {
$ossClient->putObject($bucket, $object, $content, $options);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Speed limit download.
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function getObjectSpeed($ossClient, $bucket)
{
$object = "upload-test-object-name.txt";
$options = array(
OssClient::OSS_HEADERS => array(
OssClient::OSS_TRAFFIC_LIMIT => 819200,
));
try {
$ossClient->getObject($bucket, $object, $options);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Speed limit download.
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function signUrlSpeedUpload($ossClient, $bucket)
{
$object = "upload-test-object-name.txt";
$timeout = 120;
$options = array(
OssClient::OSS_TRAFFIC_LIMIT => 819200,
);
$timeout = 60;
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT", $options);
print($signedUrl);
}
/**
* Speed limit download.
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function signUrlSpeedDownload($ossClient, $bucket)
{
$object = "upload-test-object-name.txt";
$timeout = 120;
$options = array(
OssClient::OSS_TRAFFIC_LIMIT => 819200,
);
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET", $options);
print($signedUrl);
print(__FUNCTION__ . ": OK" . "\n");
}
/**
* Restore object
*
* @param OssClient $ossClient OssClient instance
* @param string $bucket bucket name
* @return null
*/
function restoreObject($ossClient, $bucket)
{
$object = "oss-php-sdk-test/upload-test-object-name.txt";
$day = 3;
$tier = 'Expedited';
$config = new RestoreConfig($day,$tier);
$options = array(
OssClient::OSS_RESTORE_CONFIG => $config
);
try {
$ossClient->restoreObject($bucket, $object,$options);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
print(__FUNCTION__ . ": OK" . "\n");
}
This diff is collapsed.
......@@ -31,7 +31,11 @@ class OssUtil
uksort($options, 'strnatcasecmp');
foreach ($options as $key => $value) {
if (is_string($key) && !is_array($value)) {
$temp[] = rawurlencode($key) . '=' . rawurlencode($value);
if (strlen($value) > 0) {
$temp[] = rawurlencode($key) . '=' . rawurlencode($value);
} else {
$temp[] = rawurlencode($key);
}
}
}
return implode('&', $temp);
......
<?php
namespace OSS\Credentials;
use OSS\Core\OssException;
/**
* Basic implementation of the OSS Credentials that allows callers to
* pass in the OSS Access Key and OSS Secret Access Key in the constructor.
*/
class Credentials
{
private $key;
private $secret;
private $token;
/**
* Constructor a new BasicOSSCredentials object, with the specified OSS
* access key and OSS secret key
*
* @param string $key OSS access key ID
* @param string $secret OSS secret access key
* @param string $token Security token to use
*/
public function __construct($key, $secret, $token = null)
{
if (empty($key)) {
throw new OssException("access key id is empty");
}
if (empty($secret)) {
throw new OssException("access key secret is empty");
}
$this->key = trim($key);
$this->secret = trim($secret);
$this->token = $token;
}
/**
* @return string
*/
public function getAccessKeyId()
{
return $this->key;
}
/**
* @return string
*/
public function getAccessKeySecret()
{
return $this->secret;
}
/**
* @return string|null
*/
public function getSecurityToken()
{
return $this->token;
}
}
<?php
namespace OSS\Credentials;
interface CredentialsProvider
{
/**
* @return Credentials
*/
public function getCredentials();
}
\ No newline at end of file
<?php
namespace OSS\Credentials;
/**
* Basic implementation of the OSS Credentials interface that allows callers to
* pass in the OSS Access Key Id and OSS Secret Access Key in the constructor.
*/
class StaticCredentialsProvider implements CredentialsProvider
{
/**
* @var Credentials
*/
private $credentials;
/**
* Constructs a new StaticCredentialsProvider object, with the specified OSS
* access key and OSS secret key
*
* @param string $key OSS access key ID
* @param string $secret OSS access key secret
* @param string $token Security token to use
*/
public function __construct($key, $secret, $token = null)
{
$this->credentials = new Credentials($key, $secret, $token);
}
/**
* @return Credentials
*/
public function getCredentials()
{
return $this->credentials;
}
}
......@@ -789,7 +789,7 @@ class RequestCore
}
// As long as this came back as a valid resource or CurlHandle instance...
if (is_resource($curl_handle) || (is_object($curl_handle) && get_class($curl_handle) === 'CurlHandle')) {
if (is_resource($curl_handle) || (is_object($curl_handle) && in_array(get_class($curl_handle),array('CurlHandle','Swoole\Curl\Handler', 'Swoole\Coroutine\Curl\Handle'),true))) {
// Determine what's what.
$header_size = curl_getinfo($curl_handle, CURLINFO_HEADER_SIZE);
$this->response_headers = substr($this->response, 0, $header_size);
......
......@@ -41,6 +41,135 @@ class BucketStat
return $this->multipartUploadCount;
}
/**
* Get live channel count
*
* @return int
*/
public function getLiveChannelCount()
{
return $this->liveChannelCount;
}
/**
* Get last modified time
*
* @return int
*/
public function getLastModifiedTime()
{
return $this->lastModifiedTime;
}
/**
* Get standard storage
*
* @return int
*/
public function getStandardStorage()
{
return $this->standardStorage;
}
/**
* Get standard object count
*
* @return int
*/
public function getStandardObjectCount()
{
return $this->standardObjectCount;
}
/**
* Get infrequent access storage
*
* @return int
*/
public function getInfrequentAccessStorage()
{
return $this->infrequentAccessStorage;
}
/**
* Get infrequent access real storage
*
* @return int
*/
public function getInfrequentAccessRealStorage()
{
return $this->infrequentAccessRealStorage;
}
/**
* Get infrequent access object count
*
* @return int
*/
public function getInfrequentAccessObjectCount()
{
return $this->infrequentAccessObjectCount;
}
/**
* Get archive storage
*
* @return int
*/
public function getArchiveStorage()
{
return $this->archiveStorage;
}
/**
* Get archive real storage
*
* @return int
*/
public function getArchiveRealStorage()
{
return $this->archiveRealStorage;
}
/**
* Get archive object count
*
* @return int
*/
public function getArchiveObjectCount()
{
return $this->archiveObjectCount;
}
/**
* Get cold archive storage
*
* @return int
*/
public function getColdArchiveStorage()
{
return $this->coldArchiveStorage;
}
/**
* Get cold archive real storage
*
* @return int
*/
public function getColdArchiveRealStorage()
{
return $this->coldArchiveRealStorage;
}
/**
* Get cold archive object count
*
* @return int
*/
public function getColdArchiveObjectCount()
{
return $this->coldArchiveObjectCount;
}
/**
* Parse stat from the xml.
*
......@@ -60,6 +189,45 @@ class BucketStat
if (isset($xml->MultipartUploadCount) ) {
$this->multipartUploadCount = intval($xml->MultipartUploadCount);
}
if (isset($xml->LiveChannelCount) ) {
$this->liveChannelCount = intval($xml->LiveChannelCount);
}
if (isset($xml->LastModifiedTime) ) {
$this->lastModifiedTime = intval($xml->LastModifiedTime);
}
if (isset($xml->StandardStorage) ) {
$this->standardStorage = intval($xml->StandardStorage);
}
if (isset($xml->StandardObjectCount) ) {
$this->standardObjectCount = intval($xml->StandardObjectCount);
}
if (isset($xml->InfrequentAccessStorage) ) {
$this->infrequentAccessStorage = intval($xml->InfrequentAccessStorage);
}
if (isset($xml->InfrequentAccessRealStorage) ) {
$this->infrequentAccessRealStorage = intval($xml->InfrequentAccessRealStorage);
}
if (isset($xml->InfrequentAccessObjectCount) ) {
$this->infrequentAccessObjectCount = intval($xml->InfrequentAccessObjectCount);
}
if (isset($xml->ArchiveStorage) ) {
$this->archiveStorage = intval($xml->ArchiveStorage);
}
if (isset($xml->ArchiveRealStorage) ) {
$this->archiveRealStorage = intval($xml->ArchiveRealStorage);
}
if (isset($xml->ArchiveObjectCount) ) {
$this->archiveObjectCount = intval($xml->ArchiveObjectCount);
}
if (isset($xml->ColdArchiveStorage) ) {
$this->coldArchiveStorage = intval($xml->ColdArchiveStorage);
}
if (isset($xml->ColdArchiveRealStorage) ) {
$this->coldArchiveRealStorage = intval($xml->ColdArchiveRealStorage);
}
if (isset($xml->ColdArchiveObjectCount) ) {
$this->coldArchiveObjectCount = intval($xml->ColdArchiveObjectCount);
}
}
/**
......@@ -82,4 +250,82 @@ class BucketStat
*/
private $multipartUploadCount;
/**
* live channel count
* @var int
*/
private $liveChannelCount;
/**
* last modified time
* @var int
*/
private $lastModifiedTime;
/**
* standard storage
* @var int
*/
private $standardStorage;
/**
* standard object count
* @var int
*/
private $standardObjectCount;
/**
* infrequent access storage
* @var int
*/
private $infrequentAccessStorage;
/**
* infrequent access real storage
* @var int
*/
private $infrequentAccessRealStorage;
/**
* infrequent access object Count
* @var int
*/
private $infrequentAccessObjectCount;
/**
* archive storage
* @var int
*/
private $archiveStorage;
/**
* archive real storage
* @var int
*/
private $archiveRealStorage;
/**
* archive object count
* @var int
*/
private $archiveObjectCount;
/**
* cold archive storage
* @var int
*/
private $coldArchiveStorage;
/**
* cold archive real storage
* @var int
*/
private $coldArchiveRealStorage;
/**
* cold archive object count
* @var int
*/
private $coldArchiveObjectCount;
}
\ No newline at end of file
<?php
namespace OSS\Model;
/**
* Cname token info class.
*
* Class CnameTokenInfo
* @package OSS\Model
*/
class CnameTokenInfo
{
/**
* Get bucket name
*
* @return string
*/
public function getBucket()
{
return $this->bucket;
}
/**
* Get cname
*
* @return string
*/
public function getCname()
{
return $this->cname;
}
/**
* Get token.
*
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* Get expireTime.
*
* @return string
*/
public function getExpireTime()
{
return $this->expireTime;
}
/**
* Parse cname token from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);
if (isset($xml->Bucket) ) {
$this->bucket = strval($xml->Bucket);
}
if (isset($xml->Cname) ) {
$this->cname = strval($xml->Cname);
}
if (isset($xml->Token) ) {
$this->token = strval($xml->Token);
}
if (isset($xml->ExpireTime) ) {
$this->expireTime = strval($xml->ExpireTime);
}
}
/**
* bucket name
*
* @var string
*/
private $bucket;
/**
* cname
*
* @var string
*/
private $cname;
/**
* token
*
* @var string
*/
private $token;
/**
* expire time
*
* @var string
*/
private $expireTime;
}
\ No newline at end of file
<?php
namespace OSS\Model;
/**
*
* Class ObjectInfo
......@@ -67,25 +66,25 @@ class ObjectInfo
{
return $this->type;
}
/**
* php7 && 64bit can use it
* @return int
*/
public function getSize()
{
return (int)$this->size;
}
/**
* php5.x or 32bit must use it
* @return string
*/
public function getSizeStr()
{
return $this->size;
}
/**
* php7 && 64bit can use it
* @return int
*/
public function getSize()
{
return (int)$this->size;
}
/**
* php5.x or 32bit must use it
* @return string
*/
public function getSizeStr()
{
return $this->size;
}
/**
* @return string
......
<?php
namespace OSS\Model;
/**
* Class ObjectListInfoV2
*
* The class of return value of ListObjectsV2
*
* @package OSS\Model
*/
class ObjectListInfoV2
{
/**
* ObjectListInfoV2 constructor.
*
* @param string $bucketName
* @param string $prefix
* @param int $maxKeys
* @param string $delimiter
* @param null $isTruncated
* @param array $objectList
* @param array $prefixList
* @param string $continuationToken
* @param string $nextContinuationToken
* @param string $startAfter
* @param int $keyCount
*/
public function __construct($bucketName, $prefix, $maxKeys, $delimiter, $isTruncated, array $objectList, array $prefixList, $continuationToken, $nextContinuationToken, $startAfter, $keyCount)
{
$this->bucketName = $bucketName;
$this->prefix = $prefix;
$this->maxKeys = $maxKeys;
$this->delimiter = $delimiter;
$this->isTruncated = $isTruncated;
$this->objectList = $objectList;
$this->prefixList = $prefixList;
$this->continuationToken = $continuationToken;
$this->nextContinuationToken = $nextContinuationToken;
$this->startAfter = $startAfter;
$this->keyCount = $keyCount;
}
/**
* @return string
*/
public function getBucketName()
{
return $this->bucketName;
}
/**
* @return string
*/
public function getPrefix()
{
return $this->prefix;
}
/**
* @return int
*/
public function getMaxKeys()
{
return $this->maxKeys;
}
/**
* @return string
*/
public function getDelimiter()
{
return $this->delimiter;
}
/**
* @return mixed
*/
public function getIsTruncated()
{
return $this->isTruncated;
}
/**
* Get the ObjectInfo list.
*
* @return ObjectInfo[]
*/
public function getObjectList()
{
return $this->objectList;
}
/**
* Get the PrefixInfo list
*
* @return PrefixInfo[]
*/
public function getPrefixList()
{
return $this->prefixList;
}
/**
* @return string
*/
public function getContinuationToken()
{
return $this->continuationToken;
}
/**
* @return string
*/
public function getNextContinuationToken()
{
return $this->nextContinuationToken;
}
/**
* @return string
*/
public function getStartAfter()
{
return $this->startAfter;
}
/**
* @return int
*/
public function getKeyCount()
{
return $this->keyCount;
}
private $bucketName = "";
private $prefix = "";
private $maxKeys = 0;
private $delimiter = "";
private $isTruncated = null;
private $objectList = array();
private $prefixList = array();
private $nextContinuationToken = "";
private $continuationToken = "";
private $startAfter = "";
private $keyCount = 0;
}
\ No newline at end of file
<?php
namespace OSS\Result;
use OSS\Model\CnameTokenInfo;
class CreateBucketCnameTokenResult extends Result
{
/**
* @return CnameConfig
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
$info = new CnameTokenInfo();
$info->parseFromXml($content);
return $info;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment