MediaWiki  master
SimpleParsoidOutputStash.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Edit;
4 
5 use BagOStuff;
6 use FormatJson;
7 use MediaWiki\Parser\Parsoid\PageBundleJsonTrait;
9 use Wikimedia\Parsoid\Core\PageBundle;
10 
16  use PageBundleJsonTrait;
17 
19  private $bagOfStuff;
20 
22  private $duration;
23 
28  public function __construct( BagOStuff $bagOfStuff, int $duration ) {
29  $this->bagOfStuff = $bagOfStuff;
30  $this->duration = $duration;
31  }
32 
42  public function set( ParsoidRenderId $renderId, PageBundle $bundle ): bool {
43  $pageBundleJson = FormatJson::encode( $this->jsonSerializePageBundle( $bundle ) );
44 
45  return $this->bagOfStuff->set( $renderId->getKey(), $pageBundleJson, $this->duration );
46  }
47 
57  public function get( ParsoidRenderId $renderId ): ?PageBundle {
58  $pageBundleArray = FormatJson::decode(
59  $this->bagOfStuff->get( $renderId->getKey() ),
60  true
61  ) ?? [];
62  $pageBundle = $this->newPageBundleFromJson( $pageBundleArray );
63 
64  return $pageBundle ?: null;
65  }
66 
67 }
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:85
JSON formatter wrapper class.
Definition: FormatJson.php:26
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:96
static decode( $value, $assoc=false)
Decodes a JSON string.
Definition: FormatJson.php:146
__construct(BagOStuff $bagOfStuff, int $duration)
Represents the identity of a specific rendering of a specific revision at some point in time.
Interface for saving and retrieval of Parsoid HTML and Parsoid metadata from storage.