<commit_before><?php
/*
 * Copyright (c) 2014 <NAME> <<EMAIL>>,
 * All rights reserved.
 *
 * This file is part of PHPMentorsProxyURLRewriteBundle.
 *
 * This program and the accompanying materials are made available under
 * the terms of the BSD 2-Clause License which accompanies this
 * distribution, and is available at http://opensource.org/licenses/BSD-2-Clause
 */

namespace PHPMentors\ProxyURLRewriteBundle\ProxyUrl;

class ProxyUrlFactory
{
    /**
     * @param  string                                             $path
     * @param  string                                             $proxyUrl
     * @return \PHPMentors\ProxyURLRewriteBundle\Routing\ProxyUrl
     */
    public function create($path, $proxyUrl)
    {
        $proxyUrlComponents = parse_url($proxyUrl);

        return new ProxyUrl(
            $path,
            $proxyUrlComponents['path'],
            array_key_exists('host', $proxyUrlComponents) ? $proxyUrlComponents['host'] : null,
            array_key_exists('scheme', $proxyUrlComponents) ? $proxyUrlComponents['scheme'] : null
        );
    }
}<commit_msg>[ProxyUrl] change ProxyUrlFactory so that different behavior of parse_url() between PHP >= 5.4.7 and PHP < 5.4.7 is fixed<commit_after><?php
/*
 * Copyright (c) 2014 <NAME> <<EMAIL>>,
 * All rights reserved.
 *
 * This file is part of PHPMentorsProxyURLRewriteBundle.
 *
 * This program and the accompanying materials are made available under
 * the terms of the BSD 2-Clause License which accompanies this
 * distribution, and is available at http://opensource.org/licenses/BSD-2-Clause
 */

namespace PHPMentors\ProxyURLRewriteBundle\ProxyUrl;

class ProxyUrlFactory
{
    /**
     * @param  string                                             $path
     * @param  string                                             $proxyUrl
     * @return \PHPMentors\ProxyURLRewriteBundle\Routing\ProxyUrl
     */
    public function create($path, $proxyUrl)
    {
        list($proxyUrlPath, $proxyUrlHost, $proxyUrlScheme) = static::parseUrl($proxyUrl);

        return new ProxyUrl($path, $proxyUrlPath, $proxyUrlHost, $proxyUrlScheme);
    }

    /**
     * @param  string                    $url
     * @return array
     * @throws \UnexpectedValueException
     * @link http://php.net/manual/en/function.parse-url.php
     */
    public static function parseUrl($url)
    {
        $components = parse_url($url);
        $path = array_key_exists('path', $components) ? $components['path'] : null;
        $host = array_key_exists('host', $components) ? $components['host'] : null;
        $scheme = array_key_exists('scheme', $components) ? $components['scheme'] : null;

        if (strpos($path, '//') === 0) {
            $endOfHostPosition = strpos($path, '/', 2);
            if ($endOfHostPosition === false) { // //example.com
                $host = substr($path, 2);
                $path = null;
            } elseif ($endOfHostPosition == 2) {
                throw new \UnexpectedValueException(sprintf('The URL "%s" is malformed.', $url));
            } elseif ($endOfHostPosition > 2) {
                $host = substr($path, 2, $endOfHostPosition - 2);
                $path = substr($path, $endOfHostPosition);
            }
        }

        return array($path, $host, $scheme);
    }
}
{'fraction_non_alphanumeric': 0.12109256449165402, 'fraction_numerical': 0.007587253414264037, 'mean_word_length': 2.2894211576846306, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '224767', 'n_tokens_mistral': 934, 'n_tokens_neox': 907, 'n_words': 226}