34 private static $data = [];
36 private static $nextId = 0;
39 [ $location, $id ] = self::getURLComponents(
$url );
41 throw new UnexpectedValueException(
"Missing ID in URL component." );
49 foreach ( $urls as
$url ) {
51 if ( $blob !==
false ) {
59 public function store( $location, $data ) {
60 $index = ++self::$nextId;
63 return "memory://$location/$index";
70 foreach ( self::$data as &$dataForLocation ) {
71 unset( $dataForLocation[$this->dbDomain] );
73 unset( $dataForLocation );
74 self::$data = array_filter( self::$data,
'count' );
82 private function getURLComponents(
$url ) {
84 [ $proto,
$path ] = explode(
'://',
$url, 2 ) + [
null, null ];
85 if ( $proto !==
'memory' ) {
86 throw new UnexpectedValueException(
"Got URL of protocol '$proto', not 'memory'." );
87 } elseif (
$path ===
null ) {
88 throw new UnexpectedValueException(
"URL is missing path component." );
91 $parts = explode(
'/',
$path );
92 if ( count( $parts ) > 2 ) {
93 throw new UnexpectedValueException(
"Too components in URL '$path'." );
96 return [ $parts[0], $parts[1] ?? null ];
Base class for external storage.
string $dbDomain
Default database domain to store content under.
External storage in PHP process memory for testing.
clear()
Remove all data from memory for this domain.
fetchFromURL( $url)
Fetch data from given external store URL.
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.
store( $location, $data)
Insert a data item into a given location.