-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResponseMetadata.php
executable file
·80 lines (62 loc) · 1.58 KB
/
ResponseMetadata.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace UrlChecker;
/**
* Represents URL check result. Must be serializable.
*/
class ResponseMetadata
{
protected $checkSuccess = false;
protected $errorText = null;
protected $redirected = false;
protected $location = null;
protected $redirectCode;
public function __construct($checkSuccess, /* , $httpCode, */ $errorText = null)
{
assert(is_bool($checkSuccess));
if (!$checkSuccess) {
assert(!empty($errorText));
}
$this->checkSuccess = $checkSuccess;
// $this->httpCode = $httpCode;
$this->errorText = $errorText;
}
public static function createWithError($errorText)
{
return new self(false, $errorText);
}
public static function createWithRedirect($location, $httpCode)
{
$self = new self(false, "Redirected to $location");
$self->redirected = true;
$self->location = $location;
$self->redirectCode = $httpCode;
return $self;
}
public static function createWithSuccess()
{
return new self(true);
}
public function isSuccessful()
{
return $this->checkSuccess;
}
public function isRedirected()
{
return $this->redirected;
}
public function getRedirectLocation()
{
return $this->location;
}
public function getRedirectCode()
{
return $this->redirectCode;
}
public function getErrorReason()
{
if (!$this->checkSuccess) {
return $this->errorText;
}
return null;
}
}