Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
namespace Guzzle\Parser\Url;
4
 
5
use Guzzle\Common\Version;
6
 
7
/**
8
 * Parses URLs into parts using PHP's built-in parse_url() function
9
 * @deprecated Just use parse_url. UTF-8 characters should be percent encoded anyways.
10
 * @codeCoverageIgnore
11
 */
12
class UrlParser implements UrlParserInterface
13
{
14
    /** @var bool Whether or not to work with UTF-8 strings */
15
    protected $utf8 = false;
16
 
17
    /**
18
     * Set whether or not to attempt to handle UTF-8 strings (still WIP)
19
     *
20
     * @param bool $utf8 Set to TRUE to handle UTF string
21
     */
22
    public function setUtf8Support($utf8)
23
    {
24
        $this->utf8 = $utf8;
25
    }
26
 
27
    public function parseUrl($url)
28
    {
29
        Version::warn(__CLASS__ . ' is deprecated. Just use parse_url()');
30
 
31
        static $defaults = array('scheme' => null, 'host' => null, 'path' => null, 'port' => null, 'query' => null,
32
            'user' => null, 'pass' => null, 'fragment' => null);
33
 
34
        $parts = parse_url($url);
35
 
36
        // Need to handle query parsing specially for UTF-8 requirements
37
        if ($this->utf8 && isset($parts['query'])) {
38
            $queryPos = strpos($url, '?');
39
            if (isset($parts['fragment'])) {
40
                $parts['query'] = substr($url, $queryPos + 1, strpos($url, '#') - $queryPos - 1);
41
            } else {
42
                $parts['query'] = substr($url, $queryPos + 1);
43
            }
44
        }
45
 
46
        return $parts + $defaults;
47
    }
48
}