@@ -14,38 +14,17 @@ class Meta implements Contracts\Meta
14
14
protected $ types = [];
15
15
protected $ instances = [];
16
16
17
- public function __construct (Contracts \Manager $ manager )
17
+ public function __construct (Contracts \Manager $ manager, array $ data = null )
18
18
{
19
19
$ this ->manager = $ manager ;
20
20
21
- $ client = $ manager ->getClient ();
22
- foreach ($ client ->getSpace ('property ' )->select ([], 'space ' )->getData () as $ property ) {
23
- list ($ id , $ spaceId , $ line , $ name , $ type ) = $ property ;
24
- if (!array_key_exists ($ spaceId , $ this ->property )) {
25
- $ this ->property [$ spaceId ] = [];
26
- $ this ->types [$ spaceId ] = [];
27
- }
28
- $ this ->property [$ spaceId ][$ line ] = $ name ;
29
- $ this ->types [$ spaceId ][$ name ] = $ type ;
30
- }
31
- foreach ($ client ->getSpace ('_vindex ' )->select ([], 'primary ' )->getData () as $ index ) {
32
- list ($ spaceId , $ num , $ name , $ type , $ params , $ properties ) = $ index ;
33
- if (!array_key_exists ($ spaceId , $ this ->property )) {
34
- // tarantool space index
35
- continue ;
36
- }
37
- if (!isset ($ this ->indexes [$ spaceId ])) {
38
- $ this ->indexes [$ spaceId ] = [];
39
- }
40
- $ this ->indexes [$ spaceId ][$ num ] = [];
41
- foreach ($ properties as $ row ) {
42
- list ($ part , $ type ) = $ row ;
43
- $ this ->indexes [$ spaceId ][$ num ][] = $ this ->property [$ spaceId ][$ part ];
44
- }
45
- }
46
- foreach ($ this ->property as $ spaceId => $ collection ) {
47
- ksort ($ collection );
48
- $ this ->property [$ spaceId ] = $ collection ;
21
+ if ($ data ) {
22
+ $ this ->property = $ data ['property ' ];
23
+ $ this ->indexes = $ data ['indexes ' ];
24
+ $ this ->types = $ data ['types ' ];
25
+
26
+ } else {
27
+ $ this ->collectData ();
49
28
}
50
29
}
51
30
@@ -170,4 +149,49 @@ public function getConvention()
170
149
171
150
return $ this ->convention ;
172
151
}
152
+
153
+ private function collectData ()
154
+ {
155
+ $ client = $ this ->manager ->getClient ();
156
+ foreach ($ client ->getSpace ('property ' )->select ([], 'space ' )->getData () as $ property ) {
157
+ list ($ id , $ spaceId , $ line , $ name , $ type ) = $ property ;
158
+ if (!array_key_exists ($ spaceId , $ this ->property )) {
159
+ $ this ->property [$ spaceId ] = [];
160
+ $ this ->types [$ spaceId ] = [];
161
+ }
162
+ $ this ->property [$ spaceId ][$ line ] = $ name ;
163
+ $ this ->types [$ spaceId ][$ name ] = $ type ;
164
+ }
165
+ foreach ($ client ->getSpace ('_vindex ' )->select ([], 'primary ' )->getData () as $ index ) {
166
+ list ($ spaceId , $ num , $ name , $ type , $ params , $ properties ) = $ index ;
167
+ if (!array_key_exists ($ spaceId , $ this ->property )) {
168
+ // tarantool space index
169
+ continue ;
170
+ }
171
+ if (!isset ($ this ->indexes [$ spaceId ])) {
172
+ $ this ->indexes [$ spaceId ] = [];
173
+ }
174
+ $ this ->indexes [$ spaceId ][$ num ] = [];
175
+ foreach ($ properties as $ row ) {
176
+ list ($ part , $ type ) = $ row ;
177
+ $ this ->indexes [$ spaceId ][$ num ][] = $ this ->property [$ spaceId ][$ part ];
178
+ }
179
+ }
180
+ foreach ($ this ->property as $ spaceId => $ collection ) {
181
+ ksort ($ collection );
182
+ $ this ->property [$ spaceId ] = $ collection ;
183
+ }
184
+
185
+ }
186
+
187
+ public function toArray ()
188
+ {
189
+ $ this ->collectData ();
190
+
191
+ return [
192
+ 'property ' => $ this ->property ,
193
+ 'indexes ' => $ this ->indexes ,
194
+ 'types ' => $ this ->types ,
195
+ ];
196
+ }
173
197
}
0 commit comments