-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAWSResponse.php
More file actions
64 lines (53 loc) · 1.64 KB
/
AWSResponse.php
File metadata and controls
64 lines (53 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace UltimateGuitar\SwiftSesTransport;
use UltimateGuitar\SwiftSesTransport\Exceptions\AWSEmptyResponseException;
use UltimateGuitar\SwiftSesTransport\Exceptions\InvalidHeaderException;
class AWSResponse
{
public $headers = array();
public $code = 0;
public $message = '';
public $body = '';
public $xml = null;
const STATE_EMPTY = 0;
const STATE_HEADERS = 1;
const STATE_BODY = 2;
protected $state = self::STATE_EMPTY;
public function line ( $line )
{
switch( $this->state )
{
case self::STATE_EMPTY:
if( ! $line )
{
throw new AWSEmptyResponseException();
}
$split = explode( ' ', $line );
$this->code = $split[1];
$this->message = implode( array_slice( $split, 2 ), ' ' );
$this->state = self::STATE_HEADERS;
break;
case self::STATE_HEADERS:
if( "\r\n" == $line )
{
$this->state = self::STATE_BODY;
break;
}
$pos = strpos( $line, ':' );
if( false === $pos )
{
throw new InvalidHeaderException( $line );
}
$key = substr( $line, 0, $pos );
$this->headers[$key] = substr( $line, $pos );
break;
case self::STATE_BODY:
$this->body .= $line;
break;
}
}
public function complete ()
{
$this->xml = simplexml_load_string( $this->body );
}
}