Merge "Add missing return types to User::getOption()"
[lhc/web/wiklou.git] / tests / phpunit / includes / externalstore / ExternalStoreForTesting.php
1 <?php
2
3 class ExternalStoreForTesting {
4
5 protected $data = [
6 'cluster1' => [
7 '200' => 'Hello',
8 '300' => [
9 'Hello', 'World',
10 ],
11 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
12 '12345' => "sttttr\002\022\000",
13 ],
14 ];
15
16 /**
17 * Fetch data from given URL
18 * @param string $url An url of the form FOO://cluster/id or FOO://cluster/id/itemid.
19 * @return mixed
20 */
21 public function fetchFromURL( $url ) {
22 // Based on ExternalStoreDB
23 $path = explode( '/', $url );
24 $cluster = $path[2];
25 $id = $path[3];
26 if ( isset( $path[4] ) ) {
27 $itemID = $path[4];
28 } else {
29 $itemID = false;
30 }
31
32 if ( !isset( $this->data[$cluster][$id] ) ) {
33 return null;
34 }
35
36 if ( $itemID !== false
37 && is_array( $this->data[$cluster][$id] )
38 && isset( $this->data[$cluster][$id][$itemID] )
39 ) {
40 return $this->data[$cluster][$id][$itemID];
41 }
42
43 return $this->data[$cluster][$id];
44 }
45
46 }