public static function parseClass($path) { $code = file_get_contents($path); $parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative()); try { $stmts = $parser->parse($code); $class = new CodeGenerator\ClassGenerator(); $class->name = $stmts[0]->name; $class->extends = implode(',', $stmts[0]->extends->parts); foreach ($stmts[0]->stmts as $stmt) { if (get_class($stmt) == 'PhpParser\\Node\\Stmt\\ClassMethod') { $class->addMethod($stmt->name); } } return $class; // $stmts is an array of statement nodes } catch (PhpParser\Error $e) { echo 'Parse Error: ', $e->getMessage(); exit; } }
public function createController($module, $controllerType) { $modulePath = Module::getModulePath($module); $path = $modulePath . '/' . $controllerType . '/' . $module . 'Controller.php'; $class = new CodeGenerator\ClassGenerator(); $class->name = $module . 'Controller'; $class->extends = 'Controller'; $controllerCode = "<?php\n\n" . $class->generate(); Tools::createDir(pathinfo($path, PATHINFO_DIRNAME)); file_put_contents($path, $controllerCode); $config = Config::custom($modulePath . '/generatorHash.php'); $config[$controllerType . '/' . $module . 'Controller.php'] = md5($controllerCode); Config::save($modulePath . '/generatorHash.php', $config); }