Merge "HTMLForm: Remove parameters 'notice', 'notice-messages', 'notice-message'"
[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 int
29 */
30 protected $blockId;
31
32 /**
33 * @var int
34 */
35 protected $value;
36
37 /**
38 * Create Restriction.
39 *
40 * @param int $blockId
41 * @param int $value
42 */
43 public function __construct( $blockId, $value ) {
44 $this->blockId = (int)$blockId;
45 $this->value = (int)$value;
46 }
47
48 /**
49 * {@inheritdoc}
50 */
51 public function getBlockId() {
52 return $this->blockId;
53 }
54
55 /**
56 * {@inheritdoc}
57 */
58 public function setBlockId( $blockId ) {
59 $this->blockId = (int)$blockId;
60
61 return $this;
62 }
63
64 /**
65 * {@inheritdoc}
66 */
67 public function getValue() {
68 return $this->value;
69 }
70
71 /**
72 * {@inheritdoc}
73 */
74 public static function newFromRow( \stdClass $row ) {
75 return new static( $row->ir_ipb_id, $row->ir_value );
76 }
77
78 /**
79 * {@inheritdoc}
80 */
81 public function toRow() {
82 return [
83 'ir_ipb_id' => $this->getBlockId(),
84 'ir_type' => $this->getTypeId(),
85 'ir_value' => $this->getValue(),
86 ];
87 }
88
89 /**
90 * {@inheritdoc}
91 */
92 public function equals( Restriction $other ) {
93 return $this->getHash() === $other->getHash();
94 }
95
96 /**
97 * {@inheritdoc}
98 */
99 public function getHash() {
100 return $this->getType() . '-' . $this->getValue();
101 }
102 }