-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpc-ide-helper.php
74 lines (65 loc) · 2.85 KB
/
pc-ide-helper.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* @package pcIdeHelper
* @version 1.1.0
* @url https://github.com/proudcommerce/oxid-ide-modulehelper
*
* @author Stefan Moises <[email protected]>
* @author Tobias Merkl <[email protected]>
*
* Script to generate a .module-helper.php file in the OXID root dir.
* The generated file contains all module namespaces and extensions for your IDE to use for reference.
* This way, the IDE should find the extended classes for every class that uses OXIDs
* custom "_parent" logic to extend OXID classes.
*/
if (PHP_SAPI != 'cli') {
die("Only cli execution allowed!");
}
require_once dirname(__FILE__) . "/../bootstrap.php";
function _processMetadata($sPath)
{
$str = '';
try {
include $sPath;
if (isset($aModule["extend"]) && count($aModule["extend"])) {
$aNamespaces = [];
foreach ($aModule["extend"] as $sParent => $sPathToModule) {
// no valid namespaced class?
if (strpos($sPathToModule, '\\') === false) {
continue;
}
// split at last backslash to get namespace and classname
$namespace = substr($sPathToModule, 0, strrpos($sPathToModule, '\\'));
$classname = substr($sPathToModule, strrpos($sPathToModule, '\\') + 1);
// new namespace?
if (!isset($aNamespaces[ $namespace ])) {
$aNamespaces[ $namespace ] = [];
}
$sFakeParent = $classname . "_parent";
$aNamespaces[ $namespace ][ $sFakeParent ] = "\\" . $sParent;
}
// now generate string
foreach ($aNamespaces as $sNameSpace => $aClasses) {
$str .= "\n\nnamespace {$sNameSpace};";
foreach ($aClasses as $sClass => $sParent) {
$str .= "\nclass {$sClass} extends {$sParent} {}";
}
}
}
} catch (\Exception $ex) {
echo "\nCould not include file '$sPath': " . $ex->getMessage();
}
return $str;
}
$modulePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'modules';
$dir = new RecursiveDirectoryIterator($modulePath);
$iter = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($iter, '/\/metadata\.php$/i', RecursiveRegexIterator::GET_MATCH);
$str = "<?php\n/*\n" . date('Y-m-d H:i:s') . " - auto-generated file, do not edit! \nhttps://github.com/proudcommerce/oxid-ide-modulehelper\n*/\n";
foreach ($files as $name => $file) {
$str .= _processMetadata($name);
}
// write to file
$helperFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '.module-helper.php';
file_put_contents($helperFile, $str);
echo "\nDone, please check the generated file at " . str_replace('source/bin/../../', '', $helperFile) . "\n";