MediaWiki
REL1_40
MutableRevisionSlots.php
Go to the documentation of this file.
1
<?php
23
namespace
MediaWiki\Revision
;
24
25
use
Content
;
26
33
class
MutableRevisionSlots
extends
RevisionSlots
{
37
private
$resetCallback;
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
}
MediaWiki\Revision\MutableRevisionSlots
Mutable version of RevisionSlots, for constructing a new revision.
Definition
MutableRevisionSlots.php:33
MediaWiki\Revision\MutableRevisionSlots\setSlot
setSlot(SlotRecord $slot)
Sets the given slot.
Definition
MutableRevisionSlots.php:79
MediaWiki\Revision\MutableRevisionSlots\inheritSlot
inheritSlot(SlotRecord $slot)
Sets the given slot to an inherited version of $slot.
Definition
MutableRevisionSlots.php:95
MediaWiki\Revision\MutableRevisionSlots\newFromParentRevisionSlots
static newFromParentRevisionSlots(array $slots, ?callable $resetCallback=null)
Constructs a MutableRevisionSlots that inherits from the given list of slots.
Definition
MutableRevisionSlots.php:49
MediaWiki\Revision\MutableRevisionSlots\__construct
__construct(array $slots=[], ?callable $resetCallback=null)
Definition
MutableRevisionSlots.php:67
MediaWiki\Revision\MutableRevisionSlots\setContent
setContent( $role, Content $content)
Sets the content for the slot with the given role.
Definition
MutableRevisionSlots.php:106
MediaWiki\Revision\MutableRevisionSlots\removeSlot
removeSlot( $role)
Remove the slot for the given role, discontinue the corresponding stream.
Definition
MutableRevisionSlots.php:116
MediaWiki\Revision\RevisionSlots
Value object representing the set of slots belonging to a revision.
Definition
RevisionSlots.php:41
MediaWiki\Revision\RevisionSlots\$slots
SlotRecord[] callable $slots
Definition
RevisionSlots.php:45
MediaWiki\Revision\RevisionSlots\getSlots
getSlots()
Returns an associative array that maps role names to SlotRecords.
Definition
RevisionSlots.php:168
MediaWiki\Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition
SlotRecord.php:40
MediaWiki\Revision\SlotRecord\getRole
getRole()
Returns the role of the slot.
Definition
SlotRecord.php:509
MediaWiki\Revision\SlotRecord\newInherited
static newInherited(SlotRecord $slot)
Constructs a new SlotRecord for a new revision, inheriting the content of the given SlotRecord of a p...
Definition
SlotRecord.php:129
MediaWiki\Revision\SlotRecord\newUnsaved
static newUnsaved(string $role, Content $content, bool $derived=false)
Constructs a new Slot from a Content object for a new revision.
Definition
SlotRecord.php:155
Content
Base interface for representing page content.
Definition
Content.php:37
MediaWiki\Revision
Definition
ArchivedRevisionLookup.php:21
$content
$content
Definition
router.php:76
includes
Revision
MutableRevisionSlots.php
Generated on Thu Jun 27 2024 14:04:01 for MediaWiki by
1.10.0