Go to the documentation of this file.
26 use InvalidArgumentException;
28 use OutOfBoundsException;
29 use Wikimedia\Assert\Assert;
30 use Wikimedia\NonSerializable\NonSerializableTrait;
41 use NonSerializableTrait;
43 public const MAIN =
'main';
83 $row = clone $slot->row;
86 foreach ( $overrides as $key => $value ) {
113 'slot_revision_id' =>
null,
132 Assert::parameterType(
'string', $role,
'$role' );
136 'slot_revision_id' =>
null,
137 'slot_origin' =>
null,
138 'content_size' =>
null,
139 'content_sha1' =>
null,
140 'slot_content_id' =>
null,
141 'content_address' =>
null,
142 'role_name' => $role,
172 Assert::parameterType(
'integer', $revisionId,
'$revisionId' );
174 Assert::parameterType(
'integer|null', $contentId,
'$contentId' );
175 Assert::parameterType(
'string', $contentAddress,
'$contentAddress' );
178 throw new LogicException(
179 "Mismatching revision ID $revisionId: "
180 .
"The slot already belongs to revision {$protoSlot->getRevision()}. "
181 .
"Use SlotRecord::newInherited() to re-use content between revisions."
186 throw new LogicException(
187 "Mismatching blob address $contentAddress: "
188 .
"The slot already has content at {$protoSlot->getAddress()}."
193 throw new LogicException(
194 "Mismatching content ID $contentId: "
195 .
"The slot already has content row {$protoSlot->getContentId()} associated."
201 throw new InvalidArgumentException(
202 "An inherited blob should have a content address!"
205 if ( !$protoSlot->
hasField(
'slot_origin' ) ) {
206 throw new InvalidArgumentException(
207 "A saved inherited slot should have an origin set!"
212 $origin = $revisionId;
216 'slot_revision_id' => $revisionId,
217 'slot_content_id' => $contentId,
218 'slot_origin' => $origin,
219 'content_address' => $contentAddress,
237 Assert::parameterType( \stdClass::class,
$row,
'$row' );
238 Assert::parameterType(
'Content|callable',
$content,
'$content' );
241 property_exists(
$row,
'slot_revision_id' ),
242 '$row->slot_revision_id',
246 property_exists(
$row,
'slot_content_id' ),
247 '$row->slot_content_id',
251 property_exists(
$row,
'content_address' ),
252 '$row->content_address',
256 property_exists(
$row,
'model_name' ),
261 property_exists(
$row,
'slot_origin' ),
266 !property_exists(
$row,
'slot_inherited' ),
267 '$row->slot_inherited',
271 !property_exists(
$row,
'slot_revision' ),
272 '$row->slot_revision',
296 if ( $this->content instanceof
Content ) {
300 $obj = call_user_func( $this->content, $this );
302 Assert::postcondition(
304 'Slot content callback should return a Content object'
307 $this->content = $obj;
323 if ( !isset( $this->row->$name ) ) {
325 if ( property_exists( $this->row, $name ) ) {
328 throw new OutOfBoundsException(
'No such field: ' . $name );
332 $value = $this->row->$name;
335 if ( !is_string( $value ) && is_callable( $value ) ) {
336 $value = call_user_func( $value, $this );
353 return strval( $this->
getField( $name ) );
366 return intval( $this->
getField( $name ) );
374 if ( isset( $this->row->$name ) ) {
376 if ( !is_string( $this->row->$name ) && is_callable( $this->row->$name ) ) {
381 return isset( $this->row->$name );
429 return $this->
hasField(
'content_address' );
440 return $this->
hasField(
'slot_origin' );
463 return $this->
hasField(
'slot_content_id' );
474 return $this->
hasField(
'slot_revision_id' );
520 $this->
setField(
'content_size', $size );
539 if ( $sha1 ===
null || $sha1 ===
'' ) {
540 $format = $this->
hasField(
'format_name' )
544 $data = $this->
getContent()->serialize( $format );
546 $this->
setField(
'content_sha1', $sha1 );
564 $this->
setField(
'model_name', $model );
582 if ( $this->
hasField(
'format_name' ) ) {
594 $this->row->$name = $value;
606 return \Wikimedia\base_convert( sha1(
$blob ), 16, 36, 31 );
629 if ( $other === $this ) {
639 && $this->getAddress() == $other->
getAddress()
661 class_alias( SlotRecord::class,
'MediaWiki\Storage\SlotRecord' );
Base interface for content objects.
getModel()
Returns the ID of the content model used by this Content object.