|
| 1 | +<?php |
| 2 | + |
| 3 | +require_once __DIR__ . '/Common.php'; |
| 4 | + |
| 5 | +use OSS\OssClient; |
| 6 | +use OSS\Core\OssException; |
| 7 | + |
| 8 | +$ossClient = Common::getOssClient(); |
| 9 | +if (is_null($ossClient)) exit(1); |
| 10 | +$bucket = Common::getBucketName(); |
| 11 | + |
| 12 | +//******************************* Simple Usage**************************************************************** |
| 13 | + |
| 14 | +// put access monitor |
| 15 | +$status = 'Enabled'; |
| 16 | +$ossClient->putBucketAccessMonitor($bucket, $status); |
| 17 | +printf('Put Bucket Access Monitor Success' . "\n"); |
| 18 | + |
| 19 | + |
| 20 | +// get access monitor |
| 21 | +$status = $ossClient->getBucketAccessMonitor($bucket); |
| 22 | +printf('Get Bucket Access Monitor Status:%s'."\n",$status); |
| 23 | + |
| 24 | + |
| 25 | +//******************************* For complete usage, see the following functions **************************************************** |
| 26 | +putBucketAccessMonitor($ossClient,$bucket); |
| 27 | +getBucketAccessMonitor($ossClient,$bucket); |
| 28 | + |
| 29 | +/** |
| 30 | + * Put Bucket Access Monitor |
| 31 | + * @param $ossClient OssClient |
| 32 | + * @param string $bucket bucket_name string |
| 33 | + */ |
| 34 | +function putBucketAccessMonitor($ossClient, $bucket) |
| 35 | +{ |
| 36 | + try{ |
| 37 | + $status = 'Enabled'; // set Enabled to enable access monitor; set Disabled to disable access monitor |
| 38 | + $ossClient->putBucketAccessMonitor($bucket,$status); |
| 39 | + printf('Put Bucket Access Monitor Success' . "\n"); |
| 40 | + } catch(OssException $e) { |
| 41 | + printf($e->getMessage() . "\n"); |
| 42 | + return; |
| 43 | + } |
| 44 | + print(__FUNCTION__ . ": OK" . "\n"); |
| 45 | +} |
| 46 | + |
| 47 | +/** |
| 48 | + * Get Bucket Access Monitor |
| 49 | + * @param $ossClient OssClient |
| 50 | + * @param string $bucket bucket_name |
| 51 | + */ |
| 52 | +function getBucketAccessMonitor($ossClient, $bucket) |
| 53 | +{ |
| 54 | + try{ |
| 55 | + $status = $ossClient->getBucketAccessMonitor($bucket); |
| 56 | + printf('Get Bucket Access Monitor Status:%s'."\n",$status); |
| 57 | + } catch(OssException $e) { |
| 58 | + printf($e->getMessage() . "\n"); |
| 59 | + return; |
| 60 | + } |
| 61 | + print(__FUNCTION__ . ": OK" . "\n"); |
| 62 | +} |
0 commit comments