Merge "Fix slow queries in migrateActors.php"
[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 * @since 1.33
41 * @param int $blockId
42 * @param int $value
43 */
44 public function __construct( $blockId, $value ) {
45 $this->blockId = (int)$blockId;
46 $this->value = (int)$value;
47 }
48
49 /**
50 * {@inheritdoc}
51 */
52 public function getBlockId() {
53 return $this->blockId;
54 }
55
56 /**
57 * {@inheritdoc}
58 */
59 public function setBlockId( $blockId ) {
60 $this->blockId = (int)$blockId;
61
62 return $this;
63 }
64
65 /**
66 * {@inheritdoc}
67 */
68 public function getValue() {
69 return $this->value;
70 }
71
72 /**
73 * {@inheritdoc}
74 */
75 public static function newFromRow( \stdClass $row ) {
76 return new static( $row->ir_ipb_id, $row->ir_value );
77 }
78
79 /**
80 * {@inheritdoc}
81 */
82 public function toRow() {
83 return [
84 'ir_ipb_id' => $this->getBlockId(),
85 'ir_type' => $this->getTypeId(),
86 'ir_value' => $this->getValue(),
87 ];
88 }
89
90 /**
91 * {@inheritdoc}
92 */
93 public function equals( Restriction $other ) {
94 return $this->getHash() === $other->getHash();
95 }
96
97 /**
98 * {@inheritdoc}
99 */
100 public function getHash() {
101 return $this->getType() . '-' . $this->getValue();
102 }
103 }