3 * Mutable version of RevisionSlots, for constructing a new revision.
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.
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.
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
23 namespace MediaWiki\Storage
;
28 * Mutable version of RevisionSlots, for constructing a new revision.
32 class MutableRevisionSlots
extends RevisionSlots
{
35 * Constructs a MutableRevisionSlots that inherits from the given
38 * @param SlotRecord[] $slots
40 * @return MutableRevisionSlots
42 public static function newFromParentRevisionSlots( array $slots ) {
44 foreach ( $slots as $slot ) {
45 $role = $slot->getRole();
46 $inherited[$role] = SlotRecord
::newInherited( $slot );
49 return new MutableRevisionSlots( $inherited );
53 * @param SlotRecord[] $slots An array of SlotRecords.
55 public function __construct( array $slots = [] ) {
56 parent
::__construct( $slots );
60 * Sets the given slot.
61 * If a slot with the same role is already present, it is replaced.
63 * @param SlotRecord $slot
65 public function setSlot( SlotRecord
$slot ) {
66 if ( !is_array( $this->slots
) ) {
67 $this->getSlots(); // initialize $this->slots
70 $role = $slot->getRole();
71 $this->slots
[$role] = $slot;
75 * Sets the given slot to an inherited version of $slot.
76 * If a slot with the same role is already present, it is replaced.
78 * @param SlotRecord $slot
80 public function inheritSlot( SlotRecord
$slot ) {
81 $this->setSlot( SlotRecord
::newInherited( $slot ) );
85 * Sets the content for the slot with the given role.
86 * If a slot with the same role is already present, it is replaced.
89 * @param Content $content
91 public function setContent( $role, Content
$content ) {
92 $slot = SlotRecord
::newUnsaved( $role, $content );
93 $this->setSlot( $slot );
97 * Remove the slot for the given role, discontinue the corresponding stream.
101 public function removeSlot( $role ) {
102 if ( !is_array( $this->slots
) ) {
103 $this->getSlots(); // initialize $this->slots
106 unset( $this->slots
[$role] );