20 private static $data = [];
22 private static $nextId = 0;
26 [ $location, $id ] = self::getURLComponents(
$url );
28 throw new UnexpectedValueException(
"Missing ID in URL component." );
37 foreach ( $urls as
$url ) {
39 if ( $blob !==
false ) {
48 public function store( $location, $data ) {
49 $index = ++self::$nextId;
52 return "memory://$location/$index";
59 foreach ( self::$data as &$dataForLocation ) {
60 unset( $dataForLocation[$this->dbDomain] );
62 unset( $dataForLocation );
63 self::$data = array_filter( self::$data,
'count' );
71 private function getURLComponents(
$url ) {
73 [ $proto,
$path ] = explode(
'://',
$url, 2 ) + [
null, null ];
74 if ( $proto !==
'memory' ) {
75 throw new UnexpectedValueException(
"Got URL of protocol '$proto', not 'memory'." );
76 } elseif (
$path ===
null ) {
77 throw new UnexpectedValueException(
"URL is missing path component." );
80 $parts = explode(
'/',
$path );
81 if ( count( $parts ) > 2 ) {
82 throw new UnexpectedValueException(
"Too components in URL '$path'." );
85 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.string|bool The text stored or false on error
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.string[] Map of (url => text) for the URLs where data was a...
store( $location, $data)
Insert a data item into a given location.string|bool The URL of the stored data item,...