MediaWiki  1.33.0
AbstractRestriction.php
Go to the documentation of this file.
1 <?php
24 
25 abstract class AbstractRestriction implements Restriction {
26 
30  const TYPE = '';
31 
35  const TYPE_ID = 0;
36 
40  protected $blockId;
41 
45  protected $value;
46 
54  public function __construct( $blockId, $value ) {
55  $this->blockId = (int)$blockId;
56  $this->value = (int)$value;
57  }
58 
62  public static function getType() {
63  return static::TYPE;
64  }
65 
69  public static function getTypeId() {
70  return static::TYPE_ID;
71  }
72 
76  public function getBlockId() {
77  return $this->blockId;
78  }
79 
83  public function setBlockId( $blockId ) {
84  $this->blockId = (int)$blockId;
85 
86  return $this;
87  }
88 
92  public function getValue() {
93  return $this->value;
94  }
95 
99  public static function newFromRow( \stdClass $row ) {
100  // @phan-suppress-next-line PhanTypeInstantiateAbstract
101  return new static( $row->ir_ipb_id, $row->ir_value );
102  }
103 
107  public function toRow() {
108  return [
109  'ir_ipb_id' => $this->getBlockId(),
110  'ir_type' => $this->getTypeId(),
111  'ir_value' => $this->getValue(),
112  ];
113  }
114 
118  public function equals( Restriction $other ) {
119  return $this->getHash() === $other->getHash();
120  }
121 
125  public function getHash() {
126  return $this->getType() . '-' . $this->getValue();
127  }
128 }
MediaWiki\Block\Restriction\AbstractRestriction\toRow
toRow()
@inheritDoc
Definition: AbstractRestriction.php:107
MediaWiki\Block\Restriction\Restriction\getHash
getHash()
Create a unique hash of the block restriction based on the type and value.
MediaWiki\Block\Restriction\AbstractRestriction\__construct
__construct( $blockId, $value)
Create Restriction.
Definition: AbstractRestriction.php:54
value
if( $inline) $status value
Definition: SyntaxHighlight.php:345
MediaWiki\Block\Restriction\AbstractRestriction\getType
static getType()
@inheritDoc
Definition: AbstractRestriction.php:62
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Block\Restriction
Definition: AbstractRestriction.php:23
MediaWiki\Block\Restriction\Restriction
Definition: Restriction.php:25
MediaWiki\Block\Restriction\AbstractRestriction\equals
equals(Restriction $other)
@inheritDoc
Definition: AbstractRestriction.php:118
MediaWiki\Block\Restriction\AbstractRestriction\newFromRow
static newFromRow(\stdClass $row)
@inheritDoc
Definition: AbstractRestriction.php:99
MediaWiki\Block\Restriction\AbstractRestriction\getBlockId
getBlockId()
@inheritDoc
Definition: AbstractRestriction.php:76
MediaWiki\Block\Restriction\AbstractRestriction\$value
int $value
Definition: AbstractRestriction.php:45
MediaWiki\Block\Restriction\AbstractRestriction\getTypeId
static getTypeId()
@inheritDoc
Definition: AbstractRestriction.php:69
MediaWiki\Block\Restriction\AbstractRestriction
Definition: AbstractRestriction.php:25
MediaWiki\Block\Restriction\AbstractRestriction\setBlockId
setBlockId( $blockId)
@inheritDoc
Definition: AbstractRestriction.php:83
MediaWiki\Block\Restriction\AbstractRestriction\getValue
getValue()
@inheritDoc
Definition: AbstractRestriction.php:92
MediaWiki\Block\Restriction\AbstractRestriction\getHash
getHash()
@inheritDoc
Definition: AbstractRestriction.php:125
MediaWiki\Block\Restriction\AbstractRestriction\$blockId
int $blockId
Definition: AbstractRestriction.php:32