/** * @param string $path */ public function generateFromNeonFile($path) { $definition = Neon::decode(file_get_contents($path)); assert(isset($definition['class'])); assert(isset($definition['type'])); assert($definition['type'] === 'in-place'); $data = $definition['data']; $output = $this->configuration->getDir() . DIRECTORY_SEPARATOR . $this->configuration->getOutputFolder() . DIRECTORY_SEPARATOR . $definition['class'] . '.php'; $consts = Helper::createStringConstants($data); $node = $this->createClassFromData($definition['class'], $this->configuration->getNamespace(), $consts); $prettyPrinter = new PrettyPrinter\Standard(); file_put_contents($output, $prettyPrinter->prettyPrintFile([$node])); }
/** * @param array $definition * @param string $className * @param array $keys * * @return array|PhpParser\Node\Const_[] */ private function createKeyConstants(array $definition, $className, array $keys) { $constants = Helper::createStringConstants($keys); $factory = new BuilderFactory(); $classNode = $factory->namespace($this->getNamespace($definition, 'Keys'))->addStmt($factory->class($className)->addStmts($constants))->getNode(); $addFolder = null; if (isset($definition['addNamespace'])) { $addFolder = implode(DIRECTORY_SEPARATOR, explode('\\', $definition['addNamespace'] . '\\' . 'Keys')); } else { $addFolder = 'Keys'; } $this->saveGeneratedFile($this->getOutputPath($className, $addFolder), $classNode); return $constants; }