blob: 528e3c88a91482b301c2138acbafc9ef52466c31 (
plain)
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
81
82
83
84
85
|
<?php
namespace Mediawiki\DataModel;
use InvalidArgumentException;
use JsonSerializable;
class PageIdentifier implements JsonSerializable {
/**
* @var int|null
*/
private $id;
/**
* @var Title|null
*/
private $title;
/**
* @param Title|null $title
* @param int|null $id
* @throws InvalidArgumentException
*/
public function __construct( Title $title = null, $id = null ) {
if( !is_int( $id ) && !is_null( $id ) ) {
throw new InvalidArgumentException( '$id must be an int' );
}
$this->title = $title;
$this->id = $id;
}
/**
* @return int|null
*/
public function getId() {
return $this->id;
}
/**
* @return Title|null
*/
public function getTitle() {
return $this->title;
}
/**
* Does this object identify a page
* @return bool
*/
public function identifiesPage() {
if( is_null( $this->title ) && is_null( $this->id ) ) {
return false;
}
return true;
}
/**
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
*/
public function jsonSerialize() {
$array = array();
if ( $this->id !== null ) {
$array['id'] = $this->id;
}
if ( $this->title !== null ) {
$array['title'] = $this->title->jsonSerialize();
}
return $array;
}
/**
* @param array $array
*
* @returns self
*/
public static function jsonDeserialize( $array ) {
return new self(
isset( $array['title'] ) ? Title::jsonDeserialize( $array['title'] ) : null,
isset( $array['id'] ) ? $array['id'] : null
);
}
}
|