-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.php
80 lines (70 loc) · 1.6 KB
/
code.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
<?php
/**
Development tools for the PHP Fat-Free Framework
The contents of this file are subject to the terms of the GNU General
Public License Version 3.0. You may not use this file except in
compliance with the license. Any of the license terms and conditions
can be waived if you get permission from the copyright holder.
Copyright (c) 2009-2012 F3::Factory
Bong Cosca <[email protected]>
@package Code
@version 2.0.12
**/
//! Development tools
class Code extends Base {
/**
Highlight syntax in string
@param $str string
@param $php bool
@public
**/
static function highlight($str,$php=TRUE) {
return $php?
highlight_string($str,TRUE):
preg_replace('/<\?php |\?>/s','',
highlight_string('<?php '.$str,TRUE));
}
/**
Return HTML-friendly dump of PHP expression
@return string
@param $expr mixed
@param $echo bool
@param $highlight bool
@public
**/
static function dump($expr,$echo=TRUE,$highlight=TRUE) {
ob_start();
var_dump($expr);
$out=ob_get_clean();
$out=$highlight?
self::highlight($out,FALSE):('<code>'.$out.'</code>'."\n");
if ($echo)
echo $out;
else
return $out;
}
/**
Convert snakecase string to camelcase
@return string
@param $str string
@public
**/
static function camel($str) {
return preg_replace_callback(
'/_(\w)/',
function($match) {
return strtoupper($match[1]);
},
$str
);
}
/**
Convert camelcase string to snakecase
@return string
@param $str string
@public
**/
static function snake($str) {
return strtolower(preg_replace('/[[:upper:]]/','_\0',$str));
}
}