original_string: public static function setBucketLogging($bucket, $targetBucket, $targetPrefix = null)
  	{
  		// The S3 log delivery group has to be added to the target bucket's ACP
  		if ($targetBucket !== null && ($acp = self::getAccessControlPolicy($targetBucket, '')) !== false)
  		{
  			// Only add permissions to the target bucket when they do not exist
  			$aclWriteSet = false;
  			$aclReadSet = false;
  			foreach ($acp['acl'] as $acl)
  			if ($acl['type'] == 'Group' && $acl['uri'] == 'http://acs.amazonaws.com/groups/s3/LogDelivery')
  			{
  				if ($acl['permission'] == 'WRITE') $aclWriteSet = true;
  				elseif ($acl['permission'] == 'READ_ACP') $aclReadSet = true;
  			}
  			if (!$aclWriteSet) $acp['acl'][] = array(
  				'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'WRITE'
  			);
  			if (!$aclReadSet) $acp['acl'][] = array(
  				'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'READ_ACP'
  			);
  			if (!$aclReadSet || !$aclWriteSet) self::setAccessControlPolicy($targetBucket, '', $acp);
  		}
  
  		$dom = new DOMDocument;
  		$bucketLoggingStatus = $dom->createElement('BucketLoggingStatus');
  		$bucketLoggingStatus->setAttribute('xmlns', 'http://s3.amazonaws.com/doc/2006-03-01/');
  		if ($targetBucket !== null)
  		{
  			if ($targetPrefix == null) $targetPrefix = $bucket . '-';
  			$loggingEnabled = $dom->createElement('LoggingEnabled');
  			$loggingEnabled->appendChild($dom->createElement('TargetBucket', $targetBucket));
  			$loggingEnabled->appendChild($dom->createElement('TargetPrefix', $targetPrefix));
  			// TODO: Add TargetGrants?
  			$bucketLoggingStatus->appendChild($loggingEnabled);
  		}
  		$dom->appendChild($bucketLoggingStatus);
  
  		$rest = new S3Request('PUT', $bucket, '', self::$endpoint);
  		$rest->setParameter('logging', null);
  		$rest->data = $dom->saveXML();
  		$rest->size = strlen($rest->data);
  		$rest->setHeader('Content-Type', 'application/xml');
  		$rest = $rest->getResponse();
  		if ($rest->error === false && $rest->code !== 200)
  			$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
  		if ($rest->error !== false)
  		{
  			self::__triggerError(sprintf("S3::setBucketLogging({$bucket}, {$targetBucket}): [%s] %s",
  			$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
  			return false;
  		}
  		return true;
  	}
code: public static function setBucketLogging($bucket, $targetBucket, $targetPrefix = null)
  	{
  		// The S3 log delivery group has to be added to the target bucket's ACP
  		if ($targetBucket !== null && ($acp = self::getAccessControlPolicy($targetBucket, '')) !== false)
  		{
  			// Only add permissions to the target bucket when they do not exist
  			$aclWriteSet = false;
  			$aclReadSet = false;
  			foreach ($acp['acl'] as $acl)
  			if ($acl['type'] == 'Group' && $acl['uri'] == 'http://acs.amazonaws.com/groups/s3/LogDelivery')
  			{
  				if ($acl['permission'] == 'WRITE') $aclWriteSet = true;
  				elseif ($acl['permission'] == 'READ_ACP') $aclReadSet = true;
  			}
  			if (!$aclWriteSet) $acp['acl'][] = array(
  				'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'WRITE'
  			);
  			if (!$aclReadSet) $acp['acl'][] = array(
  				'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'READ_ACP'
  			);
  			if (!$aclReadSet || !$aclWriteSet) self::setAccessControlPolicy($targetBucket, '', $acp);
  		}
  
  		$dom = new DOMDocument;
  		$bucketLoggingStatus = $dom->createElement('BucketLoggingStatus');
  		$bucketLoggingStatus->setAttribute('xmlns', 'http://s3.amazonaws.com/doc/2006-03-01/');
  		if ($targetBucket !== null)
  		{
  			if ($targetPrefix == null) $targetPrefix = $bucket . '-';
  			$loggingEnabled = $dom->createElement('LoggingEnabled');
  			$loggingEnabled->appendChild($dom->createElement('TargetBucket', $targetBucket));
  			$loggingEnabled->appendChild($dom->createElement('TargetPrefix', $targetPrefix));
  			// TODO: Add TargetGrants?
  			$bucketLoggingStatus->appendChild($loggingEnabled);
  		}
  		$dom->appendChild($bucketLoggingStatus);
  
  		$rest = new S3Request('PUT', $bucket, '', self::$endpoint);
  		$rest->setParameter('logging', null);
  		$rest->data = $dom->saveXML();
  		$rest->size = strlen($rest->data);
  		$rest->setHeader('Content-Type', 'application/xml');
  		$rest = $rest->getResponse();
  		if ($rest->error === false && $rest->code !== 200)
  			$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
  		if ($rest->error !== false)
  		{
  			self::__triggerError(sprintf("S3::setBucketLogging({$bucket}, {$targetBucket}): [%s] %s",
  			$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
  			return false;
  		}
  		return true;
  	}
code_tokens: public static function setBucketLogging ( $ bucket , $ targetBucket , $ targetPrefix = null ) { // The S3 log delivery group has to be added to the target bucket's ACP if ( $ targetBucket !== null && ( $ acp = self :: getAccessControlPolicy ( $ targetBucket , '' ) ) !== false ) { // Only add permissions to the target bucket when they do not exist $ aclWriteSet = false ; $ aclReadSet = false ; foreach ( $ acp [ 'acl' ] as $ acl ) if ( $ acl [ 'type' ] == 'Group' && $ acl [ 'uri' ] == 'http://acs.amazonaws.com/groups/s3/LogDelivery' ) { if ( $ acl [ 'permission' ] == 'WRITE' ) $ aclWriteSet = true ; elseif ( $ acl [ 'permission' ] == 'READ_ACP' ) $ aclReadSet = true ; } if ( ! $ aclWriteSet ) $ acp [ 'acl' ] [ ] = array ( 'type' => 'Group' , 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery' , 'permission' => 'WRITE' ) ; if ( ! $ aclReadSet ) $ acp [ 'acl' ] [ ] = array ( 'type' => 'Group' , 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery' , 'permission' => 'READ_ACP' ) ; if ( ! $ aclReadSet || ! $ aclWriteSet ) self :: setAccessControlPolicy ( $ targetBucket , '' , $ acp ) ; } $ dom = new DOMDocument ; $ bucketLoggingStatus = $ dom -> createElement ( 'BucketLoggingStatus' ) ; $ bucketLoggingStatus -> setAttribute ( 'xmlns' , 'http://s3.amazonaws.com/doc/2006-03-01/' ) ; if ( $ targetBucket !== null ) { if ( $ targetPrefix == null ) $ targetPrefix = $ bucket . '-' ; $ loggingEnabled = $ dom -> createElement ( 'LoggingEnabled' ) ; $ loggingEnabled -> appendChild ( $ dom -> createElement ( 'TargetBucket' , $ targetBucket ) ) ; $ loggingEnabled -> appendChild ( $ dom -> createElement ( 'TargetPrefix' , $ targetPrefix ) ) ; // TODO: Add TargetGrants? $ bucketLoggingStatus -> appendChild ( $ loggingEnabled ) ; } $ dom -> appendChild ( $ bucketLoggingStatus ) ; $ rest = new S3Request ( 'PUT' , $ bucket , '' , self :: $ endpoint ) ; $ rest -> setParameter ( 'logging' , null ) ; $ rest -> data = $ dom -> saveXML ( ) ; $ rest -> size = strlen ( $ rest -> data ) ; $ rest -> setHeader ( 'Content-Type' , 'application/xml' ) ; $ rest = $ rest -> getResponse ( ) ; if ( $ rest -> error === false && $ rest -> code !== 200 ) $ rest -> error = array ( 'code' => $ rest -> code , 'message' => 'Unexpected HTTP status' ) ; if ( $ rest -> error !== false ) { self :: __triggerError ( sprintf ( "S3::setBucketLogging({$bucket}, {$targetBucket}): [%s] %s" , $ rest -> error [ 'code' ] , $ rest -> error [ 'message' ] ) , __FILE__ , __LINE__ ) ; return false ; } return true ; }
docstring: Set logging for a bucket
  
  @param string $bucket Bucket name
  @param string $targetBucket Target bucket (where logs are stored)
  @param string $targetPrefix Log prefix (e,g; domain.com-)
  @return boolean
docstring_tokens: Set logging for a bucket