MediaWiki master
AbstractRestriction.php
Go to the documentation of this file.
1<?php
24
25abstract class AbstractRestriction implements Restriction {
26
31 public const TYPE = '';
32
37 public const TYPE_ID = 0;
38
42 protected $blockId;
43
47 protected $value;
48
56 public function __construct( $blockId, $value ) {
57 $this->blockId = (int)$blockId;
58 $this->value = (int)$value;
59 }
60
64 public static function getType() {
65 return static::TYPE;
66 }
67
71 public static function getTypeId() {
72 return static::TYPE_ID;
73 }
74
78 public function getBlockId() {
79 return $this->blockId;
80 }
81
85 public function setBlockId( $blockId ) {
86 $this->blockId = (int)$blockId;
87
88 return $this;
89 }
90
94 public function getValue() {
95 return $this->value;
96 }
97
101 public static function newFromRow( \stdClass $row ) {
102 // @phan-suppress-next-line PhanTypeInstantiateAbstractStatic
103 return new static( $row->ir_ipb_id, $row->ir_value );
104 }
105
109 public function toRow() {
110 return [
111 'ir_ipb_id' => $this->getBlockId(),
112 'ir_type' => $this->getTypeId(),
113 'ir_value' => $this->getValue(),
114 ];
115 }
116
120 public function equals( Restriction $other ) {
121 return $this->getHash() === $other->getHash();
122 }
123
127 public function getHash() {
128 return $this->getType() . '-' . $this->getValue();
129 }
130}
setBlockId( $blockId)
Set the ID of the block.1.33 self
toRow()
Convert a restriction object into a row array for insertion.1.33 array
static newFromRow(\stdClass $row)
Create a new Restriction from a database row.1.33 static
getValue()
Get the value of the restriction.1.33 int
static getType()
Get the type of restriction.1.33 string
const TYPE
String constant identifying the type of restriction.
__construct( $blockId, $value)
Create Restriction.
getHash()
Create a unique hash of the block restriction based on the type and value.1.33 string
equals(Restriction $other)
Determine if a restriction equals another restriction.1.33 bool
static getTypeId()
Get the ID of the type of restriction.This ID is used in the database.1.33 int
getHash()
Create a unique hash of the block restriction based on the type and value.