1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<?php /** * Static, read-only caching of data held in serialized files. * Used for pre-built arrays of information such as plural forms. */ class Loco_data_CompiledData implements ArrayAccess, Countable, IteratorAggregate { /** * @var array */ private static $reg = []; /** * @var string */ private $name; /** * @var array */ private $data;
/** * @param string $name * @return self */ public static function get( $name ){ if( ! isset(self::$reg[$name]) ){ self::$reg[$name] = new Loco_data_CompiledData($name); } return self::$reg[$name]; }
/** * Remove all cached data from memory * @return void */ public static function flush(){ self::$reg = []; }
private function __construct( $name ){ $path = 'lib/data/'.$name.'.php'; $this->data = loco_include( $path ); $this->name = $name; }
public function destroy(){ unset( self::$reg[$this->name], $this->data ); }
#[ReturnTypeWillChange] public function offsetGet( $k ){ return isset($this->data[$k]) ? $this->data[$k] : null; }
#[ReturnTypeWillChange] public function offsetExists( $k ){ return isset($this->data[$k]); }
#[ReturnTypeWillChange] public function offsetUnset( $k ){ throw new RuntimeException('Read only'); }
#[ReturnTypeWillChange] public function offsetSet( $k, $v ){ throw new RuntimeException('Read only'); }
#[ReturnTypeWillChange] public function count(){ return count($this->data); } /** * Implements IteratorAggregate::getIterator * @return ArrayIterator */ #[ReturnTypeWillChange] public function getIterator(){ return new ArrayIterator( $this->data ); }
}
|