Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
910b0ec9
Commit
910b0ec9
authored
10 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
page class: php8 only; added variable types; short array syntax
parent
43b5d42e
No related branches found
No related tags found
1 merge request
!66
php8 only; added variable types; short array syntax; remove glyphicons
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
public_html/deployment/classes/page.class.php
+86
-67
86 additions, 67 deletions
public_html/deployment/classes/page.class.php
with
86 additions
and
67 deletions
public_html/deployment/classes/page.class.php
+
86
−
67
View file @
910b0ec9
<?php
/**
* PIMPED APACHE-STATUS
* Page class
* Render output page by replacing placeholders
*
* @package pimped_apache_status
* origin is from PIMPED APACHE-STATUS
*
* @author Axel Hahn
*
* 2024-08-23 v1.1 Axel Hahn php8 only; added variable types; short array syntax
*/
class
Page
{
class
Page
{
/**
*
o
utput type of content
* @var
array
*
O
utput type of content
* @var
string
*/
private
$sType
=
'html'
;
private
string
$sType
=
'html'
;
/**
*
a
rray of strings for http response header
*
A
rray of strings for http response header
* @var array
*/
private
$aResponseHeader
=
array
()
;
private
array
$aResponseHeader
=
[]
;
/**
* Replacements in the template
* @var array
*/
private
$aReplace
=
array
(
private
array
$aReplace
=
[
'{{HEADER}}'
=>
''
,
'{{CONTENT}}'
=>
''
,
'{{FOOTER}}'
=>
''
,
'{{JSONREADY}}'
=>
''
,
)
;
]
;
/**
* constructor (it does nothing)
* @return boolean (true)
* Constructor
*/
public
function
__construct
()
{
public
function
__construct
()
{
$this
->
setOutputtype
();
return
true
;
}
/**
*
w
rap on document ready instructions in jQuery style
* @return
type
*
W
rap on document ready instructions in jQuery style
* @return
string
*/
private
function
_finalizeJsOnReady
()
{
private
function
_finalizeJsOnReady
():
string
{
return
$this
->
aReplace
[
"
{
{JSONREADY}
}
"
]
=
'
<script>
$(document).ready(function() {
...
...
@@ -60,43 +63,48 @@ class Page {
// ----------------------------------------------------------------------
/**
*
g
et current page content
* @return string
*
G
et current page content
* @return string
HTML code
*/
public
function
getContent
()
{
public
function
getContent
():
string
{
return
$this
->
aReplace
[
'{{CONTENT}}'
];
}
/**
*
g
et current footer
* @return
type
*
G
et current footer
* @return
string
*/
public
function
getFooter
()
{
public
function
getFooter
():
string
{
return
$this
->
aReplace
[
'{{FOOTER}}'
];
}
/**
*
g
et current header in response body
* @return
type
*
G
et current header in response body
* @return
string
*/
public
function
getHeader
()
{
public
function
getHeader
():
string
{
return
$this
->
aReplace
[
'{{HEADER}}'
];
}
/**
*
g
et on ready javascript instructions
* @return
type¨
*
G
et on ready javascript instructions
* @return
string
*/
public
function
getJsOnReady
()
{
public
function
getJsOnReady
():
string
{
return
$this
->
aReplace
[
'{{JSONREADY}}'
];
}
/**
*
g
et output type
*
G
et output type
* @return string
*/
public
function
getOutputtype
()
{
public
function
getOutputtype
()
{
return
$this
->
sType
;
}
...
...
@@ -105,12 +113,14 @@ class Page {
// ----------------------------------------------------------------------
/**
*
a
dd javascript for on ready execution
*
A
dd javascript for on ready execution
* @param string $s javascript code
* @return bool
ean
* @return bool
*/
public
function
addJsOnReady
(
$s
)
{
return
$this
->
aReplace
[
'{{JSONREADY}}'
]
.
=
$s
;
public
function
addJsOnReady
(
string
$s
):
string
{
$this
->
aReplace
[
'{{JSONREADY}}'
]
.
=
$s
;
return
true
;
}
/**
...
...
@@ -118,67 +128,78 @@ class Page {
* @param string $s
* @return boolean
*/
public
function
addResponseHeader
(
$s
)
{
return
$this
->
aResponseHeader
[]
=
$s
;
public
function
addResponseHeader
(
string
$s
)
{
$this
->
aResponseHeader
[]
=
$s
;
return
true
;
}
/**
*
s
et html body; it replaces old content
*
S
et html body; it replaces old content
* @param string $s html code
* @return boolean
*/
public
function
setContent
(
$s
)
{
return
$this
->
aReplace
[
'{{CONTENT}}'
]
=
$s
;
public
function
setContent
(
string
$s
):
bool
{
$this
->
aReplace
[
'{{CONTENT}}'
]
=
$s
;
return
true
;
}
/**
*
s
et footer in html body; it replaces old content
*
S
et footer in html body; it replaces old content
* @param string $s html code
* @return boolean
*/
public
function
setFooter
(
$s
)
{
return
$this
->
aReplace
[
'{{FOOTER}}'
]
=
$s
;
public
function
setFooter
(
string
$s
):
bool
{
$this
->
aReplace
[
'{{FOOTER}}'
]
=
$s
;
return
true
;
}
/**
*
s
et html header; it replaces old content
*
S
et html header; it replaces old content
* @param string $s html code
* @return boolean
*/
public
function
setHeader
(
$s
)
{
return
$this
->
aReplace
[
'{{HEADER}}'
]
=
$s
;
public
function
setHeader
(
string
$s
):
bool
{
$this
->
aReplace
[
'{{HEADER}}'
]
=
$s
;
return
true
;
}
/**
*
s
et javascript code on ready; it replaces old content
*
S
et javascript code on ready; it replaces old content
* @param string $s javascript code
* @return boolean
*/
public
function
setJsOnReady
(
$s
)
{
return
$this
->
aReplace
[
'{{JSONREADY}}'
]
=
$s
;
public
function
setJsOnReady
(
string
$s
):
bool
{
$this
->
aReplace
[
'{{JSONREADY}}'
]
=
$s
;
return
true
;
}
/**
*
s
et output type of response
*
S
et output type of response
* @param string $sOutputType
* @return boolean
*/
public
function
setOutputtype
(
$sOutputType
=
'html'
)
{
return
$this
->
sType
=
$sOutputType
;
public
function
setOutputtype
(
string
$sOutputType
=
'html'
):
bool
{
$this
->
sType
=
$sOutputType
;
return
true
;
}
// ----------------------------------------------------------------------
// OUTPUT
// ----------------------------------------------------------------------
/**
*
s
end http reponse headers and built the response body
* @return
type
*
S
end http reponse headers and built the response body
* @return
string
*/
public
function
render
()
{
$aS
=
array
();
// search
$aR
=
array
();
// replace
public
function
render
():
string
{
$aS
=
[];
// search
$aR
=
[];
// replace
$this
->
_finalizeJsOnReady
();
...
...
@@ -190,12 +211,12 @@ class Page {
$sTemplate
=
false
;
$sTplFile
=
dirname
(
__FILE__
)
.
"/"
.
$this
->
sType
.
".tpl.php"
;
if
(
!
file_exists
(
$sTplFile
))
{
die
(
"ERROR: template for type "
.
$this
->
sType
.
" was not found:
$sTplFile
"
);
throw
new
Exception
(
"ERROR: template for type "
.
$this
->
sType
.
" was not found:
$sTplFile
"
);
}
$sTemplate
=
file_get_contents
(
$sTplFile
);
if
(
!
$sTemplate
)
{
die
(
"ERROR: template file
$sTplFile
is empty or could not be read."
);
throw
new
Exception
(
"ERROR: template file
$sTplFile
is empty or could not be read."
);
}
foreach
(
$this
->
aResponseHeader
as
$sHeader
)
{
...
...
@@ -205,5 +226,3 @@ class Page {
}
}
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment