forked from gabordemooij/redbean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space.php
executable file
·51 lines (38 loc) · 1.12 KB
/
space.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
<?php
/*
* RedBean NameSpace Utility (experimental)
* Written by Gabor de Mooij (c) copyright 2011
* Licensed New BSD
*/
echo "\n Namespace Utility for RedBeanPHP (experimental). ";
if (($_SERVER["argc"])!==2) {
die("\n Usage php space.php [namespace] \n\n");
}
if (!file_exists("rb.php")) {
die("\n could not find rb.php, must be in same directory. ");
}
$n = $_SERVER["argv"][1];
if (preg_match("/\w+/",$n)) {
echo "\n selected namespace: $n ";
}
else {
die("\n namespace contains illegal characters. ");
}
$code = file_get_contents("rb.php");
//prefix
$code = "<?php
namespace $n;
?>".$code;
$natObjects = array(
"IteratorAggregate","ArrayAccess","RuntimeException","LogicException","Exception","PDO","ArrayIterator","Countable"
);
foreach($natObjects as $natObj) {
$code = str_replace(" ".$natObj,"\\$natObj",$code);
$code = str_replace("(".$natObj,"(\\$natObj",$code);
$code = str_replace(",".$natObj,",\\$natObj",$code);
$code = str_replace(";".$natObj,";\\$natObj",$code);
$code = str_replace("{".$natObj,"{\\$natObj",$code);
}
//save code
file_put_contents("rbn.php", $code);
die("\n output has been stored in rbn.php \n");