-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.php
117 lines (105 loc) · 2.23 KB
/
Utils.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
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
<?php
namespace SnooPHP\Utils;
use SnooPHP\Http\Request;
use SnooPHP\Vue\Component;
/**
* Set of utility methods
*
* @author sneppy
*/
class Utils
{
/**
* Include view
*
* @deprecated v1.0.0
*
* @param string $name view name
* @param array $args arguments to expose
* @param Request $request request if differs from current request
*
* @return bool
*/
public static function view($name, array $args, Request $request = null)
{
$request = $request ?: Request::current();
$fullPath = path("views")."/{$name}.php";
if (file_exists($fullPath))
{
include $fullPath;
return true;
}
return false;
}
/**
* Compile style content using specified css preprocessor
*
* @deprecated v1.0.0
*
* @param string $content content to compile
* @param string $lang css preprocessor (default to vanilla css, no process)
*
* @return string compiled content
*/
public static function compileStyle($content, $lang = "vanilla")
{
return compile_style($content, $lang);
}
/**
* Minify javascript using uglify-js if available
*
* @param string $content content to minify
*/
public static function minifyJs($content)
{
if (!empty(`which uglifyjs`))
return `echo "$content" | uglifyjs --compress --mangle --mangle-props`;
return $content;
}
/**
* Get or set session errors
*
* @param string $err error string
*/
public static function errors($err = null)
{
// Start session
if (!isset($_SESSION)) session_start();
if ($err)$_SESSION["errors"][] = $err;
return isset($_SESSION["errors"]) ? $_SESSION["errors"] : [];
}
/**
* Flush all errors
*/
public static function flushErrors()
{
if (isset($_SESSION)) unset($_SESSION["errors"]);
}
/**
* Get path relative to public folder
*
* @param string $absolutePath absolute path
*
* @return string|bool
*/
public static function publicPath($absolutePath)
{
$publicPath = path("public");
if (preg_match("@^{$publicPath}(.*)$@", $absolutePath, $matches))
return $matches[1];
return false;
}
/**
* Parse string as value
*
* @deprecated v1.0.0
*
* @param string $val string to parse
*
* @return mixed
*/
public static function parseValue($val)
{
return parse_string($val);
}
}