This repository has been archived by the owner on May 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Quick.php
55 lines (48 loc) · 1.41 KB
/
Quick.php
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
<?php
namespace Cyantree\Grout;
use Cyantree\Grout\Tools\ArrayTools;
use Cyantree\Grout\Tools\StringTools;
use Cyantree\Grout\Tools\VarTools;
class Quick
{
/** @var Quick */
public static $default;
public $defaultEscapingContext = 'html';
public $defaultEcho = false;
public function __construct($defaultEscapingContext = 'html', $defaultEcho = false)
{
$this->defaultEscapingContext = $defaultEscapingContext;
$this->defaultEcho = $defaultEcho;
}
public function e($text, $context = null, $echo = null)
{
if ($context === null) {
$context = $this->defaultEscapingContext;
}
if ($echo === null) {
$echo = $this->defaultEcho;
}
if ($context == 'html') {
$text = StringTools::escapeHtml($text);
} else if ($context == 'js') {
$text = StringTools::escapeJs($text);
} else if ($context == 'url') {
$text = urlencode($text);
}
if ($echo) {
echo $text;
return null;
} else {
return $text;
}
}
public function k($object, $key, $defaultValue = null, $type = null, $typeArgs = null)
{
$data = ArrayTools::get($object, $key, $defaultValue);
if ($type === null) {
return $data;
} else {
return VarTools::prepare($data, $type, $typeArgs);
}
}
}