forked from Enalean/ForgeUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerator.php
39 lines (26 loc) · 839 Bytes
/
generator.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
<?php
/*foreach($argv as $arg) {
}*/
$name = $argv[$argc - 1];
$filename = date('YmdHi', $_SERVER['REQUEST_TIME']).'_'.unCapitalize($name).'.php';
$tmpl = file_get_contents(dirname(__FILE__).'/templates/DefaultBucket.tmpl.php');
$tmpl = preg_replace('/%className%/', $name, $tmpl);
// Directory
$dir = date('Y', $_SERVER['REQUEST_TIME']);
if (!is_dir($dir)) {
mkdir($dir);
}
file_put_contents($dir.'/'.$filename, $tmpl);
function unCapitalize($name) {
if (preg_match('%^([A-Z][^A-Z]*)([A-Z].*)%', $name, $matches)) {
$res = strtolower($matches[1]);
if (isset($matches[2])) {
return $res.'_'.unCapitalize($matches[2]);
}
return $res;
} elseif(preg_match('%^([A-Z][^A-Z]*)$%', $name, $matches)) {
return strtolower($matches[1]);
}
return '';
}
?>