20678ad0c1a52a890a0ab0d012d8bdf732c8a6c4
[lhc/web/wiklou.git] / includes / block / Restriction / AbstractRestriction.php
1 <?php
2 /**
3 * Abstract block restriction.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 namespace MediaWiki\Block\Restriction;
24
25 abstract class AbstractRestriction implements Restriction {
26
27 /**
28 * @var string
29 */
30 const TYPE = '';
31
32 /**
33 * @var int
34 */
35 const TYPE_ID = 0;
36
37 /**
38 * @var int
39 */
40 protected $blockId;
41
42 /**
43 * @var int
44 */
45 protected $value;
46
47 /**
48 * Create Restriction.
49 *
50 * @since 1.33
51 * @param int $blockId
52 * @param int $value
53 */
54 public function __construct( $blockId, $value ) {
55 $this->blockId = (int)$blockId;
56 $this->value = (int)$value;
57 }
58
59 /**
60 * @inheritDoc
61 */
62 public static function getType() {
63 return static::TYPE;
64 }
65
66 /**
67 * @inheritDoc
68 */
69 public static function getTypeId() {
70 return static::TYPE_ID;
71 }
72
73 /**
74 * @inheritDoc
75 */
76 public function getBlockId() {
77 return $this->blockId;
78 }
79
80 /**
81 * @inheritDoc
82 */
83 public function setBlockId( $blockId ) {
84 $this->blockId = (int)$blockId;
85
86 return $this;
87 }
88
89 /**
90 * @inheritDoc
91 */
92 public function getValue() {
93 return $this->value;
94 }
95
96 /**
97 * @inheritDoc
98 */
99 public static function newFromRow( \stdClass $row ) {
100 return new static( $row->ir_ipb_id, $row->ir_value );
101 }
102
103 /**
104 * @inheritDoc
105 */
106 public function toRow() {
107 return [
108 'ir_ipb_id' => $this->getBlockId(),
109 'ir_type' => $this->getTypeId(),
110 'ir_value' => $this->getValue(),
111 ];
112 }
113
114 /**
115 * @inheritDoc
116 */
117 public function equals( Restriction $other ) {
118 return $this->getHash() === $other->getHash();
119 }
120
121 /**
122 * @inheritDoc
123 */
124 public function getHash() {
125 return $this->getType() . '-' . $this->getValue();
126 }
127 }