| 1 | <?php |
||
| 11 | class Title implements JsonSerializable { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | private $title; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var int |
||
| 20 | */ |
||
| 21 | private $ns; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param string $title |
||
| 25 | * @param int $ns |
||
| 26 | * |
||
| 27 | * @throws InvalidArgumentException |
||
| 28 | */ |
||
| 29 | 10 | public function __construct( $title, $ns = 0 ) { |
|
| 30 | 10 | if( !is_string( $title ) ) { |
|
| 31 | 4 | throw new InvalidArgumentException( '$title must be a string' ); |
|
| 32 | } |
||
| 33 | 6 | if( !is_int( $ns ) ) { |
|
| 34 | 2 | throw new InvalidArgumentException( '$ns must be an int' ); |
|
| 35 | } |
||
| 36 | 4 | $this->title = $title; |
|
| 37 | 4 | $this->ns = $ns; |
|
| 38 | 4 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @return int |
||
| 42 | * @since 0.1 |
||
| 43 | */ |
||
| 44 | 3 | public function getNs() { |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @return string |
||
| 50 | * @since 0.6 |
||
| 51 | */ |
||
| 52 | 3 | public function getText() { |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @return string |
||
| 58 | * @deprecated in 0.6 use getText (makes things look cleaner) |
||
| 59 | */ |
||
| 60 | 3 | public function getTitle() { |
|
| 61 | 3 | return $this->getText(); |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
| 66 | */ |
||
| 67 | 1 | public function jsonSerialize() { |
|
| 68 | return array( |
||
| 69 | 1 | 'title' => $this->title, |
|
| 70 | 1 | 'ns' => $this->ns, |
|
| 71 | 1 | ); |
|
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param array $json |
||
| 76 | * |
||
| 77 | * @return self |
||
| 78 | */ |
||
| 79 | 1 | public static function jsonDeserialize( $json ) { |
|
| 82 | |||
| 83 | } |
||
| 84 |