1 #!/usr/bin/php5
2 <?php
4 /* Function to include all class_ files starting at a given directory base */
5 function get_classes($folder= ".")
6 {
7 static $base_dir= "";
8 static $result= array();
10 if ($base_dir == ""){
11 $base_dir= getcwd();
12 }
14 $currdir=getcwd();
15 if ($folder){
16 chdir("$folder");
17 }
19 $dh = opendir(".");
20 while(false !== ($file = readdir($dh))){
22 if (preg_match("/.*\.svn.*/", $file) ||
23 preg_match("/.*smarty.*/i",$file) ||
24 preg_match("/.*\.tpl.*/",$file) ||
25 ($file==".") ||($file =="..")){
26 continue;
27 }
29 /* Recurse through all "common" directories */
30 if (is_dir($file)){
31 get_classes($file);
32 continue;
33 }
35 /* Only take care about .inc and .php files... */
36 if (!(preg_match('/\.php$/', $file) || preg_match('/\.inc$/', $file))){
37 continue;
38 }
40 /* Include existing class_ files */
41 $contents= file($file);
42 foreach($contents as $line){
43 $line= chop($line);
44 if (preg_match('/^\s*class\s*\w.*$/', $line)){
45 $class= preg_replace('/^\s*class\s*(\w+).*$/', '\1', $line);
46 $result[$class]= preg_replace("%$base_dir/%", "", "$currdir/$folder/$file");
47 }
48 }
49 }
51 closedir($dh);
52 chdir($currdir);
54 return ($result);
55 }
57 $class_mapping= get_classes();
58 $filename= "include/autoload-data.inc";
60 /* Sanity checks */
61 if (is_writable($filename)) {
63 if (!$handle= fopen($filename, 'w')) {
64 echo "Cannot open file \"$filename\" - aborted\n";
65 exit (1);
66 }
68 } else {
69 echo "File \"$filename\" is not writable - aborted\n";
70 exit (2);
71 }
73 fwrite ($handle, "<?php\n\$class_mapping= array(\n");
74 foreach ($class_mapping as $key => $value){
75 fwrite ($handle, " \"$key\" => \"$value\",\n");
76 }
77 fwrite ($handle, ");\n?>");
79 fclose($handle);
81 ?>