1 | <?php |
||
12 | class AdUrlParser |
||
13 | { |
||
14 | /** |
||
15 | * @var \League\Uri\Interfaces\Uri|\Psr\Http\Message\UriInterface |
||
16 | */ |
||
17 | protected $url; |
||
18 | |||
19 | /** |
||
20 | * @var |
||
21 | */ |
||
22 | protected $id; |
||
23 | /** |
||
24 | * @var |
||
25 | */ |
||
26 | protected $category; |
||
27 | |||
28 | /** |
||
29 | * AdUrlParser constructor. |
||
30 | * @param $url |
||
31 | */ |
||
32 | 34 | public function __construct($url) |
|
33 | { |
||
34 | 34 | $this->url = Http::createFromString($url); |
|
35 | |||
36 | 34 | $this->url = (new RemoveQueryKeys($this->url->query->keys()))->__invoke($this->url); |
|
37 | |||
38 | 34 | preg_match( |
|
39 | 34 | '/\/(.*)\/(.*)\.htm/', |
|
40 | 34 | parse_url($this->url, PHP_URL_PATH), |
|
41 | 34 | $matches |
|
42 | ); |
||
43 | |||
44 | 34 | $this->category = $matches[1]; |
|
45 | 34 | $this->id = $matches[2]; |
|
46 | 34 | } |
|
47 | |||
48 | /** |
||
49 | * @return mixed |
||
50 | */ |
||
51 | 8 | public function getCategory() |
|
52 | { |
||
53 | 8 | return $this->category; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return mixed |
||
58 | */ |
||
59 | 18 | public function getId() |
|
60 | { |
||
61 | 18 | return $this->id; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return string |
||
66 | */ |
||
67 | 12 | public function __toString() |
|
71 | } |
||
72 |