diff --git a/samples/BucketMetaQuery.php b/samples/BucketMetaQuery.php
new file mode 100644
index 0000000..2365ea6
--- /dev/null
+++ b/samples/BucketMetaQuery.php
@@ -0,0 +1,238 @@
+openMetaQuery($bucket);
+Common::println("bucket $bucket open meta query success".PHP_EOL);
+
+// Get Meta Query Status
+$rs = $ossClient->getMetaQueryStatus($bucket);
+Common::println("bucket $bucket meta query status state:".$rs->getState().PHP_EOL);
+Common::println("bucket $bucket meta query status phase:".$rs->getPhase().PHP_EOL);
+Common::println("bucket $bucket meta query status create time:".$rs->getCreateTime().PHP_EOL);
+Common::println("bucket $bucket meta query status update time:".$rs->getUpdateTime().PHP_EOL);
+
+// Do meta query
+// Query files larger than 500
+$query = '{"Field": "Size","Value": "500","Operation": "gt"}';
+$maxResults=100;
+$sort="Size";
+$order="asc";
+$metaQuery = new MetaQuery();
+$metaQuery->setQuery($query);
+$metaQuery->setMaxResults($maxResults);
+$metaQuery->setSort($sort);
+$metaQuery->setOrder($order);
+//Add aggregation condition
+$agg = new MetaQueryAggregation();
+$agg->setField("Size");
+$agg->setOperation("sum");
+$aggOne = new MetaQueryAggregation();
+$aggOne->setField("Size");
+$aggOne->setOperation("count");
+$metaQuery->addAggregation($agg);
+$metaQuery->addAggregation($aggOne);
+
+$rs = $ossClient->doMetaQuery($bucket,$metaQuery);
+if ($rs->getNextToken() != ""){
+ printf("Next Token:".$rs->getNextToken().PHP_EOL);
+}
+if ($rs->getFiles() != null){
+ foreach ($rs->getFiles() as $file ){
+ printf("File info ===============".$file->getFileName()."============================== start ".PHP_EOL);
+ printf("File Name:".$file->getFileName().PHP_EOL);
+ printf("File Size:".$file->getSize().PHP_EOL);
+ printf("File Modified Time:".$file->getFileModifiedTime().PHP_EOL);
+ printf("File Oss Object Type:".$file->getOssObjectType().PHP_EOL);
+ printf("File Oss Storage Class:".$file->getOssStorageClass().PHP_EOL);
+ printf("File Object Acl:".$file->getObjectAcl().PHP_EOL);
+ printf("File ETag:".$file->getETag().PHP_EOL);
+ printf("File Oss Crc64:".$file->getOssCrc64().PHP_EOL);
+ printf("File Oss Tagging Count:".$file->getOssTaggingCount().PHP_EOL);
+ printf("File Server Side Encryption:".$file->getServerSideEncryption().PHP_EOL);
+ printf("File Server Side Encryption Customer Algorithm:".$file->getServerSideEncryptionCustomerAlgorithm().PHP_EOL);
+ if ($file->getOssUserMeta() != null){
+ foreach ($file->getOssUserMeta() as $ossUserMeta ){
+ printf("File OSS User Meta Key:".$ossUserMeta->getKey().PHP_EOL);
+ printf("File OSS User Meta Value:".$ossUserMeta->getValue().PHP_EOL);
+ }
+ }
+ if ($file->getOssTagging() != null){
+ foreach ($file->getOssTagging() as $ossTagging ){
+ printf("File OSS Tagging Key:".$ossTagging->getKey().PHP_EOL);
+ printf("File OSS Tagging Value:".$ossTagging->getValue().PHP_EOL);
+ }
+ }
+ }
+}
+if ($rs->getAggregations() != null){
+ foreach ($rs->getAggregations() as $aggregation){
+ printf("Aggregation Field:".$aggregation->getField().PHP_EOL);
+ printf("Aggregation Operation:".$aggregation->getOperation().PHP_EOL);
+ printf("Aggregation Value:".$aggregation->getValue().PHP_EOL);
+ if ($aggregation->getGroups() != null){
+ foreach ($aggregation->getGroups() as $group ){
+ printf("Aggregation Group Value:".$group->getValue().PHP_EOL);
+ printf("Aggregation Group Count:".$group->getCount().PHP_EOL);
+ }
+ }
+ }
+}
+
+// Close Meta Query
+$ossClient->closeMetaQuery($bucket);
+Common::println("bucket $bucket has closed meta query".PHP_EOL);
+
+//******************************* For complete usage, see the following functions ****************************************************
+openMetaQuery($ossClient,$bucket);
+getMetaQueryStatus($ossClient,$bucket);
+doMetaQuery($ossClient,$bucket);
+closeMetaQuery($ossClient,$bucket);
+
+/**
+ * Open Meta Query
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @param string $bucket bucket name
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function openMetaQuery($ossClient,$bucket){
+ try {
+ $ossClient->openMetaQuery($bucket);
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+}
+
+/**
+ * Get Meta Query Status
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @param string $bucket bucket name
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function getMetaQueryStatus($ossClient,$bucket){
+ try {
+ $rs = $ossClient->getMetaQueryStatus($bucket);
+ printf("bucket $bucket meta query status state:".$rs->getState().PHP_EOL);
+ printf("bucket $bucket meta query status phase:".$rs->getPhase().PHP_EOL);
+ printf("bucket $bucket meta query status create time:".$rs->getCreateTime().PHP_EOL);
+ printf("bucket $bucket meta query status update time:".$rs->getUpdateTime().PHP_EOL);
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+}
+
+/**
+ * Do Meta Query
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @param string $bucket bucket name
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function doMetaQuery($ossClient,$bucket){
+ try {
+ // Query files larger than 500
+ $query = '{"Field": "Size","Value": "500","Operation": "gt"}';
+ $maxResults=100;
+ $sort="Size";
+ $order="asc";
+ $metaQuery = new MetaQuery($query,$maxResults,$sort,$order);
+ //Add aggregation condition
+ $agg = new MetaQueryAggregation("Size","sum");
+ $aggOne = new MetaQueryAggregation("Size","count");
+ $metaQuery->addAggregation($agg);
+ $metaQuery->addAggregation($aggOne);
+ $rs = $ossClient->doMetaQuery($bucket,$metaQuery);
+ if ($rs->getNextToken() != ""){
+ printf("Next Token:".$rs->getNextToken().PHP_EOL);
+ }
+ if ($rs->getFiles() != null){
+ foreach ($rs->getFiles() as $file ){
+ printf("File info ===============".$file->getFileName()."============================== start ".PHP_EOL);
+ printf("File Name:".$file->getFileName().PHP_EOL);
+ printf("File Size:".$file->getSize().PHP_EOL);
+ printf("File Modified Time:".$file->getFileModifiedTime().PHP_EOL);
+ printf("File Oss Object Type:".$file->getOssObjectType().PHP_EOL);
+ printf("File Oss Storage Class:".$file->getOssStorageClass().PHP_EOL);
+ printf("File Object Acl:".$file->getObjectAcl().PHP_EOL);
+ printf("File ETag:".$file->getETag().PHP_EOL);
+ printf("File Oss Crc64:".$file->getOssCrc64().PHP_EOL);
+ printf("File Oss Tagging Count:".$file->getOssTaggingCount().PHP_EOL);
+ printf("File Server Side Encryption:".$file->getServerSideEncryption().PHP_EOL);
+ printf("File Server Side Encryption Customer Algorithm:".$file->getServerSideEncryptionCustomerAlgorithm().PHP_EOL);
+ if ($file->getOssUserMeta() != null){
+ foreach ($file->getOssUserMeta() as $ossUserMeta ){
+ printf("File OSS User Meta Key:".$ossUserMeta->getKey().PHP_EOL);
+ printf("File OSS User Meta Value:".$ossUserMeta->getValue().PHP_EOL);
+ }
+ }
+ if ($file->getOssTagging() != null){
+ foreach ($file->getOssTagging() as $ossTagging ){
+ printf("File OSS Tagging Key:".$ossTagging->getKey().PHP_EOL);
+ printf("File OSS Tagging Value:".$ossTagging->getValue().PHP_EOL);
+ }
+ }
+ }
+ }
+ if ($rs->getAggregations() != null){
+ foreach ($rs->getAggregations() as $aggregation){
+ printf("Aggregation Field:".$aggregation->getField().PHP_EOL);
+ printf("Aggregation Operation:".$aggregation->getOperation().PHP_EOL);
+ printf("Aggregation Value:".$aggregation->getValue().PHP_EOL);
+ if ($aggregation->getGroups() != null){
+ foreach ($aggregation->getGroups() as $group ){
+ printf("Aggregation Group Value:".$group->getValue().PHP_EOL);
+ printf("Aggregation Group Count:".$group->getCount().PHP_EOL);
+ }
+ }
+ }
+ }
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+
+}
+
+/**
+ * Close Meta Query
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @param string $bucket bucket name
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function closeMetaQuery($ossClient,$bucket){
+ try {
+ $ossClient->closeMetaQuery($bucket);
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+}
\ No newline at end of file
diff --git a/samples/RunAll.php b/samples/RunAll.php
index 0cd7ec1..2807b4f 100644
--- a/samples/RunAll.php
+++ b/samples/RunAll.php
@@ -8,6 +8,7 @@
require_once __DIR__ . '/BucketReferer.php';
require_once __DIR__ . '/BucketLogging.php';
require_once __DIR__ . '/BucketWebsite.php';
+require_once __DIR__ . '/BucketMetaQuery.php';
require_once __DIR__ . '/Signature.php';
require_once __DIR__ . '/Object1.php';
require_once __DIR__ . '/MultipartUpload.php';
\ No newline at end of file
diff --git a/src/OSS/Model/BucketMetaQueryStatus.php b/src/OSS/Model/BucketMetaQueryStatus.php
new file mode 100644
index 0000000..2544cf7
--- /dev/null
+++ b/src/OSS/Model/BucketMetaQueryStatus.php
@@ -0,0 +1,104 @@
+state;
+ }
+
+ /**
+ * Get phase
+ *
+ * @return string
+ */
+ public function getPhase()
+ {
+ return $this->phase;
+ }
+
+ /**
+ * Get create time
+ *
+ * @return string
+ */
+ public function getCreateTime()
+ {
+ return $this->createTime;
+ }
+
+ /**
+ * Get update time
+ *
+ * @return string
+ */
+ public function getUpdateTime()
+ {
+ return $this->updateTime;
+ }
+
+ /**
+ * Parse stat from the xml.
+ *
+ * @param string $strXml
+ * @throws OssException
+ * @return null
+ */
+ public function parseFromXml($strXml)
+ {
+ $xml = simplexml_load_string($strXml);
+ if (isset($xml->State) ) {
+ $this->state = strval($xml->State);
+ }
+ if (isset($xml->Phase) ) {
+ $this->phase = strval($xml->Phase);
+ }
+ if (isset($xml->CreateTime) ) {
+ $this->createTime = strval($xml->CreateTime);
+ }
+
+ if (isset($xml->UpdateTime) ) {
+ $this->updateTime = strval($xml->UpdateTime);
+ }
+
+ }
+
+ /**
+ * state
+ * @var string
+ */
+ private $state;
+
+ /**
+ * phase
+ * @var string
+ */
+ private $phase;
+
+ /**
+ * Create time
+ * @var string
+ */
+ private $createTime;
+
+ /**
+ * Update time
+ * @var string
+ */
+ private $updateTime;
+
+}
\ No newline at end of file
diff --git a/src/OSS/Model/DoMetaQuery.php b/src/OSS/Model/DoMetaQuery.php
new file mode 100644
index 0000000..a05e212
--- /dev/null
+++ b/src/OSS/Model/DoMetaQuery.php
@@ -0,0 +1,263 @@
+nextToken;
+ }
+
+ /**
+ * @return MetaQueryFiles[]
+ */
+ public function getFiles(){
+ return $this->files;
+ }
+
+ /**
+ * @param $file MetaQueryFiles
+ */
+ public function addFiles($file){
+ $this->files[] = $file;
+ }
+
+ /**
+ * @return MetaQueryAggregation[]
+ */
+ public function getAggregations(){
+ return $this->aggregations;
+ }
+
+ /**
+ * @param $aggregation MetaQueryAggregation
+ */
+ public function addAggregations($aggregation){
+ $this->aggregations[] = $aggregation;
+ }
+
+ /**
+ * Parse the xml into this object.
+ *
+ * @param string $strXml
+ * @return void|null
+ */
+
+ /**
+ * Parse the xml into this object.
+ * @param $strXml
+ * @throws \OSS\Core\OssException
+ */
+ public function parseFromXml($strXml)
+ {
+ $xml = simplexml_load_string($strXml);
+ if (!isset($xml->NextToken) && !isset($xml->Files) && !isset($xml->Aggregation)) return;
+ if (isset($xml->NextToken)){
+ $this->nextToken = strval($xml->NextToken);
+ }
+ if (isset($xml->Files)){
+ $this->parseFiles($xml->Files);
+ }
+ if (isset($xml->Aggregations)){
+ $this->parseAggregations($xml->Aggregations);
+ }
+ }
+
+ /**
+ * @param \SimpleXMLElement $xmlFiles
+ */
+ private function parseFiles($xmlFiles)
+ {
+ if (isset($xmlFiles)) {
+ foreach ($xmlFiles->File as $file) {
+ $metaQueryFiles = new MetaQueryFiles();
+ if (isset($file->Filename)) {
+ $metaQueryFiles->setFileName(strval($file->Filename));
+ }
+ if (isset($file->Size)){
+ $metaQueryFiles->setSize(strval($file->Size));
+ }
+ if (isset($file->FileModifiedTime)){
+ $metaQueryFiles->setFileModifiedTime(strval($file->FileModifiedTime));
+ }
+ if (isset($file->OSSObjectType)){
+ $metaQueryFiles->setOssObjectType(strval($file->OSSObjectType));
+ }
+ if (isset($file->OSSStorageClass)){
+ $metaQueryFiles->setOssStorageClass(strval($file->OSSStorageClass));
+ }
+ if (isset($file->ObjectACL)){
+ $metaQueryFiles->setObjectAcl(strval($file->ObjectACL));
+ }
+ if (isset($file->ETag)){
+ $metaQueryFiles->setETag(strval($file->ETag));
+ }
+ if (isset($file->OSSCRC64)){
+ $metaQueryFiles->setOssCrc64(strval($file->OSSCRC64));
+ }
+ if (isset($file->OSSCRC64)){
+ $metaQueryFiles->setOssCrc64(strval($file->OSSCRC64));
+ }
+ if (isset($file->OSSTaggingCount)){
+ $metaQueryFiles->setOssTaggingCount(strval($file->OSSTaggingCount));
+ }
+ if (isset($file->OSSUserMeta)){
+ $this->parseOssUserMeta($file->OSSUserMeta,$metaQueryFiles);
+ }
+ if (isset($file->OSSTagging)){
+ $this->parseOssTagging($file->OSSTagging,$metaQueryFiles);
+ }
+ if (isset($file->ServerSideEncryption)){
+ $metaQueryFiles->setServerSideEncryption(strval($file->ServerSideEncryption));
+ }
+ if (isset($file->ServerSideEncryptionCustomerAlgorithm)){
+ $metaQueryFiles->setServerSideEncryptionCustomerAlgorithm(strval($file->ServerSideEncryptionCustomerAlgorithm));
+ }
+ $this->addFiles($metaQueryFiles);
+ }
+ }
+ }
+
+ /**
+ * @param \SimpleXMLElement $ossUserMeta
+ * @param MetaQueryFiles $metaQueryFiles
+ */
+ private function parseOssUserMeta($ossUserMeta,&$metaQueryFiles)
+ {
+ if (isset($ossUserMeta->UserMeta)) {
+ foreach ($ossUserMeta->UserMeta as $userMeta) {
+ $queryUserMeta = new MetaQueryUserMeta();
+ if (isset($userMeta->Key)){
+ $queryUserMeta->setKey(strval($userMeta->Key));
+ }
+ if (isset($userMeta->Value)){
+ $queryUserMeta->setValue(strval($userMeta->Value));
+ }
+ $metaQueryFiles->addOssUserMeta($queryUserMeta);
+ }
+ }
+ }
+
+
+ /**
+ * @param \SimpleXMLElement $ossTagging
+ * @param MetaQueryFiles $metaQueryFiles
+ */
+ private function parseOssTagging($ossTagging,&$metaQueryFiles)
+ {
+ if (isset($ossTagging->Tagging)) {
+ foreach ($ossTagging->Tagging as $tag) {
+ $metaQueryTag = new MetaQueryTagging();
+ if (isset($tag->Key)){
+ $metaQueryTag->setKey(strval($tag->Key));
+ }
+ if (isset($tag->Value)){
+ $metaQueryTag->setValue(strval($tag->Value));
+ }
+ $metaQueryFiles->addOssTagging($metaQueryTag);
+ }
+ }
+ }
+
+
+ /**
+ * @param $xml
+ * @return array | MetaQueryAggregation[]
+ */
+ private function parseAggregations($xmlAggregations)
+ {
+ if (isset($xmlAggregations->Aggregation)) {
+ foreach ($xmlAggregations->Aggregation as $aggregation) {
+ $metaQueryAggregation = new MetaQueryAggregation();
+ if (isset($aggregation->Field)){
+ $metaQueryAggregation->setField(strval($aggregation->Field));
+ }
+ if (isset($aggregation->Operation)){
+ $metaQueryAggregation->setOperation(strval($aggregation->Operation));
+ }
+ if (isset($aggregation->Value)){
+ $metaQueryAggregation->setValue(strval($aggregation->Value));
+ }
+ if (isset($aggregation->Groups)){
+ $this->parseGroups($aggregation->Groups,$metaQueryAggregation);
+ }
+ $this->addAggregations($metaQueryAggregation);
+ }
+ }
+ }
+
+ /**
+ * @param \SimpleXMLElement $xmlGroup
+ * @param MetaQueryAggregation $metaQueryAggregation
+ */
+ private function parseGroups($xmlGroup,&$metaQueryAggregation){
+ if (isset($xmlGroup->Group)) {
+ foreach ($xmlGroup->Group as $group) {
+ $metaQueryGroup = new MetaQueryGroup();
+ if (isset($group->Value)){
+ $metaQueryGroup->setValue(strval($group->Value));
+ }
+ if (isset($group->Count)){
+ $metaQueryGroup->setCount(intval($group->Count));
+ }
+ $metaQueryAggregation->addGroup($metaQueryGroup);
+ }
+ }
+ }
+
+ public function serializeToXml()
+ {
+ $xml = new \SimpleXMLElement('');
+ if (isset($this->nextToken)){
+ $xml->addChild('NextToken',$this->nextToken);
+ }
+ if (isset($this->files)){
+ $xmlFiles = $xml->addChild('Files');
+ foreach ($this->files as $file) {
+ $xmlFile = $xmlFiles->addChild('File');
+ $file->appendToXml($xmlFile);
+ }
+ }
+
+ if (isset($this->aggregations)){
+ $xmlAggregations = $xml->addChild('Aggregations');
+ foreach ($this->aggregations as $aggregation) {
+ $xmlAggregation = $xmlAggregations->addChild('Aggregation');
+ $aggregation->appendToXml($xmlAggregation);
+ }
+ }
+
+ return $xml->asXML();
+ }
+
+ public function __toString()
+ {
+ return $this->serializeToXml();
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/OSS/Model/MetaQuery.php b/src/OSS/Model/MetaQuery.php
new file mode 100644
index 0000000..fd55291
--- /dev/null
+++ b/src/OSS/Model/MetaQuery.php
@@ -0,0 +1,143 @@
+');
+ if (isset($this->nextToken)) {
+ $xml->addChild('NextToken',$this->nextToken);
+ }
+ if (isset($this->maxResults)) {
+ $xml->addChild('MaxResults',$this->maxResults);
+ }
+ if (isset($this->query)) {
+ $xml->addChild('Query',$this->query);
+ }
+ if (isset($this->sort)) {
+ $xml->addChild('Sort',$this->sort);
+ }
+ if (isset($this->order)) {
+ $xml->addChild('Order',$this->order);
+ }
+ if (isset($this->aggregations) && count($this->aggregations) > 0) {
+ $aggregations = $xml->addChild('Aggregations');
+ foreach ($this->aggregations as $aggregation) {
+ $xmlAggregation = $aggregations->addChild('Aggregation');
+ $xmlAggregation->addChild('Field', strval($aggregation->getField()));
+ $xmlAggregation->addChild('Operation', strval($aggregation->getOperation()));
+ }
+ }
+ return $xml->asXML();
+ }
+
+
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->serializeToXml();
+ }
+
+ /**
+ * @param $aggregation MetaQueryAggregation
+ */
+ public function addAggregation($aggregation)
+ {
+ $this->aggregations[] = $aggregation;
+ }
+
+
+ /**
+ * @param string $nextToken
+ */
+ public function setNextToken($nextToken)
+ {
+ $this->nextToken = $nextToken;
+ }
+
+ /**
+ * @param int $maxResults
+ */
+ public function setMaxResults($maxResults)
+ {
+ $this->maxResults = $maxResults;
+ }
+
+ /**
+ * @param string $query
+ */
+ public function setQuery($query)
+ {
+ $this->query = $query;
+ }
+
+ /**
+ * @param string $order
+ */
+ public function setOrder($order)
+ {
+ $this->order = $order;
+ }
+
+ /**
+ * @param string $sort
+ */
+ public function setSort($sort)
+ {
+ $this->sort = $sort;
+ }
+
+ /**
+ * @var string
+ */
+ private $nextToken;
+ /**
+ * @var int
+ */
+ private $maxResults;
+ /**
+ * @var string
+ */
+ private $query;
+ /**
+ * @var string
+ */
+ private $sort;
+ /**
+ * @var string
+ */
+ private $order;
+ /**
+ * @var MetaQueryAggregation[]
+ */
+ private $aggregations;
+}
\ No newline at end of file
diff --git a/src/OSS/Model/MetaQueryAggregation.php b/src/OSS/Model/MetaQueryAggregation.php
new file mode 100644
index 0000000..e446527
--- /dev/null
+++ b/src/OSS/Model/MetaQueryAggregation.php
@@ -0,0 +1,109 @@
+field;
+ }
+
+ /**
+ * @param $field string
+ */
+ public function setField($field){
+ $this->field = $field;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOperation(){
+ return $this->operation;
+ }
+
+ /**
+ * @param $operation string
+ */
+ public function setOperation($operation){
+ $this->operation = $operation;
+ }
+
+ /**
+ * @return float|null
+ */
+ public function getValue(){
+ return $this->value;
+ }
+
+ /**
+ * @param $value string
+ */
+ public function setValue($value){
+ $this->value = $value;
+ }
+
+ /**
+ * @return MetaQueryGroup[]
+ */
+ public function getGroups(){
+ return $this->groups;
+ }
+
+
+ /**
+ * @param $group MetaQueryGroup
+ */
+ public function addGroup($group){
+ $this->groups[] = $group;
+ }
+
+ /**
+ * @param \SimpleXMLElement $xmlAggregation
+ */
+ public function appendToXml(&$xmlAggregation)
+ {
+
+ if (isset($this->field)){
+ $xmlAggregation->addChild('Field',$this->field);
+ }
+ if (isset($this->operation)){
+ $xmlAggregation->addChild('Operation',$this->operation);
+ }
+ if (isset($this->groups)){
+ $xmlGroups = $xmlAggregation->addChild('Groups',$this->operation);
+ foreach ($this->groups as $group){
+ $xmlGroup = $xmlGroups->addChild('Group');
+ $group->appendToXml($xmlGroup);
+ }
+ }
+
+ }
+
+
+ /**
+ * @var string
+ */
+ private $field;
+ /**
+ * @var string
+ */
+ private $operation;
+ /**
+ * @var float
+ */
+ private $value;
+ /**
+ * @var MetaQueryGroup[]
+ */
+ private $groups;
+}
\ No newline at end of file
diff --git a/src/OSS/Model/MetaQueryFiles.php b/src/OSS/Model/MetaQueryFiles.php
new file mode 100644
index 0000000..2636808
--- /dev/null
+++ b/src/OSS/Model/MetaQueryFiles.php
@@ -0,0 +1,296 @@
+fileName;
+ }
+
+ /**
+ * @param $fileName string
+ */
+ public function setFileName($fileName){
+ $this->fileName = $fileName;
+ }
+
+ /**
+ * @return int
+ */
+ public function getSize(){
+ return $this->size;
+ }
+
+ /**
+ * @param $size string
+ */
+ public function setSize($size){
+ $this->size = $size;
+ }
+
+ /**
+ * @return string
+ */
+ public function getFileModifiedTime(){
+ return $this->fileModifiedTime;
+ }
+
+ /**
+ * @param $fileModifiedTime string
+ */
+ public function setFileModifiedTime($fileModifiedTime){
+ $this->fileModifiedTime = $fileModifiedTime;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOssObjectType(){
+ return $this->ossObjectType;
+ }
+
+ /**
+ * @param $ossObjectType string
+ */
+ public function setOssObjectType($ossObjectType){
+ $this->ossObjectType = $ossObjectType;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOssStorageClass(){
+ return $this->ossStorageClass;
+ }
+
+ /**
+ * @param $ossStorageClass string
+ */
+ public function setOssStorageClass($ossStorageClass){
+ $this->ossStorageClass = $ossStorageClass;
+ }
+
+ /**
+ * @return string
+ */
+ public function getObjectAcl(){
+ return $this->objectAcl;
+ }
+
+ /**
+ * @param $objectAcl string
+ */
+ public function setObjectAcl($objectAcl){
+ $this->objectAcl = $objectAcl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getETag(){
+ return $this->eTag;
+ }
+
+ /**
+ * @param $eTag string
+ */
+ public function setETag($eTag){
+ $this->eTag = $eTag;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOssCrc64(){
+ return $this->ossCrc64;
+ }
+
+ /**
+ * @param $ossCrc64 string
+ */
+ public function setOssCrc64($ossCrc64){
+ $this->ossCrc64 = $ossCrc64;
+ }
+
+ /**
+ * @return int
+ */
+ public function getOssTaggingCount(){
+ return $this->ossTaggingCount;
+ }
+
+ /**
+ * @param $ossTaggingCount string
+ */
+ public function setOssTaggingCount($ossTaggingCount){
+ $this->ossTaggingCount = $ossTaggingCount;
+ }
+
+ /**
+ * @return MetaQueryUserMeta[]
+ */
+ public function getOssUserMeta(){
+ return $this->ossUserMeta;
+ }
+
+ /**
+ * @param $ossUserMeta MetaQueryUserMeta
+ */
+ public function addOssUserMeta($ossUserMeta){
+ $this->ossUserMeta[] = $ossUserMeta;
+ }
+
+ /**
+ * @return MetaQueryTagging[]
+ */
+ public function getOssTagging(){
+ return $this->ossTagging;
+ }
+
+ /**
+ * @param $ossTagging MetaQueryTagging
+ */
+ public function addOssTagging($ossTagging){
+ $this->ossTagging[] = $ossTagging;
+ }
+
+ /**
+ * @return string
+ */
+ public function getServerSideEncryption(){
+ return $this->serverSideEncryption;
+ }
+
+ /**
+ * @param $serverSideEncryption string
+ */
+ public function setServerSideEncryption($serverSideEncryption){
+ $this->serverSideEncryption= $serverSideEncryption;
+ }
+
+ /**
+ * @return string
+ */
+ public function getServerSideEncryptionCustomerAlgorithm(){
+ return $this->serverSideEncryptionCustomerAlgorithm;
+ }
+
+ /**
+ * @param $serverSideEncryptionCustomerAlgorithm string
+ */
+ public function setServerSideEncryptionCustomerAlgorithm($serverSideEncryptionCustomerAlgorithm){
+ $this->serverSideEncryptionCustomerAlgorithm= $serverSideEncryptionCustomerAlgorithm;
+ }
+
+ /**
+ * @param \SimpleXMLElement $xmlFile
+ */
+ public function appendToXml(&$xmlFile)
+ {
+ if (isset($this->fileName)){
+ $xmlFile->addChild('Filename', $this->fileName);
+ }
+ if (isset($this->size)){
+ $xmlFile->addChild('Size', $this->size);
+ }
+ if (isset($this->fileModifiedTime)){
+ $xmlFile->addChild('FileModifiedTime', $this->fileModifiedTime);
+ }
+ if (isset($this->ossObjectType)){
+ $xmlFile->addChild('OSSObjectType', $this->ossObjectType);
+ }
+ if (isset($this->ossStorageClass)){
+ $xmlFile->addChild('OSSStorageClass', $this->ossStorageClass);
+ }
+ if (isset($this->objectAcl)){
+ $xmlFile->addChild('ObjectACL', $this->objectAcl);
+ }
+
+ if (isset($this->eTag)){
+ $xmlFile->addChild('ETag', $this->eTag);
+ }
+ if (isset($this->ossCrc64)){
+ $xmlFile->addChild('OSSCRC64', $this->ossCrc64);
+ }
+ if (isset($this->ossTaggingCount)){
+ $xmlFile->addChild('OSSTaggingCount', $this->ossTaggingCount);
+ }
+ if (isset($this->ossTagging)){
+ $xmlOssTagging = $xmlFile->addChild('OSSTagging');
+ foreach ($this->ossTagging as $tagging){
+ $tagging->appendToXml($xmlOssTagging);
+ }
+ }
+ if (isset($this->ossUserMeta)){
+ $xmlOssUserMeta = $xmlFile->addChild('OSSUserMeta');
+ foreach ($this->ossUserMeta as $userMeta){
+ $userMeta->appendToXml($xmlOssUserMeta);
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/Model/MetaQueryGroup.php b/src/OSS/Model/MetaQueryGroup.php
new file mode 100644
index 0000000..aa5fe9a
--- /dev/null
+++ b/src/OSS/Model/MetaQueryGroup.php
@@ -0,0 +1,62 @@
+value;
+ }
+
+ /**
+ * @param $value
+ */
+ public function setValue($value){
+ $this->value = $value;
+ }
+
+ /**
+ * @return float
+ */
+ public function getCount(){
+ return $this->count;
+ }
+
+ /**
+ * @param $count float
+ */
+ public function setCount($count){
+ $this->count = $count;
+ }
+
+ /**
+ * @param \SimpleXMLElement $xmlGroup
+ */
+ public function appendToXml(&$xmlGroup)
+ {
+ if (isset($this->value)){
+ $xmlGroup->addChild('Value', $this->value);
+ }
+ if (isset($this->count)){
+ $xmlGroup->addChild('Count', $this->count);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/Model/MetaQueryTagging.php b/src/OSS/Model/MetaQueryTagging.php
new file mode 100644
index 0000000..6280d91
--- /dev/null
+++ b/src/OSS/Model/MetaQueryTagging.php
@@ -0,0 +1,64 @@
+key;
+ }
+
+ /**
+ * @param $key string
+ */
+ public function setKey($key){
+ $this->key = $key;
+ }
+
+ /**
+ * @return string
+ */
+ public function getValue(){
+ return $this->value;
+ }
+
+ /**
+ * @param $value
+ */
+ public function setValue($value){
+ $this->value = $value;
+ }
+
+ /**
+ * @param \SimpleXMLElement $xmlOssTagging
+ */
+ public function appendToXml(&$xmlOssTagging)
+ {
+ if (isset($this->key) || isset($this->value)){
+ $xmlTagging = $xmlOssTagging->addChild('Tagging');
+ }
+ if (isset($this->key)){
+ $xmlTagging->addChild('Key', $this->key);
+ }
+ if (isset($this->value)){
+ $xmlTagging->addChild('Value', $this->value);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/Model/MetaQueryUserMeta.php b/src/OSS/Model/MetaQueryUserMeta.php
new file mode 100644
index 0000000..724d7b2
--- /dev/null
+++ b/src/OSS/Model/MetaQueryUserMeta.php
@@ -0,0 +1,68 @@
+key;
+ }
+
+ /**
+ * @param $key string
+ */
+ public function setKey($key){
+ $this->key = $key;
+ }
+
+ /**
+ * @return string
+ */
+ public function getValue(){
+ return $this->value;
+ }
+
+ /**
+ * @param $value
+ */
+ public function setValue($value){
+ $this->value = $value;
+ }
+
+
+ /**
+ * @param \SimpleXMLElement $xmlOssUserMeta
+ */
+ public function appendToXml(&$xmlOssUserMeta)
+ {
+ if (isset($this->key) || isset($this->value)){
+ $xmlUserMeta = $xmlOssUserMeta->addChild('UserMeta');
+ }
+ if (isset($this->key)){
+ $xmlUserMeta->addChild('Key', $this->key);
+ }
+ if (isset($this->value)){
+ $xmlUserMeta->addChild('Value', $this->value);
+ }
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/src/OSS/OssClient.php b/src/OSS/OssClient.php
index c953344..9d6e5ba 100644
--- a/src/OSS/OssClient.php
+++ b/src/OSS/OssClient.php
@@ -9,16 +9,21 @@
use OSS\Http\RequestCore;
use OSS\Http\RequestCore_Exception;
use OSS\Http\ResponseCore;
+use OSS\Model\BucketMetaQueryStatus;
use OSS\Model\CorsConfig;
use OSS\Model\CnameConfig;
+use OSS\Model\DoMetaQuery;
use OSS\Model\LoggingConfig;
use OSS\Model\LiveChannelConfig;
use OSS\Model\LiveChannelInfo;
use OSS\Model\LiveChannelListInfo;
+use OSS\Model\MetaQuery;
use OSS\Model\ObjectListInfoV2;
use OSS\Model\StorageCapacityConfig;
use OSS\Result\AclResult;
use OSS\Result\BodyResult;
+use OSS\Result\DoMetaQueryResult;
+use OSS\Result\GetBucketMetaQueryStatusResult;
use OSS\Result\GetCorsResult;
use OSS\Result\GetLifecycleResult;
use OSS\Result\GetLocationResult;
@@ -2058,12 +2063,94 @@ public function copyObject($fromBucket, $fromObject, $toBucket, $toObject, $opti
}
/**
- * Gets Object metadata
+ * Open Meta Query
+ * @param string $bucket the bucket name
+ * @param array|null $options Checks out the SDK document for the detail
+ * @return array|null
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+ public function openMetaQuery($bucket, $options = NULL)
+ {
+ $this->precheckCommon($bucket, NULL, $options,false);
+ $options[self::OSS_BUCKET] = $bucket;
+ $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
+ $options[self::OSS_OBJECT] = "/";
+ $options[self::OSS_SUB_RESOURCE] = "metaQuery&comp=add";
+ $response = $this->auth($options);
+ $result = new HeaderResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * Gets Object meta query status
*
* @param string $bucket bucket name
+ * @param string $options Checks out the SDK document for the detail
+ * @return BucketMetaQueryStatus|null
+ * @throws OssException|RequestCore_Exception
+ */
+ public function getMetaQueryStatus($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_SUB_RESOURCE] = "metaQuery";
+ $response = $this->auth($options);
+ $result = new GetBucketMetaQueryStatusResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * Do Meta query
+ * @param string $bucket bucket name
+ * @param MetaQuery $metaQuery
+ * @param array|null $options
+ * @return DoMetaQuery|null
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+ public function doMetaQuery($bucket,$metaQuery,$options = NULL)
+ {
+ $this->precheckCommon($bucket, NULL, $options,false);
+ $options[self::OSS_BUCKET] = $bucket;
+ $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
+ $options[self::OSS_OBJECT] = "/";
+ $options[self::OSS_SUB_RESOURCE] = "metaQuery&comp=query";
+ $options[self::OSS_CONTENT_TYPE] = 'application/xml';
+ $options[self::OSS_CONTENT] = $metaQuery->serializeToXml();
+ $response = $this->auth($options);
+ $result = new DoMetaQueryResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * Close Meta Query
+ * @param string $bucket the bucket name
+ * @param array|null $options Checks out the SDK document for the detail
+ * @return array|null
+ * @throws OssException|RequestCore_Exception
+ */
+ public function closeMetaQuery($bucket,$options = NULL)
+ {
+ $this->precheckCommon($bucket, NULL, $options,false);
+ $options[self::OSS_BUCKET] = $bucket;
+ $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
+ $options[self::OSS_OBJECT] = "/";
+ $options[self::OSS_SUB_RESOURCE] = "metaQuery&comp=delete";
+ $response = $this->auth($options);
+ $result = new HeaderResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * Gets Object metadata
+ * @param string $bucket bucket name
* @param string $object object name
* @param string $options Checks out the SDK document for the detail
- * @return array
+ * @return array|null
+ * @throws OssException|RequestCore_Exception
*/
public function getObjectMeta($bucket, $object, $options = NULL)
{
diff --git a/src/OSS/Result/DoMetaQueryResult.php b/src/OSS/Result/DoMetaQueryResult.php
new file mode 100644
index 0000000..b9b7524
--- /dev/null
+++ b/src/OSS/Result/DoMetaQueryResult.php
@@ -0,0 +1,32 @@
+rawResponse->body;
+ $doMetaQuery = new DoMetaQuery();
+ $doMetaQuery->parseFromXml($content);
+ return $doMetaQuery;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/src/OSS/Result/GetBucketMetaQueryStatusResult.php b/src/OSS/Result/GetBucketMetaQueryStatusResult.php
new file mode 100644
index 0000000..e39cbe7
--- /dev/null
+++ b/src/OSS/Result/GetBucketMetaQueryStatusResult.php
@@ -0,0 +1,17 @@
+rawResponse->body;
+ $query = new BucketMetaQueryStatus();
+ $query->parseFromXml($content);
+ return $query;
+ }
+}
\ No newline at end of file
diff --git a/tests/OSS/Tests/BucketDoMetaQueryResultTest.php b/tests/OSS/Tests/BucketDoMetaQueryResultTest.php
new file mode 100644
index 0000000..4745685
--- /dev/null
+++ b/tests/OSS/Tests/BucketDoMetaQueryResultTest.php
@@ -0,0 +1,174 @@
+
+
+ MTIzNDU2Nzg6aW1tdGVzdDpleGFtcGxlYnVja2V0OmRhdGFzZXQwMDE6b3NzOi8vZXhhbXBsZWJ1Y2tldC9zYW1wbGVvYmplY3QxLmpwZw==
+
+
+ exampleobject.txt
+ 120
+ 2021-06-29T14:50:13.011643661+08:00
+ Normal
+ Standard
+ default
+ "fba9dede5f27731c9771645a3986"
+ 4858A48BD1466884
+ 2
+
+
+ owner
+ John
+
+
+ type
+ document
+
+
+
+
+ x-oss-meta-location
+ hangzhou
+
+
+
+
+
+BBBB;
+
+ private $validXml2 = <<
+
+
+
+ Size
+ sum
+ 839665882
+
+
+ Size
+ count
+ 36
+
+
+ Size
+ group
+
+
+ 518
+ 1
+
+
+ 581
+ 1
+
+
+ 605
+ 1
+
+
+ 793
+ 1
+
+
+ 858
+ 1
+
+
+ 1021
+ 1
+
+
+ 1235
+ 1
+
+
+ 1644
+ 1
+
+
+ 2222
+ 1
+
+
+ 2634
+ 1
+
+
+
+
+
+BBB;
+
+
+ public function testParseValidXml()
+ {
+ try {
+ $response = new ResponseCore(array(), $this->validXml, 200);
+ $result = new DoMetaQueryResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $queryResult = $result->getData();
+ $this->assertEquals("MTIzNDU2Nzg6aW1tdGVzdDpleGFtcGxlYnVja2V0OmRhdGFzZXQwMDE6b3NzOi8vZXhhbXBsZWJ1Y2tldC9zYW1wbGVvYmplY3QxLmpwZw==",$queryResult->getNextToken());
+ $file = $queryResult->getFiles()[0];
+ $this->assertEquals("exampleobject.txt",$file->getFileName());
+ $this->assertEquals(120,$file->getSize());
+ $this->assertEquals("2021-06-29T14:50:13.011643661+08:00",$file->getFileModifiedTime());
+ $this->assertEquals("Normal",$file->getOssObjectType());
+ $this->assertEquals("Standard",$file->getOssStorageClass());
+ $this->assertEquals("default",$file->getObjectAcl());
+ $this->assertEquals("\"fba9dede5f27731c9771645a3986\"",$file->getETag());
+ $this->assertEquals("4858A48BD1466884",$file->getOssCrc64());
+ $this->assertEquals(2,$file->getOssTaggingCount());
+ $this->assertEquals("default",$file->getObjectAcl());
+ $tag = $file->getOssTagging()[1];
+ $this->assertEquals("type",$tag->getKey());
+ $this->assertEquals("document",$tag->getValue());
+ $userMeta = $file->getOssUserMeta()[0];
+ $this->assertEquals("x-oss-meta-location",$userMeta->getKey());
+ $this->assertEquals("hangzhou",$userMeta->getValue());
+ }catch (OssException $e){
+ print_r($e->getMessage());
+ $this->assertEquals(false);
+ }
+ }
+
+ public function testValidXml2()
+ {
+ try {
+ $response = new ResponseCore(array(), $this->validXml2, 200);
+ $result = new DoMetaQueryResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $queryResult = $result->getData();
+ $this->assertEquals("",$queryResult->getNextToken());
+ $files = $queryResult->getFiles();
+ $this->assertNull($files);
+ $agg = $queryResult->getAggregations()[0];
+ $this->assertEquals("Size",$agg->getField());
+ $this->assertEquals("sum",$agg->getOperation());
+ $this->assertEquals("839665882",$agg->getValue());
+ $agg3 = $queryResult->getAggregations()[2];
+ $this->assertEquals("group",$agg3->getOperation());
+
+ $group2 = $agg3->getGroups()[2];
+ $this->assertEquals("605",$group2->getValue());
+ $this->assertEquals(1,$group2->getCount());
+ }catch (OssException $e){
+ print_r($e->getMessage());
+ $this->assertEquals(false);
+ }
+ }
+
+}
diff --git a/tests/OSS/Tests/BucketMetaQueryTest.php b/tests/OSS/Tests/BucketMetaQueryTest.php
new file mode 100644
index 0000000..19dd82f
--- /dev/null
+++ b/tests/OSS/Tests/BucketMetaQueryTest.php
@@ -0,0 +1,96 @@
+ossClient->putObject($this->bucket, $key, "content");
+ }
+ }
+
+ public function testMetaQuery()
+ {
+ try {
+ $this->ossClient->openMetaQuery($this->bucket);
+ $this->assertTrue(true);
+ } catch (OssException $e) {
+ printf("Open Meta Query status error:".$e->getMessage());
+ $this->assertTrue(false);
+ }
+
+ try {
+ $rs = $this->ossClient->getMetaQueryStatus($this->bucket);
+ $this->assertEquals(true, $rs->getState() != "");
+ $this->assertEquals(true, $rs->getUpdateTime() != "");
+ $this->assertEquals(true, $rs->getCreateTime() != "");
+ } catch (OssException $e) {
+ printf("Get Meta Query status error:".$e->getMessage());
+ $this->assertEquals(false);
+ }
+
+
+ sleep(180);
+
+ try {
+ $query = '{"Field": "Size","Value": "5","Operation": "gt"}';
+ $metaQuery = new MetaQuery();
+ $metaQuery->setQuery($query);
+ $metaQuery->setMaxResults(5);
+ $metaQuery->setOrder("asc");
+ $metaQuery->setSort("Size");
+
+ $rs = $this->ossClient->doMetaQuery($this->bucket,$metaQuery);
+ $this->assertEquals(true,$rs->getNextToken() != null);
+ $this->assertEquals(5,count($rs->getFiles()));
+ $this->assertNull($rs->getAggregations());
+ } catch (OssException $e) {
+ printf("Get Meta Query status error:".$e->getMessage());
+ $this->assertEquals(false);
+ }
+
+ try {
+ $query = '{"Field": "Size","Value": "5","Operation": "gt"}';
+ $metaQuery = new MetaQuery();
+ $metaQuery->setQuery($query);
+ $metaQuery->setMaxResults(5);
+ $metaQuery->setOrder("asc");
+ $metaQuery->setSort("Size");
+ $agg = new MetaQueryAggregation();
+ $agg->setField("Size");
+ $agg->setOperation("sum");
+ $aggOne = new MetaQueryAggregation();
+ $aggOne->setField("Size");
+ $aggOne->setOperation("count");
+ $metaQuery->addAggregation($agg);
+ $metaQuery->addAggregation($aggOne);
+ $rs = $this->ossClient->doMetaQuery($this->bucket,$metaQuery);
+ $this->assertEquals("",$rs->getNextToken());
+ $this->assertNull($rs->getFiles());
+ $this->assertNotNull(true,$rs->getAggregations());
+ } catch (OssException $e) {
+ printf("Get Meta Query status error:".$e->getMessage());
+ $this->assertEquals(false);
+ }
+
+
+ try {
+ $this->ossClient->closeMetaQuery($this->bucket);
+ $this->assertTrue(true);
+ } catch (OssException $e) {
+ printf("Close Meta Query error:".$e->getMessage());
+ $this->assertTrue(false);
+ }
+ }
+
+}
diff --git a/tests/OSS/Tests/MetaQueryTest.php b/tests/OSS/Tests/MetaQueryTest.php
new file mode 100644
index 0000000..2d17acc
--- /dev/null
+++ b/tests/OSS/Tests/MetaQueryTest.php
@@ -0,0 +1,101 @@
+
+
+MTIzNDU2Nzg6aW1tdGVzdDpleGFtcGxlYnVja2V0OmRhdGFzZXQwMDE6b3NzOi8vZXhhbXBsZWJ1Y2tldC9zYW1wbGVvYmplY3QxLmpwZw==
+5
+{"Field": "Size","Value": "1048576","Operation": "gt"}
+Size
+asc
+
+
+Size
+sum
+
+
+Size
+max
+
+
+
+BBB;
+
+ private $validXml1 = <<
+
+5
+{"Field": "Size","Value": "1048576","Operation": "gt"}
+Size
+desc
+
+
+Size
+group
+
+
+Size
+max
+
+
+
+BBB;
+
+
+ public function testValidXml(){
+ $query = '{"Field": "Size","Value": "1048576","Operation": "gt"}';
+ $metaQuery = new MetaQuery();
+ $metaQuery->setQuery($query);
+ $metaQuery->setMaxResults(5);
+ $metaQuery->setSort("Size");
+ $metaQuery->setOrder("asc");
+ $agg = new MetaQueryAggregation();
+ $agg->setField("Size");
+ $agg->setOperation("sum");
+ $metaQuery->addAggregation($agg);
+
+ $aggTwo = new MetaQueryAggregation();
+ $aggTwo->setField("Size");
+ $aggTwo->setOperation("max");
+ $metaQuery->addAggregation($aggTwo);
+
+ $metaQuery->setNextToken("MTIzNDU2Nzg6aW1tdGVzdDpleGFtcGxlYnVja2V0OmRhdGFzZXQwMDE6b3NzOi8vZXhhbXBsZWJ1Y2tldC9zYW1wbGVvYmplY3QxLmpwZw==");
+ $this->assertEquals($this->cleanXml($this->validXml),$this->cleanXml($metaQuery->serializeToXml()));
+ }
+
+ public function testValidXml1(){
+ $query = '{"Field": "Size","Value": "1048576","Operation": "gt"}';
+ $metaQuery = new MetaQuery();
+ $metaQuery->setQuery($query);
+ $metaQuery->setMaxResults(5);
+ $metaQuery->setSort("Size");
+ $metaQuery->setOrder("desc");
+ $agg = new MetaQueryAggregation();
+ $agg->setField("Size");
+ $agg->setOperation("group");
+ $metaQuery->addAggregation($agg);
+
+ $aggTwo = new MetaQueryAggregation();
+ $aggTwo->setField("Size");
+ $aggTwo->setOperation("max");
+ $metaQuery->addAggregation($aggTwo);
+
+ $this->assertEquals($this->cleanXml($this->validXml1),$this->cleanXml($metaQuery->serializeToXml()));
+ }
+
+ private function cleanXml($xml)
+ {
+ return str_replace("\n", "", str_replace("\r", "", $xml));
+ }
+
+
+}