forked from dkarvounaris/PHPStorm-CC-PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.php
41 lines (35 loc) · 1.59 KB
/
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
40
<?php
$output_folder = 'CC-helpers';
function readFilesRecursively($folder, $output_folder) {
if (!file_exists($output_folder)) {
mkdir($output_folder);
}
$array = explode('/', $folder);
$base = array_pop($array);
$files = scandir($folder);
foreach($files as $key => $value){
if ($value == '.' || $value == '..' || $value == 'index.php')
continue;
if(!is_dir($folder. DIRECTORY_SEPARATOR .$value)){
$class_name = str_replace(".php","",$value);
//echo $folder. DIRECTORY_SEPARATOR .$value."\n";
$file_content = file_get_contents($folder. DIRECTORY_SEPARATOR .$value);
if (stristr($file_content, 'class '.$class_name."Core") !== false) {
$abstract = '';
if (stristr($file_content, 'abstract class '.$class_name."Core") !== false) {
$abstract = 'abstract ';
}
$code = "<?php\n\n" .
$abstract . "class ".$class_name." extends ".$class_name."Core {}";
if (!file_exists($output_folder. "/" . $base )) {
mkdir($output_folder. "/" . $base );
}
file_put_contents($output_folder . "/" . $base . "/" . $value, $code);
}
} else if(is_dir($folder. DIRECTORY_SEPARATOR .$value)) {
readFilesRecursively($folder. DIRECTORY_SEPARATOR .$value, $output_folder."/".$base);
}
}
}
readFilesRecursively(dirname(__FILE__).'/classes', $output_folder);
readFilesRecursively(dirname(__FILE__).'/controllers', $output_folder);