/** * Print files * * @param File[] $files * @param string $directory */ public function printFiles($files, $directory) { foreach ($files as $file) { if (!file_exists(dirname($file->getFilename()))) { mkdir(dirname($file->getFilename()), 0755, true); } file_put_contents($file->getFilename(), $this->prettyPrinter->prettyPrintFile([$file->getNode()])); } if ($this->fixer !== null) { $config = Config::create()->setRiskyAllowed(true)->setRules(array('@Symfony' => true, 'empty_return' => false, 'concat_without_spaces' => false, 'double_arrow_multiline_whitespaces' => false, 'unalign_equals' => false, 'unalign_double_arrow' => false, 'align_double_arrow' => true, 'align_equals' => true, 'concat_with_spaces' => true, 'newline_after_open_tag' => true, 'ordered_use' => true, 'phpdoc_order' => true, 'short_array_syntax' => true))->finder(DefaultFinder::create()->in($directory)); $resolver = new ConfigurationResolver(); $resolver->setDefaultConfig($config); $resolver->resolve(); $this->fixer->fix($config); } }
public function generate($schemaFilePath, $name, $namespace, $directory) { $context = $this->createContext($schemaFilePath, $name, $namespace, $directory); if (!file_exists($directory . DIRECTORY_SEPARATOR . 'Model')) { mkdir($directory . DIRECTORY_SEPARATOR . 'Model', 0755, true); } if (!file_exists($directory . DIRECTORY_SEPARATOR . 'Normalizer')) { mkdir($directory . DIRECTORY_SEPARATOR . 'Normalizer', 0755, true); } $prettyPrinter = new Standard(); $modelFiles = $this->modelGenerator->generate($context->getRootReference(), $name, $context); $normalizerFiles = $this->normalizerGenerator->generate($context->getRootReference(), $name, $context); $generated = []; foreach ($modelFiles as $file) { $generated[] = $file->getFilename(); file_put_contents($file->getFilename(), $prettyPrinter->prettyPrintFile([$file->getNode()])); } foreach ($normalizerFiles as $file) { $generated[] = $file->getFilename(); file_put_contents($file->getFilename(), $prettyPrinter->prettyPrintFile([$file->getNode()])); } if ($this->fixer !== null) { $config = Config::create()->setRiskyAllowed(true)->setRules(array('@Symfony' => true, 'empty_return' => false, 'concat_without_spaces' => false, 'double_arrow_multiline_whitespaces' => false, 'unalign_equals' => false, 'unalign_double_arrow' => false, 'align_double_arrow' => true, 'align_equals' => true, 'concat_with_spaces' => true, 'newline_after_open_tag' => true, 'ordered_use' => true, 'phpdoc_order' => true, 'short_array_syntax' => true))->finder(DefaultFinder::create()->in($directory)); $resolver = new ConfigurationResolver(); $resolver->setDefaultConfig($config); $resolver->resolve(); $this->fixer->fix($config); } return $generated; }