1
|
|
|
<?php |
2
|
|
|
namespace vipnytt\RobotsTxtParser; |
3
|
|
|
|
4
|
|
|
use vipnytt\UserAgentParser; |
5
|
|
|
|
6
|
|
|
class Parser extends Core |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* HTTP status code parser |
10
|
|
|
* @var StatusCodeParser |
11
|
|
|
*/ |
12
|
|
|
protected $statusCodeParser; |
13
|
|
|
|
14
|
|
|
protected $origin; |
15
|
|
|
protected $statusCode; |
16
|
|
|
|
17
|
|
|
public function __construct($RobotsTxtURL, $statusCode, $content, $encoding = self::ENCODING, $byteLimit = self::BYTE_LIMIT) |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
parent::__construct($content, $encoding = self::ENCODING, $byteLimit = self::BYTE_LIMIT); |
20
|
|
|
$this->origin = $RobotsTxtURL; |
21
|
|
|
$this->statusCode = $statusCode; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get sitemaps |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function getSitemaps() |
30
|
|
|
{ |
31
|
|
|
return $this->sitemap->export(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get host |
36
|
|
|
* |
37
|
|
|
* @return string|null |
38
|
|
|
*/ |
39
|
|
|
public function getHost() |
40
|
|
|
{ |
41
|
|
|
return $this->host->export(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get Clean-param |
46
|
|
|
* |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
public function getCleanParam() |
50
|
|
|
{ |
51
|
|
|
return $this->cleanParam->export(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function optimizeURL($url) |
55
|
|
|
{ |
56
|
|
|
return $this->host->optimize($url); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function userAgent($string = self::USER_AGENT) |
60
|
|
|
{ |
61
|
|
|
$uaParser = new UserAgentParser($string); |
62
|
|
|
$userAgent = $uaParser->match($this->userAgent->userAgents, self::USER_AGENT); |
63
|
|
|
return new UserAgentClient([ |
64
|
|
|
self::DIRECTIVE_DISALLOW => $this->userAgent->{self::DIRECTIVE_DISALLOW}[$userAgent], |
65
|
|
|
self::DIRECTIVE_ALLOW => $this->userAgent->{self::DIRECTIVE_ALLOW}[$userAgent], |
66
|
|
|
], $userAgent, $this->origin, $this->statusCode); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.