Created
October 13, 2016 19:52
-
-
Save WyriHaximus/fda4a3300175a7c83878467dff9064d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| use Composer\Autoload\ClassLoader; | |
| use PhpParser\BuilderFactory; | |
| use PhpParser\ParserFactory; | |
| use RuntimeException; | |
| final class Generator | |
| { | |
| /** | |
| * @var BuilderFactory | |
| */ | |
| private $factory; | |
| /** | |
| * @var Parser | |
| */ | |
| private $parser; | |
| /** | |
| * @var ClassLoader | |
| */ | |
| private $classLoader; | |
| public function __construct() | |
| { | |
| $this->factory = new BuilderFactory(); | |
| $this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); | |
| $this->classLoader = $this->locateClassloader(); | |
| } | |
| private function locateClassloader() | |
| { | |
| foreach ([ | |
| dirname(__DIR__) . DS . 'vendor' . DS . 'autoload.php', | |
| dirname(dirname(dirname(__DIR__))) . DS . 'autoload.php', | |
| ] as $path) { | |
| if (file_exists($path)) { | |
| return require $path; | |
| } | |
| } | |
| throw new RuntimeException('Unable to locate class loader'); | |
| } | |
| public function generate($class) | |
| { | |
| $fileName = $this->classLoader->findFile($tableClass); | |
| $ast = $this->parser->parse(file_get_contents($fileName)); | |
| var_export($ast);die(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment