MediaWiki REL1_35
MutableRevisionSlots.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Revision;
24
25use Content;
26
38
49 public static function newFromParentRevisionSlots(
50 array $slots,
51 ?callable $resetCallback = null
52 ) {
53 $inherited = [];
54 foreach ( $slots as $slot ) {
55 $role = $slot->getRole();
56 $inherited[$role] = SlotRecord::newInherited( $slot );
57 }
58
59 return new MutableRevisionSlots( $inherited, $resetCallback );
60 }
61
67 public function __construct( array $slots = [], ?callable $resetCallback = null ) {
68 // @phan-suppress-next-line PhanTypeInvalidCallableArraySize
69 parent::__construct( $slots );
70 $this->resetCallback = $resetCallback;
71 }
72
79 public function setSlot( SlotRecord $slot ) {
80 if ( !is_array( $this->slots ) ) {
81 $this->getSlots(); // initialize $this->slots
82 }
83
84 $role = $slot->getRole();
85 $this->slots[$role] = $slot;
86 $this->triggerResetCallback();
87 }
88
95 public function inheritSlot( SlotRecord $slot ) {
96 $this->setSlot( SlotRecord::newInherited( $slot ) );
97 }
98
106 public function setContent( $role, Content $content ) {
107 $slot = SlotRecord::newUnsaved( $role, $content );
108 $this->setSlot( $slot );
109 }
110
116 public function removeSlot( $role ) {
117 if ( !is_array( $this->slots ) ) {
118 $this->getSlots(); // initialize $this->slots
119 }
120
121 unset( $this->slots[$role] );
122 $this->triggerResetCallback();
123 }
124
128 private function triggerResetCallback() {
129 if ( $this->resetCallback ) {
130 ( $this->resetCallback )( $this );
131 }
132 }
133
134}
135
140class_alias( MutableRevisionSlots::class, 'MediaWiki\Storage\MutableRevisionSlots' );
Mutable version of RevisionSlots, for constructing a new revision.
triggerResetCallback()
Trigger the reset callback supplied to the constructor, if any.
setSlot(SlotRecord $slot)
Sets the given slot.
inheritSlot(SlotRecord $slot)
Sets the given slot to an inherited version of $slot.
static newFromParentRevisionSlots(array $slots, ?callable $resetCallback=null)
Constructs a MutableRevisionSlots that inherits from the given list of slots.
__construct(array $slots=[], ?callable $resetCallback=null)
setContent( $role, Content $content)
Sets the content for the slot with the given role.
removeSlot( $role)
Remove the slot for the given role, discontinue the corresponding stream.
Value object representing the set of slots belonging to a revision.
getSlots()
Returns an associative array that maps role names to SlotRecords.
Value object representing a content slot associated with a page revision.
getRole()
Returns the role of the slot.
static newInherited(SlotRecord $slot)
Constructs a new SlotRecord for a new revision, inheriting the content of the given SlotRecord of a p...
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Base interface for content objects.
Definition Content.php:35
$content
Definition router.php:76