|
18 | 18 | use GuzzleHttp; |
19 | 19 | use vipnytt\XRobotsTagParser\Exceptions\XRobotsTagParserException; |
20 | 20 | use vipnytt\XRobotsTagParser\Rebuild; |
21 | | -use vipnytt\XRobotsTagParser\URLParser; |
22 | 21 | use vipnytt\XRobotsTagParser\UserAgentParser; |
23 | 22 |
|
24 | 23 | class XRobotsTagParser |
@@ -57,23 +56,20 @@ class XRobotsTagParser |
57 | 56 | */ |
58 | 57 | public function __construct($url, $userAgent = self::USERAGENT_DEFAULT, array $config = []) |
59 | 58 | { |
60 | | - // Parse URL |
61 | | - $urlParser = new URLParser(trim($url)); |
62 | | - if (!$urlParser->isValid()) { |
| 59 | + $this->url = $url; |
| 60 | + if (!filter_var($this->url, FILTER_VALIDATE_URL)) { |
63 | 61 | throw new XRobotsTagParserException('Invalid URL provided'); |
64 | 62 | } |
65 | | - // Encode URL |
66 | | - $this->url = $urlParser->encode(); |
67 | 63 | // Set any optional configuration options |
68 | 64 | $this->config = $config; |
69 | 65 | if (isset($this->config['headers']) && is_array($this->config['headers'])) { |
70 | 66 | $this->headers = $this->config['headers']; |
71 | 67 | } |
72 | | - // Parse rules |
73 | | - $this->parse(); |
74 | 68 | // Set User-Agent |
75 | 69 | $parser = new UserAgentParser($userAgent); |
76 | 70 | $this->userAgent = $parser->match(array_keys($this->rules), self::USERAGENT_DEFAULT); |
| 71 | + // Parse rules |
| 72 | + $this->parse(); |
77 | 73 | } |
78 | 74 |
|
79 | 75 | /** |
@@ -239,7 +235,7 @@ public function getDirectiveMeaning($directive) |
239 | 235 | throw new XRobotsTagParserException('Unknown directive'); |
240 | 236 | } |
241 | 237 | $class = "XRobotsTagParser\\directives\\$directive"; |
242 | | - $object = new $class($directive); |
| 238 | + $object = new $class($this->directiveClasses()[$directive]); |
243 | 239 | if (!$object instanceof XRobotsTagParser\directives\directiveInterface) { |
244 | 240 | throw new XRobotsTagParserException('Unsupported directive class'); |
245 | 241 | } |
|
0 commit comments