Example #1
0
 /**
  * 批量删除objects
  * @throws OSS_Exception
  * @param string $bucket(Required)
  * @param array $objects (Required)
  * @param array $options (Optional)
  * @author xiaobing
  * @since 2012-03-09
  * @return ResponseCore
  */
 public function delete_objects($bucket, $objects, $options = null)
 {
     $this->precheck_common($bucket, NULL, $options, false);
     //objects
     if (!is_array($objects) || !$objects) {
         throw new OSS_Exception('The ' . __FUNCTION__ . ' method requires the "objects" option to be set as an array.');
     }
     $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
     $options[self::OSS_BUCKET] = $bucket;
     $options[self::OSS_OBJECT] = '/';
     $options[self::OSS_SUB_RESOURCE] = 'delete';
     $options[self::OSS_CONTENT_TYPE] = 'application/xml';
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><Delete></Delete>');
     // Quiet mode
     if (isset($options['quiet'])) {
         $quiet = 'false';
         if (is_bool($options['quiet'])) {
             //Boolean
             $quiet = $options['quiet'] ? 'true' : 'false';
         } elseif (is_string($options['quiet'])) {
             // String
             $quiet = $options['quiet'] === 'true' ? 'true' : 'false';
         }
         $xml->addChild('Quiet', $quiet);
     }
     // Add the objects
     foreach ($objects as $object) {
         $sub_object = $xml->addChild('Object');
         $object = OSSUtil::s_replace($object);
         $sub_object->addChild('Key', $object);
     }
     $options[self::OSS_CONTENT] = $xml->asXML();
     return $this->auth($options);
 }