/** * 获取bucket下的object列表 * * @param string $bucket * @param array $options * 其中options中的参数如下 * $options = array( * 'max-keys' => max-keys用于限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于1000。 * 'prefix' => 限定返回的object key必须以prefix作为前缀。注意使用prefix查询时,返回的key中仍会包含prefix。 * 'delimiter' => 是一个用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素 * 'marker' => 用户设定结果从marker之后按字母排序的第一个开始返回。 * ) * 其中 prefix,marker用来实现分页显示效果,参数的长度必须小于256字节。 * * @throws Exception * @return ObjectListInfo */ public function listObjects($bucket, $options = null) { $this->precheckCommon($bucket, null, $options, false); $options[self::OSS_BUCKET] = $bucket; $options[self::OSS_METHOD] = self::OSS_HTTP_GET; $options[self::OSS_OBJECT] = '/'; $options[self::OSS_HEADERS] = array(self::OSS_DELIMITER => isset($options[self::OSS_DELIMITER]) ? $options[self::OSS_DELIMITER] : '/', self::OSS_PREFIX => isset($options[self::OSS_PREFIX]) ? $options[self::OSS_PREFIX] : '', self::OSS_MAX_KEYS => isset($options[self::OSS_MAX_KEYS]) ? $options[self::OSS_MAX_KEYS] : self::OSS_MAX_KEYS_VALUE, self::OSS_MARKER => isset($options[self::OSS_MARKER]) ? $options[self::OSS_MARKER] : ''); $query = isset($options[self::OSS_QUERY_STRING]) ? $options[self::OSS_QUERY_STRING] : array(); $options[self::OSS_QUERY_STRING] = array_merge($query, array(self::OSS_ENCODING_TYPE => self::OSS_ENCODING_TYPE_URL)); $response = $this->auth($options); $result = new ListObjectsResult($response); return $result->getData(); }
public function testParseValidXmlWithEncodedKey() { $response = new ResponseCore(array(), $this->validXmlWithEncodedKey, 200); $result = new ListObjectsResult($response); $this->assertTrue($result->isOK()); $this->assertNotNull($result->getData()); $this->assertNotNull($result->getRawResponse()); $objectListInfo = $result->getData(); $this->assertEquals(0, count($objectListInfo->getPrefixList())); $this->assertEquals(1, count($objectListInfo->getObjectList())); $this->assertEquals('testbucket-hf', $objectListInfo->getBucketName()); $this->assertEquals('php/prefix', $objectListInfo->getPrefix()); $this->assertEquals('php/marker', $objectListInfo->getMarker()); $this->assertEquals('php/next-marker', $objectListInfo->getNextMarker()); $this->assertEquals(1000, $objectListInfo->getMaxKeys()); $this->assertEquals('/', $objectListInfo->getDelimiter()); $this->assertEquals('true', $objectListInfo->getIsTruncated()); $this->assertEquals('php/a+b', $objectListInfo->getObjectList()[0]->getKey()); $this->assertEquals('2015-11-18T03:36:00.000Z', $objectListInfo->getObjectList()[0]->getLastModified()); $this->assertEquals('"89B9E567E7EB8815F2F7D41851F9A2CD"', $objectListInfo->getObjectList()[0]->getETag()); $this->assertEquals('Normal', $objectListInfo->getObjectList()[0]->getType()); $this->assertEquals(13115, $objectListInfo->getObjectList()[0]->getSize()); $this->assertEquals('Standard', $objectListInfo->getObjectList()[0]->getStorageClass()); }