@@ -10,21 +10,12 @@ class Mem implements MemInterface
1010 ];
1111
1212 /**
13- * Everything is stored here
1413 * @var Storage[]
1514 */
16- protected static array $ storage = [];
15+ protected static array $ storages = [];
1716
18- /**
19- * @var array
20- */
2117 protected static array $ configs = [];
2218
23- /**
24- * @param string $group
25- * @param array|null|false $config
26- * @return mixed|void|null
27- */
2819 public static function config ($ group = 'default ' , $ config = false )
2920 {
3021 if ($ config === false ) {
@@ -36,6 +27,8 @@ public static function config($group = 'default', $config = false)
3627 } else {
3728 static ::$ configs [$ group ] = $ config ;
3829 }
30+
31+ return null ;
3932 }
4033
4134 public static function configProp ($ name , $ group = 'default ' )
@@ -45,118 +38,97 @@ public static function configProp($name, $group = 'default')
4538 : (isset (static ::DEFAULT_CONFIG [$ name ]) ? static ::DEFAULT_CONFIG [$ name ] : null );
4639 }
4740
48-
49- /**
50- * @param string $key
51- * @param string $group
52- * @return bool
53- */
5441 public static function has ($ key , $ group = 'default ' )
5542 {
56- return static ::hasGroup ($ group ) && isset (static ::$ storage [$ group ][$ key ]);
43+ return static ::hasGroup ($ group ) && isset (static ::$ storages [$ group ][$ key ]);
44+ }
45+
46+ public static function match ($ regex , $ group = 'default ' )
47+ {
48+ if (!static ::hasGroup ($ group )) {
49+ return null ;
50+ }
51+
52+ return static ::$ storages [$ group ]->match ($ regex );
53+ }
54+
55+ public static function matches ($ regex , $ group = 'default ' )
56+ {
57+ if (!static ::hasGroup ($ group )) {
58+ return null ;
59+ }
60+
61+ return static ::$ storages [$ group ]->matches ($ regex );
5762 }
5863
59- /**
60- * @param string $group
61- * @return bool
62- */
6364 public static function hasGroup ($ group = 'default ' )
6465 {
65- return isset (static ::$ storage [$ group ]);
66+ return isset (static ::$ storages [$ group ]);
6667 }
6768
68- /**
69- * @param string $key
70- * @param string $group
71- * @param mixed $default
72- * @return mixed|null
73- */
7469 public static function get ($ key , $ group = 'default ' , $ default = null )
7570 {
76- return static ::has ($ key , $ group ) ? static ::$ storage [$ group ][$ key ] : $ default ;
71+ return static ::has ($ key , $ group ) ? static ::$ storages [$ group ][$ key ] : $ default ;
7772 }
7873
79- /**
80- * @param string $key
81- * @param mixed $value
82- * @param string $group
83- * @return void
84- */
8574 public static function set ($ key , $ value , $ group = 'default ' )
8675 {
8776 if (!static ::hasGroup ($ group )) {
88- static ::$ storage [$ group ] = new Storage ();
77+ static ::$ storages [$ group ] = new Storage ();
8978 }
9079
91- static ::$ storage [$ group ][$ key ] = $ value ;
80+ static ::$ storages [$ group ][$ key ] = $ value ;
9281
9382 $ length_limit = static ::configProp ('length_limit ' , $ group );
94- if ($ length_limit > 0 && static ::$ storage [$ group ]->count () > $ length_limit ) {
95- static ::$ storage [$ group ]->del (static ::$ storage [$ group ]->firstKey ());
83+ if ($ length_limit > 0 && static ::$ storages [$ group ]->count () > $ length_limit ) {
84+ static ::$ storages [$ group ]->del (static ::$ storages [$ group ]->firstKey ());
9685 }
9786 }
9887
99- /**
100- * @param string $key
101- * @param string $group
102- * @return bool
103- */
10488 public static function del ($ key , $ group = 'default ' )
10589 {
10690 if (static ::has ($ key , $ group )) {
107- unset(static ::$ storage [$ group ][$ key ]);
91+ unset(static ::$ storages [$ group ][$ key ]);
10892 return true ;
10993 }
11094
11195 return false ;
11296 }
11397
114- /**
115- * @return Storage[]
116- */
98+ public static function delMatches ($ regex , $ group = 'default ' )
99+ {
100+ return static ::hasGroup ($ group ) && static ::$ storages [$ group ]->delMatches ($ regex );
101+ }
102+
117103 public static function all ()
118104 {
119- return static ::$ storage ;
105+ return static ::$ storages ;
120106 }
121107
122- /**
123- * @param string $group
124- * @return Storage|null
125- */
126108 public static function group ($ group = 'default ' )
127109 {
128- return static ::hasGroup ($ group ) ? static ::$ storage [$ group ] : null ;
110+ return static ::hasGroup ($ group ) ? static ::$ storages [$ group ] : null ;
129111 }
130112
131- /**
132- * @return int
133- */
134113 public static function groupsCount ()
135114 {
136- return count (array_keys (static ::$ storage ));
115+ return count (array_keys (static ::$ storages ));
137116 }
138117
139- /**
140- * @param $group
141- * @return bool
142- */
143118 public static function drop ($ group = 'default ' )
144119 {
145120 if (static ::hasGroup ($ group )) {
146- unset(static ::$ storage [$ group ]);
121+ unset(static ::$ storages [$ group ]);
147122 return true ;
148123 }
149124
150125 return false ;
151126 }
152127
153- /**
154- * @return bool
155- */
156128 public static function reset ()
157129 {
158130 if (static ::groupsCount ()) {
159- static ::$ storage = [];
131+ static ::$ storages = [];
160132 return true ;
161133 }
162134
0 commit comments