-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflector.php
58 lines (47 loc) · 1.7 KB
/
reflector.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
<?php
use \Zend\Loader\StandardAutoloader;
use \Zend\Code\Reflection\FileReflection;
use \Zend\Code\Generator\MethodGenerator;
// Ensure your include path includes Zend Framework 2
set_include_path('C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework2\library');
require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new StandardAutoloader(array('autoregister_zf' => true));
$loader->registerNamespace('eCommunities\CodeHintAggregator', __DIR__);
$loader->register();
// Additional Application Specific Autoloaders
if (is_dir(__DIR__.'/loaders')) {
$loaders = scandir(__DIR__.'/loaders');
foreach ($loaders as $loader) {
if(strtolower(substr($loader, -4)) == '.php') {
include(__DIR__.'/loaders/'.$loader);
}
}
}
$file = $_REQUEST['file'];
include_once $file;
$reflection = new FileReflection($file);
foreach ($reflection->getClasses() as $class) {
$namespace = $class->getNamespaceName();
$className = $class->getShortName();
// Open Namespace
echo ($namespace ? 'namespace '.$namespace.' { '.PHP_EOL.PHP_EOL : NULL);
// Open Class
echo 'class '. $className. ' { '.PHP_EOL.PHP_EOL;
// TODO: Add CONST support
// TODO: Add public \ protected parameter support
foreach ($class->getMethods() as $methodReflection) {
$method = MethodGenerator::fromReflection($methodReflection);
$docblock = $method->getDocblock();
if ($docblock) {
echo $docblock->generate();
}
$params = implode(', ', array_map(function($item) {
return $item->generate();
}, $method->getParameters()));
echo 'public function '.$method->getName() . '(' . $params . ') { }'.PHP_EOL.PHP_EOL;
}
// Close Class
echo '} '.PHP_EOL.PHP_EOL;
// Close Namespace
echo ($namespace ? '} '.PHP_EOL.PHP_EOL : NULL);
}