9use UnexpectedValueException;
24 private static $data = [];
26 private static $nextId = 0;
30 [ $location, $id ] = self::getURLComponents(
$url );
32 throw new UnexpectedValueException(
"Missing ID in URL component." );
41 foreach ( $urls as
$url ) {
43 if ( $blob !==
false ) {
52 public function store( $location, $data ) {
53 $index = ++self::$nextId;
56 return "memory://$location/$index";
63 foreach ( self::$data as &$dataForLocation ) {
64 unset( $dataForLocation[$this->dbDomain] );
66 unset( $dataForLocation );
67 self::$data = array_filter( self::$data,
'count' );
75 private function getURLComponents(
$url ) {
77 [ $proto,
$path ] = explode(
'://',
$url, 2 ) + [
null, null ];
78 if ( $proto !==
'memory' ) {
79 throw new UnexpectedValueException(
"Got URL of protocol '$proto', not 'memory'." );
80 } elseif (
$path ===
null ) {
81 throw new UnexpectedValueException(
"URL is missing path component." );
84 $parts = explode(
'/',
$path );
85 if ( count( $parts ) > 2 ) {
86 throw new UnexpectedValueException(
"Too components in URL '$path'." );
89 return [ $parts[0], $parts[1] ?? null ];
94class_alias( ExternalStoreMemory::class,
'ExternalStoreMemory' );