-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake.php
More file actions
109 lines (90 loc) · 2.91 KB
/
make.php
File metadata and controls
109 lines (90 loc) · 2.91 KB
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
<?php
// run this after library changes to regenerate support files
//require 'error_handler.php';
function make_constructors()
{
// update the convenience function list from classes
$output='<'.'?php'."\n// generated by make.php - do not edit\n";
$output.='
/**
* convenience constructor functions
* @package poof
*/
';
// scan files in the class directory
$d=dir("class");
$files=array();
while ($file=$d->read())
$files[]=$file;
$d->close();
// scan files in the theme/default/class directory
$d=dir("theme/default/class");
while ($file=$d->read())
$files[]=$file;
$d->close();
sort($files);
foreach ($files as $file) {
//echo "Searching '$file'\n";
// skip anything that isn't an autoload-able class
if (!preg_match('/^(.*)\.php$/',$file,$match)) {
if ($file[0]!='.') print("WARNING: skipping $file\n");
continue;
}
$class=$match[1];
//print($class."\n");
if (file_exists("theme/default/class/$file"))
$contents=file_get_contents("theme/default/class/$file");
else
$contents=file_get_contents("class/$file");
$singleton=false;
if (strstr($contents,"extends pfSingleton"))
$singleton=true;
// locate the construct function to get args - and warn if not found
if (!preg_match('/function\s+__construct\((.*)\)/',$contents,$match)) {
print("$class: __construct() not found!\n");
continue;
}
$args=$match[1];
// break apart the argument list and remove default assignments
$pairs=explode(',',$args);
foreach ($pairs as &$pair) {
$exp=explode('=',$pair);
$pair=$exp[0];
}
$justargs=implode(',',$pairs);
if ($singleton)
$output.="
function $class($args)
{
if (empty(\$GLOBALS['$class']))
return \$GLOBALS['$class']=new $class($justargs);
else
return \$GLOBALS['$class']($justargs);
}
";
else
$output.="
function $class($args)
{
\$that=new $class($justargs);
return \$that;
}
";
preg_match_all('/POOF_CONSTRUCT:\s+(\S+)/',$contents,$matches,PREG_SET_ORDER);
foreach ($matches as $match) {
$alternate=strtolower($match[1]);
//print("Adding alternate $alternate for $class\n");
$output.="
function $alternate($args)
{
\$that=new $class($justargs);
return \$that;
}
";
}
}
file_put_contents("class_constructors.php",$output);
}
// make all the components needed
make_constructors();
// system("phpdoc -d . -i 'demo/*' -i 'tests/*' -t docs");