summaryrefslogtreecommitdiffstats
path: root/src/Router/UrlParsing.php
blob: ee892604d7f311b5207233807a91227e87e765dd (plain)
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
<?php

namespace Jasny\Router;

/**
 * Basic URL parsing helper methods
 */
trait UrlParsing
{
    /**
     * Get parts of a URL path
     * 
     * @param string $url
     * @return array
     */
    protected function splitUrl($url)
    {
        $path = parse_url(trim($url, '/'), PHP_URL_PATH);
        return $path ? explode('/', $path) : array();
    }
    
    /**
     * Clean up the URL
     * 
     * @param string $url
     * @return string
     */
    protected function cleanUrl($url)
    {
        if ($url !== '/') {
            $url = rtrim($url, '/');
        }
        
        return $url;
    }
}