Вход Регистрация
Файл: includes/library/aws/Aws/Sqs/SqsClient.php
Строк: 91
<?php
namespace AwsSqs;

use 
AwsAwsClient;
use 
AwsCommandInterface;
use 
AwsSqsExceptionSqsException;
use 
GuzzleHttpPsr7Uri;
use 
PsrHttpMessageRequestInterface;

/**
 * Client used to interact Amazon Simple Queue Service (Amazon SQS)
 */
class SqsClient extends AwsClient
{
    public function 
__construct(array $config)
    {
        
parent::__construct($config);
        
$list $this->getHandlerList();
        
$list->appendBuild($this->queueUrl(), 'sqs.queue_url');
        
$list->appendSign($this->validateMd5(), 'sqs.md5');
    }

    
/**
     * Converts a queue URL into a queue ARN.
     *
     * @param string $queueUrl The queue URL to perform the action on.
     *                         Retrieved when the queue is first created.
     *
     * @return string An ARN representation of the queue URL.
     */
    
public function getQueueArn($queueUrl)
    {
        return 
strtr($queueUrl, array(
            
'http://'        => 'arn:aws:',
            
'https://'       => 'arn:aws:',
            
'.amazonaws.com' => '',
            
'/'              => ':',
            
'.'              => ':',
        ));
    }

    
/**
     * Moves the URI of the queue to the URI in the input parameter.
     *
     * @return callable
     */
    
private function queueUrl()
    {
        return static function (callable 
$handler) {
            return function (
                
CommandInterface $c,
                
RequestInterface $r null
            
) use ($handler) {
                if (
$c->hasParam('QueueUrl')) {
                    
$uri Uri::resolve($r->getUri(), $c['QueueUrl']);
                    
$r $r->withUri($uri);
                }
                return 
$handler($c$r);
            };
        };
    }

    
/**
     * Validates ReceiveMessage body MD5s
     *
     * @return callable
     */
    
private function validateMd5()
    {
        return static function (callable 
$handler) {
            return function (
                
CommandInterface $c,
                
RequestInterface $r null
            
) use ($handler) {
                if (
$c->getName() !== 'ReceiveMessage') {
                    return 
$handler($c$r);
                }

                return 
$handler($c$r)
                    ->
then(
                        function (
$result) use ($c$r) {
                            foreach ((array) 
$result['Messages'] as $msg) {
                                if (isset(
$msg['MD5OfBody'])
                                    && 
md5($msg['Body']) !== $msg['MD5OfBody']
                                ) {
                                    throw new 
SqsException(
                                        
sprintf(
                                            
'MD5 mismatch. Expected %s, found %s',
                                            
$msg['MD5OfBody'],
                                            
md5($msg['Body'])
                                        ),
                                        
$c,
                                        [
                                            
'code' => 'ClientChecksumMismatch',
                                            
'request' => $r
                                        
]
                                    );
                                }
                            }
                            return 
$result;
                        }
                    );
            };
        };
    }
}
Онлайн: 1
Реклама