MediaWiki master
MutableRevisionSlots.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Revision;
10
12
23 private $resetCallback;
24
35 public static function newFromParentRevisionSlots(
36 array $slots,
37 ?callable $resetCallback = null
38 ) {
39 $inherited = [];
40 foreach ( $slots as $slot ) {
41 $role = $slot->getRole();
42 $inherited[$role] = SlotRecord::newInherited( $slot );
43 }
44
45 return new MutableRevisionSlots( $inherited, $resetCallback );
46 }
47
53 public function __construct( array $slots = [], ?callable $resetCallback = null ) {
54 parent::__construct( $slots );
55 $this->resetCallback = $resetCallback;
56 }
57
62 public function setSlot( SlotRecord $slot ) {
63 if ( !is_array( $this->slots ) ) {
64 $this->getSlots(); // initialize $this->slots
65 }
66
67 $role = $slot->getRole();
68 $this->slots[$role] = $slot;
69 $this->triggerResetCallback();
70 }
71
76 public function inheritSlot( SlotRecord $slot ) {
77 $this->setSlot( SlotRecord::newInherited( $slot ) );
78 }
79
87 public function setContent( $role, Content $content ) {
88 $slot = SlotRecord::newUnsaved( $role, $content );
89 $this->setSlot( $slot );
90 }
91
97 public function removeSlot( $role ) {
98 if ( !is_array( $this->slots ) ) {
99 $this->getSlots(); // initialize $this->slots
100 }
101
102 unset( $this->slots[$role] );
103 $this->triggerResetCallback();
104 }
105
109 private function triggerResetCallback() {
110 if ( $this->resetCallback ) {
111 ( $this->resetCallback )( $this );
112 }
113 }
114
115}
Mutable version of RevisionSlots, for constructing a new revision.
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(string $role, Content $content, bool $derived=false)
Constructs a new Slot from a Content object for a new revision.
Content objects represent page content, e.g.
Definition Content.php:28