MediaWiki master
AbstractRestriction.php
Go to the documentation of this file.
1<?php
10
11abstract class AbstractRestriction implements Restriction {
12
17 public const TYPE = '';
18
23 public const TYPE_ID = 0;
24
28 protected $blockId;
29
33 protected $value;
34
42 public function __construct( $blockId, $value ) {
43 $this->blockId = (int)$blockId;
44 $this->value = (int)$value;
45 }
46
50 public static function getType() {
51 return static::TYPE;
52 }
53
57 public static function getTypeId() {
58 return static::TYPE_ID;
59 }
60
64 public function getBlockId() {
65 return $this->blockId;
66 }
67
71 public function setBlockId( $blockId ) {
72 $this->blockId = (int)$blockId;
73
74 return $this;
75 }
76
80 public function getValue() {
81 return $this->value;
82 }
83
87 public static function newFromRow( \stdClass $row ) {
88 // @phan-suppress-next-line PhanTypeInstantiateAbstractStatic
89 return new static( $row->ir_ipb_id, $row->ir_value );
90 }
91
95 public function toRow() {
96 return [
97 'ir_ipb_id' => $this->getBlockId(),
98 'ir_type' => $this->getTypeId(),
99 'ir_value' => $this->getValue(),
100 ];
101 }
102
106 public function equals( Restriction $other ) {
107 return $this->getHash() === $other->getHash();
108 }
109
113 public function getHash() {
114 return $this->getType() . '-' . $this->getValue();
115 }
116}
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.