-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUrlParser.php
More file actions
52 lines (44 loc) · 1.03 KB
/
UrlParser.php
File metadata and controls
52 lines (44 loc) · 1.03 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
<?php
/**
* AttwFramework
*
* @author Gabriel Jacinto <gamjj74@hotmail.com>
* @license MIT License
* @link http://attwframework.github.io
*/
namespace Attw\Tool;
use Attw\Tool\Exception\UrlParserException;
class UrlParser
{
/**
* Return the query strings from a URL
*
* @param string $url
* @return array Queries
*/
public function getQueries($url)
{
$this->verifyUrl($url);
$params = explode('?', $url);
$queries = array();
if (count($params) > 1) {
$params = end($params);
$relations = explode('&', $params);
$queries = array();
foreach ($relations as $relation) {
$camps = explode('=', $relation);
$queries[ $camps[0] ] = $camps[1];
}
}
return $queries;
}
/**
* @param string $url
*/
private function verifyUrl($url)
{
if (!filter_Var($url, FILTER_VALIDATE_URL)) {
UrlParserException::invalidUrl($url);
}
}
}