Subversion Repositories php-qbpwcf

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
namespace Guzzle\Parser\Message;
4
 
5
/**
6
 * Implements shared message parsing functionality
7
 */
8
abstract class AbstractMessageParser implements MessageParserInterface
9
{
10
    /**
11
     * Create URL parts from HTTP message parts
12
     *
13
     * @param string $requestUrl Associated URL
14
     * @param array  $parts      HTTP message parts
15
     *
16
     * @return array
17
     */
18
    protected function getUrlPartsFromMessage($requestUrl, array $parts)
19
    {
20
        // Parse the URL information from the message
21
        $urlParts = array(
22
            'path'   => $requestUrl,
23
            'scheme' => 'http'
24
        );
25
 
26
        // Check for the Host header
27
        if (isset($parts['headers']['Host'])) {
28
            $urlParts['host'] = $parts['headers']['Host'];
29
        } elseif (isset($parts['headers']['host'])) {
30
            $urlParts['host'] = $parts['headers']['host'];
31
        } else {
32
            $urlParts['host'] = null;
33
        }
34
 
35
        if (false === strpos($urlParts['host'], ':')) {
36
            $urlParts['port'] = '';
37
        } else {
38
            $hostParts = explode(':', $urlParts['host']);
39
            $urlParts['host'] = trim($hostParts[0]);
40
            $urlParts['port'] = (int) trim($hostParts[1]);
41
            if ($urlParts['port'] == 443) {
42
                $urlParts['scheme'] = 'https';
43
            }
44
        }
45
 
46
        // Check if a query is present
47
        $path = $urlParts['path'];
48
        $qpos = strpos($path, '?');
49
        if ($qpos) {
50
            $urlParts['query'] = substr($path, $qpos + 1);
51
            $urlParts['path'] = substr($path, 0, $qpos);
52
        } else {
53
            $urlParts['query'] = '';
54
        }
55
 
56
        return $urlParts;
57
    }
58
}