Created
December 3, 2014 07:05
-
-
Save harikt/1a2a2b4d3a0e6a00bf57 to your computer and use it in GitHub Desktop.
Fastest way to create di configuration for Aura.Di . Make sure the classes are auto-loadable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"crodas/class-info": "~0.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace HariKT; | |
require __DIR__ . '/vendor/autoload.php'; | |
use crodas\ClassInfo\Definition\TFunction; | |
use RecursiveDirectoryIterator; | |
use RecursiveIteratorIterator; | |
use crodas\ClassInfo\ClassInfo; | |
use ReflectionClass; | |
use Exception; | |
class Dumper | |
{ | |
public function load($path) | |
{ | |
$dir = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS); | |
$iterator = new RecursiveIteratorIterator($dir); | |
$parser = new ClassInfo; | |
$text = ''; | |
foreach ($iterator as $file) { | |
$path = $file->getRealPath(); | |
$parser->parse($path); | |
foreach ($parser->getClasses() as $class) { | |
try { | |
$reflection = new ReflectionClass((string) $class); | |
$method = $reflection->getConstructor(); | |
if ($method) { | |
$parameters = $method->getParameters(); | |
foreach($parameters as $param) { | |
$text .= '$di->params[\'' . (string)$class . '\'][\'' . $param->name . '\'] = $di->lazyNew(\'' . $param->getClass()->name . '\');' . PHP_EOL; | |
} | |
} | |
} catch (Exception $e) { | |
echo $e->getMessage(); | |
} | |
} | |
} | |
echo PHP_EOL; | |
echo $text; | |
} | |
} | |
$dumper = new Dumper(); | |
$dumper->load(__DIR__ . '/src'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eg :
and in
src
folder you havewill output something like
and yes all are lazyNew. Change to lazyGet or something if you need shared instance. But much simpler I guess.