FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phpfui/src/PHPFUI/Base.php at master · phpfui/phpfui · GitHub
phpfui
/
phpfui
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phpfui
/
src
/
PHPFUI
/
Base.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
273 lines (229 loc) · 4.8 KB
Breadcrumbs
phpfui
/
src
/
PHPFUI
/
Base.php
Copy path
File metadata and controls
273 lines (229 loc) · 4.8 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
namespace
PHPFUI
;
/**
* Abstract base class for most PHPFUI classes
*
* Overrides string output for easy output and concatination
*/
abstract
class
Base
implements
\Countable, \
PHPFUI
\
Interfaces
\Walkable, \Stringable
{
use
\
PHPFUI
\
Traits
\Walkable;
public
const
DEBUG_SOURCE
=
1
;
private
static
int
$
debug
=
0
;
private
static
bool
$
done
=
false
;
/** @var array<mixed> */
private
array
$
items
= [];
private
static
string
$
response
=
''
;
public
function
__construct
()
{
}
public
function
__clone
()
{
foreach
(
$
this
->
items
as
$
key
=>
$
item
)
{
if
(
\is_object
(
$
item
))
{
$
this
->
items
[
$
key
] =
clone
$
item
;
}
}
}
public
function
__toString
() :
string
{
try
{
return
$
this
->
output
();
}
catch
(
\
Exception
$
e
)
{
return
$
e
->
getMessage
();
}
}
/**
* Base add function. Adds to the end of the current objects
*
* @param mixed $item should be convertable to string
*/
public
function
add
(
mixed
$
item
) :
static
{
if
(
null
!==
$
item
)
{
$
this
->
items
[] =
$
item
;
}
return
$
this
;
}
/**
* Base addAsFirst function. Adds to the front of the current
* object
*
* @param mixed $item should be convertable to string
*/
public
function
addAsFirst
(
mixed
$
item
) :
static
{
if
(
null
!==
$
item
)
{
\array_unshift
(
$
this
->
items
,
$
item
);
}
return
$
this
;
}
/**
* Number of object in this object. Does not count sub objects.
*/
public
function
count
() :
int
{
return
\count
(
$
this
->
items
);
}
/**
* Form is done rendering
*/
public
function
done
(
bool
$
done
=
true
) :
static
{
self
::
$
done
=
$
done
;
return
$
this
;
}
/**
* Gets the current debug setting
*/
public
static
function
getDebug
(
int
$
flags
=
0
) :
int
{
if
(
$
flags
)
{
return
self
::
$
debug
&
$
flags
;
}
return
self
::
$
debug
;
}
/**
* Get the current response
*/
public
function
getResponse
() :
string
{
return
self
::
$
response
;
}
/**
* Returns true if the page needs no more processing
*/
public
function
isDone
() :
bool
{
return
self
::
$
done
;
}
/**
* Add an object in front of existing object
*/
public
function
prepend
(
mixed
$
item
) :
static
{
\array_unshift
(
$
this
->
items
,
$
item
);
return
$
this
;
}
/**
* Set the debug level, 1 or higher is on
*/
public
static
function
setDebug
(
int
$
level
=
0
) :
void
{
if
(
$
level
)
{
self
::
$
debug
|=
$
level
;
}
else
{
self
::
$
debug
=
0
;
}
}
/**
* Sets the page response directly and exits the program
*
* @return never | static
*/
public
function
setRawResponse
(
string
$
response
,
bool
$
asJSON
=
true
) :
static
{
if
(!
$
this
->
isDone
())
{
self
::
$
response
=
$
response
;
$
this
->
done
();
if
(
$
asJSON
)
{
\header
(
'
Content-Type: application/json
'
);
}
}
return
$
this
;
}
/**
* Set a response in the standard format ('reponse' and 'color' array)
* exit will be called after returning the encoded response
*
* @param string $response to return
* @param string $color used for the save button
*
* @return never | static
*/
public
function
setResponse
(
string
$
response
,
string
$
color
=
'
lime
'
) :
static
{
if
(!
$
this
->
isDone
())
{
$
this
->
setRawResponse
(
\json_encode
([
'
response
'
=>
$
response
,
'
color
'
=>
$
color
, ]));
}
return
$
this
;
}
/**
* You must provide a getBody function. It will be called after start and before end.
*/
abstract
protected
function
getBody
() :
string
;
/**
* You must provide a getEnd function. It will be called last on output.
*/
abstract
protected
function
getEnd
() :
string
;
/** @return array<mixed> */
protected
function
getItems
() :
array
{
return
$
this
->
items
;
}
/**
* You must provide a getStart function. It will be called first on output.
*/
abstract
protected
function
getStart
() :
string
;
/**
* Output the object (convert to string)
*
*/
private
function
output
() :
string
{
if
(
$
this
->
isDone
())
{
echo
self
::
$
response
;
exit
();
}
$
output
=
''
;
$
debug
=
self
::
getDebug
(\
PHPFUI
\Session::
DEBUG_HTML
) ?
"\n"
:
''
;
try
{
$
output
.= (
string
)
$
this
->
getStart
();
if
(
$
output
)
{
$
output
.=
$
debug
;
}
foreach
(
$
this
->
items
as
$
item
)
{
$
output
.= (
string
)
$
item
;
if
(
$
item
)
{
$
output
.=
$
debug
;
}
}
$
body
= (
string
)
$
this
->
getBody
();
$
output
.=
$
body
;
if
(
$
body
)
{
$
output
.=
$
debug
;
}
$
end
= (
string
)
$
this
->
getEnd
();
$
output
.=
$
end
;
if
(
$
end
)
{
$
output
.=
$
debug
;
}
}
catch
(
\
Exception
$
e
)
{
$
output
.=
$
e
->
getMessage
();
}
return
$
output
;
}
}
Back
|
FazBrowse Home
|
New Git URL