MediaWiki  master
AbstractRestriction.php
Go to the documentation of this file.
1 <?php
24 
25 abstract class AbstractRestriction implements Restriction {
26 
31  const TYPE = '';
32 
37  const TYPE_ID = 0;
38 
42  protected $blockId;
43 
47  protected $value;
48 
56  public function __construct( $blockId, $value ) {
57  $this->blockId = (int)$blockId;
58  $this->value = (int)$value;
59  }
60 
64  public static function getType() {
65  return static::TYPE;
66  }
67 
71  public static function getTypeId() {
72  return static::TYPE_ID;
73  }
74 
78  public function getBlockId() {
79  return $this->blockId;
80  }
81 
85  public function setBlockId( $blockId ) {
86  $this->blockId = (int)$blockId;
87 
88  return $this;
89  }
90 
94  public function getValue() {
95  return $this->value;
96  }
97 
101  public static function newFromRow( \stdClass $row ) {
102  // @phan-suppress-next-line PhanTypeInstantiateAbstract
103  return new static( $row->ir_ipb_id, $row->ir_value );
104  }
105 
109  public function toRow() {
110  return [
111  'ir_ipb_id' => $this->getBlockId(),
112  'ir_type' => $this->getTypeId(),
113  'ir_value' => $this->getValue(),
114  ];
115  }
116 
120  public function equals( Restriction $other ) {
121  return $this->getHash() === $other->getHash();
122  }
123 
127  public function getHash() {
128  return $this->getType() . '-' . $this->getValue();
129  }
130 }
getHash()
Create a unique hash of the block restriction based on the type and value.
const TYPE
String constant identifying the type of restriction.
__construct( $blockId, $value)
Create Restriction.
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