FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
data-repository/src/ReadRepository.php at master · g4code/data-repository · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
g4code
/
data-repository
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
0
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
data-repository
/
src
/
ReadRepository.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
185 lines (158 loc) · 5.27 KB
Breadcrumbs
data-repository
/
src
/
ReadRepository.php
Copy path
File metadata and controls
185 lines (158 loc) · 5.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
namespace
G4
\
DataRepository
;
use
G4
\
ValueObject
\
Dictionary
;
class
ReadRepository
{
const
EMPTY_VALUE
=
'
EMPTY_VALUE
'
;
/**
* @var StorageContainer
*/
private
$
storageContainer
;
/**
* @var SimpleRepositoryDataResponse|DataRepositoryResponse
*/
private
$
response
;
/*
* @return RepositoryQuery
*/
private
$
query
;
/**
* Repository constructor.
* @param StorageContainer $storageContainer
*/
public
function
__construct
(
StorageContainer
$
storageContainer
)
{
$
this
->
storageContainer
=
$
storageContainer
;
}
public
function
read
(
RepositoryQuery
$
query
)
{
$
this
->
query
=
$
query
;
return
$
this
->
readFromIdentityMap
()
->
readFromRussianDoll
()
->
readFromDataMapper
()
->
getResponse
();
}
public
function
readNoCache
(
RepositoryQuery
$
query
)
{
$
this
->
query
=
$
query
;
return
$
this
->
readFromDataMapper
(
false
)
->
getResponse
();
}
public
function
simpleQuery
(
RepositoryQuery
$
query
)
{
$
this
->
query
=
$
query
;
return
$
this
->
execSimpleQuery
()
->
getSimpleResponse
();
}
private
function
getSimpleResponse
()
{
return
$
this
->
hasSimpleResponse
()
?
$
this
->
response
: (
new
RepositoryResponseFactory
())->
createSimpleEmptyResponse
();
}
private
function
hasSimpleResponse
()
{
return
$
this
->
response
instanceof
SimpleDataRepositoryResponse;
}
private
function
getResponse
()
{
return
$
this
->
hasResponse
()
?
$
this
->
response
: (
new
RepositoryResponseFactory
())->
createEmptyResponse
();
}
private
function
hasResponse
()
{
return
$
this
->
response
instanceof
DataRepositoryResponse;
}
private
function
readFromIdentityMap
()
{
if
(
$
this
->
storageContainer
->
hasIdentityMap
() && !
$
this
->
hasResponse
()) {
$
data
=
$
this
->
storageContainer
->
getIdentityMap
()->
get
(
$
this
->
query
->
getIdentityMapKey
());
if
(
$
data
===
self
::
EMPTY_VALUE
) {
$
this
->
response
= (
new
RepositoryResponseFactory
())->
createEmptyResponse
();
return
$
this
;
}
if
(
$
this
->
hasNonEmptyData
(
$
data
)) {
$
this
->
response
= (
new
RepositoryResponseFactory
())->
createFromArray
(
new
Dictionary
(
$
data
));
}
}
return
$
this
;
}
private
function
readFromRussianDoll
()
{
if
(
$
this
->
storageContainer
->
getRussianDoll
() && !
$
this
->
hasResponse
()) {
$
data
=
$
this
->
storageContainer
->
getRussianDoll
()
->
setKey
(
$
this
->
query
->
getRussianDollKey
())
->
fetch
();
if
(
$
data
===
self
::
EMPTY_VALUE
) {
$
this
->
saveIdentityMap
(
$
data
);
$
this
->
response
= (
new
RepositoryResponseFactory
())->
createEmptyResponse
();
return
$
this
;
}
if
(
$
this
->
hasNonEmptyData
(
$
data
)) {
$
this
->
saveIdentityMap
(
$
data
);
$
this
->
response
= (
new
RepositoryResponseFactory
())->
createFromArray
(
new
Dictionary
(
$
data
));
}
}
return
$
this
;
}
private
function
readFromDataMapper
(
$
saveToCache
=
true
)
{
if
(
$
this
->
storageContainer
->
hasDataMapper
() && !
$
this
->
hasResponse
()) {
$
dataMapper
=
$
this
->
storageContainer
->
getDataMapper
();
$
rawData
=
$
this
->
query
->
hasCustomQuery
()
?
$
dataMapper
->
query
(
$
this
->
query
->
getCustomQuery
())
:
$
dataMapper
->
find
(
$
this
->
query
->
getIdentity
());
$
response
= (
new
RepositoryResponseFactory
())->
create
(
$
rawData
);
if
(
$
saveToCache
) {
$
data
=
self
::
EMPTY_VALUE
;
if
(
$
response
->
hasData
()) {
$
data
= (
new
RepositoryResponseFormatter
(
$
response
))->
format
();
}
$
this
->
saveRussianDoll
(
$
data
)
->
saveIdentityMap
(
$
data
);
}
$
this
->
response
=
$
response
;
}
return
$
this
;
}
private
function
execSimpleQuery
()
{
if
(
$
this
->
storageContainer
->
hasDataMapper
() && !
$
this
->
hasSimpleResponse
() &&
$
this
->
query
->
hasCustomQuery
()) {
$
dataMapper
=
$
this
->
storageContainer
->
getDataMapper
();
$
rawData
=
$
dataMapper
->
simpleQuery
(
$
this
->
query
->
getCustomQuery
());
$
this
->
response
=
$
rawData
? (
new
RepositoryResponseFactory
())->
createSimple
(
$
rawData
) :
null
;
}
return
$
this
;
}
private
function
saveIdentityMap
(
$
data
)
{
if
(
$
this
->
storageContainer
->
hasIdentityMap
()) {
$
this
->
storageContainer
->
getIdentityMap
()
->
set
(
$
this
->
query
->
getIdentityMapKey
(),
$
data
);
}
return
$
this
;
}
private
function
saveRussianDoll
(
$
data
)
{
if
(
$
this
->
storageContainer
->
hasRussianDoll
()) {
$
this
->
storageContainer
->
getRussianDoll
()
->
setKey
(
$
this
->
query
->
getRussianDollKey
())
->
write
(
$
data
);
}
return
$
this
;
}
private
function
hasNonEmptyData
(
$
data
)
{
return
!
empty
(
$
data
) &&
is_array
(
$
data
);
}
}
Back
|
FazBrowse Home
|
New Git URL