Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
TemplateGenerator.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\views\engine
;
4
5
use
Ubiquity\utils\base\UString
;
6
17
abstract
class
TemplateGenerator
{
18
19
protected
string
$openVarTag
;
20
protected
string
$closeVarTag
;
21
protected
string
$openExpressionTag
;
22
protected
string
$closeExpressionTag
;
23
protected
string
$safeFilter
;
24
25
abstract
public
function
openBlock
(
string
$name): string;
26
27
abstract
public
function
closeBlock
(): string;
28
29
abstract
public
function
asArray
(array $array): string;
30
31
abstract
public
function
insertVariable
(
string
$name,
bool
$safe =
false
): string;
32
33
abstract
public
function
includeFile
(
string
$filename,
bool
$asVariable =
false
): string;
34
35
abstract
public
function
extendsTemplate
(
string
$templateName,
bool
$asVariable =
false
): string;
36
37
abstract
public
function
foreach
(
string
$arrayName,
string
$value, ?
string
$key =
null
): string;
38
39
abstract
public
function
endForeach
(): string;
40
41
abstract
public
function
condition
(
string
$condition): string;
42
43
abstract
public
function
endCondition
(): string;
44
45
abstract
public
function
getNonce
(): string;
46
47
abstract
public
function
getNonceArray
(): string;
48
49
abstract
public
function
getSelf
(): string;
50
51
abstract
public
function
asVariable
(
string
$var): string;
52
56
public
function
getOpenVarTag
(): string {
57
return $this->openVarTag;
58
}
59
63
public
function
getCloseVarTag
(): string {
64
return $this->closeVarTag;
65
}
66
70
public
function
getOpenExpressionTag
(): string {
71
return $this->openExpressionTag;
72
}
73
77
public
function
getCloseExpressionTag
(): string {
78
return $this->closeExpressionTag;
79
}
80
81
private
function
parseValue
($v) {
82
if
(\is_numeric($v) && gettype($v) !==
'string'
) {
83
$result = $v;
84
} elseif ($v !==
''
&& UString::isBooleanStr($v)) {
85
$result = UString::getBooleanStr($v);
86
} elseif (\is_array($v)) {
87
$result = $this->asArray($v);
88
} elseif (\is_string($v) && UString::isExpression($v)) {
89
$result = \trim($v);
90
}
else
{
91
$result =
"\""
. \str_replace([
'$'
,
'"'
], [
'\$'
,
'\"'
], $v) .
"\""
;
92
}
93
return
$result;
94
}
95
96
protected
function
implodeParameters
(array $parameters): string {
97
$result = [];
98
foreach
($parameters as $param) {
99
$result[] = $this->parseValue($param);
100
}
101
return \implode(
','
, $result);
102
}
103
104
protected
function
insertAssets
(
string
$funcName,
string
$url) {
105
return
$this->openExpressionTag .
"$funcName('"
. $url .
"',"
. $this->getNonceArray() .
")"
. $this->closeExpressionTag;
106
}
107
108
public
function
insertJS
(
string
$url): string {
109
return $this->insertAssets(
'js'
, $url);
110
}
111
112
public
function
insertCSS
(
string
$url): string {
113
return $this->insertAssets(
'css'
, $url);
114
}
115
116
public
function
callFunction
(
string
$funcName, ...$parameters): string {
117
return $this->openExpressionTag .
"$funcName("
. $this->implodeParameters($parameters) .
')'
. $this->closeExpressionTag;
118
}
119
120
}
Ubiquity\utils\base\UString
String utilities.
Definition
UString.php:15
Ubiquity\views\engine\TemplateGenerator
Ubiquity abstract TemplateGenerator class.
Definition
TemplateGenerator.php:17
Ubiquity\views\engine\TemplateGenerator\getNonceArray
getNonceArray()
Ubiquity\views\engine\TemplateGenerator\$openVarTag
string $openVarTag
Definition
TemplateGenerator.php:19
Ubiquity\views\engine\TemplateGenerator\closeBlock
closeBlock()
Ubiquity\views\engine\TemplateGenerator\getCloseExpressionTag
getCloseExpressionTag()
Definition
TemplateGenerator.php:77
Ubiquity\views\engine\TemplateGenerator\implodeParameters
implodeParameters(array $parameters)
Definition
TemplateGenerator.php:96
Ubiquity\views\engine\TemplateGenerator\$safeFilter
string $safeFilter
Definition
TemplateGenerator.php:23
Ubiquity\views\engine\TemplateGenerator\insertCSS
insertCSS(string $url)
Definition
TemplateGenerator.php:112
Ubiquity\views\engine\TemplateGenerator\asVariable
asVariable(string $var)
Ubiquity\views\engine\TemplateGenerator\insertVariable
insertVariable(string $name, bool $safe=false)
Ubiquity\views\engine\TemplateGenerator\extendsTemplate
extendsTemplate(string $templateName, bool $asVariable=false)
Ubiquity\views\engine\TemplateGenerator\endCondition
endCondition()
Ubiquity\views\engine\TemplateGenerator\condition
condition(string $condition)
Ubiquity\views\engine\TemplateGenerator\endForeach
endForeach()
Ubiquity\views\engine\TemplateGenerator\parseValue
parseValue($v)
Definition
TemplateGenerator.php:81
Ubiquity\views\engine\TemplateGenerator\asArray
asArray(array $array)
Ubiquity\views\engine\TemplateGenerator\getOpenExpressionTag
getOpenExpressionTag()
Definition
TemplateGenerator.php:70
Ubiquity\views\engine\TemplateGenerator\$openExpressionTag
string $openExpressionTag
Definition
TemplateGenerator.php:21
Ubiquity\views\engine\TemplateGenerator\callFunction
callFunction(string $funcName,... $parameters)
Definition
TemplateGenerator.php:116
Ubiquity\views\engine\TemplateGenerator\$closeExpressionTag
string $closeExpressionTag
Definition
TemplateGenerator.php:22
Ubiquity\views\engine\TemplateGenerator\getSelf
getSelf()
Ubiquity\views\engine\TemplateGenerator\insertJS
insertJS(string $url)
Definition
TemplateGenerator.php:108
Ubiquity\views\engine\TemplateGenerator\getNonce
getNonce()
Ubiquity\views\engine\TemplateGenerator\includeFile
includeFile(string $filename, bool $asVariable=false)
Ubiquity\views\engine\TemplateGenerator\getOpenVarTag
getOpenVarTag()
Definition
TemplateGenerator.php:56
Ubiquity\views\engine\TemplateGenerator\insertAssets
insertAssets(string $funcName, string $url)
Definition
TemplateGenerator.php:104
Ubiquity\views\engine\TemplateGenerator\openBlock
openBlock(string $name)
Ubiquity\views\engine\TemplateGenerator\getCloseVarTag
getCloseVarTag()
Definition
TemplateGenerator.php:63
Ubiquity\views\engine\TemplateGenerator\$closeVarTag
string $closeVarTag
Definition
TemplateGenerator.php:20
Ubiquity\views\engine
Definition
TemplateGenerator.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity-dev
src
Ubiquity
views
engine
TemplateGenerator.php
Generated on Sun Dec 10 2023 15:04:09 for
Ubiquity
by
doxygen
1.9.8