/** * @param string $file * * @return Configuration */ private function readConfiguration($file) { $definition = Neon::decode(file_get_contents($file)); $dir = dirname($file); assert(isset($definition['namespace'])); assert(isset($definition['output'])); $this->constants = isset($definition['constants']) ? $definition['constants'] : []; $this->values = isset($definition['values']) ? $definition['values'] : []; Helper::rmDirRec($dir . DIRECTORY_SEPARATOR . $definition['output'], true); return new Configuration($definition['output'], $definition['namespace'], $dir); }
/** * @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 $versions * @param $actualDir * * @return array */ private function loadCsvVersions($versions, $actualDir) { $result = []; foreach ($versions as $name => $version) { $dir = new DirectoryIterator($actualDir . DIRECTORY_SEPARATOR . $version); foreach ($dir as $file) { if (!$file->isDir()) { $tableName = $file->getBasename(".csv"); $result[$name][$tableName] = Helper::readCsvValues($file->getRealPath()); } } } return $result; }