MediaWiki  master
AbstractRestriction.php
Go to the documentation of this file.
1 <?php
24 
25 abstract class AbstractRestriction implements Restriction {
26 
31  const TYPE = '';
32 
37  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 }
getHash()
Create a unique hash of the block restriction based on the type and value.1.33 string ...
static getType()
Gets the type of restriction.1.33 string
getHash()
Create a unique hash of the block restriction based on the type and value.
toRow()
Convert a restriction object into a row array for insertion.1.33 array
setBlockId( $blockId)
Sets the id of the block.1.33 self
equals(Restriction $other)
Determine if a restriction equals another restriction.1.33 bool
getValue()
Gets the value of the restriction.1.33 int
const TYPE
String constant identifying the type of restriction.
__construct( $blockId, $value)
Create Restriction.
getBlockId()
Gets the id of the block.1.33 int
static newFromRow(\stdClass $row)
Creates a new Restriction from a database row.1.33 static
static getTypeId()
Gets the id of the type of restriction.This id is used in the database.1.33 int