b151957f9b05e1ad8f9f73e1e92b30e130f30d5c
[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 ],
12 ];
13
14 /**
15 * Fetch data from given URL
16 * @param string $url An url of the form FOO://cluster/id or FOO://cluster/id/itemid.
17 * @return mixed
18 */
19 public function fetchFromURL( $url ) {
20 // Based on ExternalStoreDB
21 $path = explode( '/', $url );
22 $cluster = $path[2];
23 $id = $path[3];
24 if ( isset( $path[4] ) ) {
25 $itemID = $path[4];
26 } else {
27 $itemID = false;
28 }
29
30 if ( !isset( $this->data[$cluster][$id] ) ) {
31 return null;
32 }
33
34 if ( $itemID !== false
35 && is_array( $this->data[$cluster][$id] )
36 && isset( $this->data[$cluster][$id][$itemID] )
37 ) {
38 return $this->data[$cluster][$id][$itemID];
39 }
40
41 return $this->data[$cluster][$id];
42 }
43
44 }