/** * @param FileGenerator $file * @param Type $type * * @return string */ public function generate(FileGenerator $file, $type) { $class = $file->getClass() ?: new ClassGenerator(); $class->setNamespaceName($type->getNamespace()); $class->setName($type->getName()); $this->ruleSet->applyRules(new TypeContext($class, $type)); foreach ($type->getProperties() as $property) { $this->ruleSet->applyRules(new PropertyContext($class, $type, $property)); } $file->setClass($class); return $file->generate(); }
/** * An existing file was found. Try to patch or ask if it can be overwritten. * * @param TypeGenerator $generator * @param Type $type * @param string $path * * @return bool */ protected function handleExistingFile(TypeGenerator $generator, Type $type, $path) { $this->output->write(sprintf('Type %s exists. Trying to patch ...', $type->getName())); $patched = $this->patchExistingFile($generator, $type, $path); if ($patched) { $this->output->writeln('Patched!'); return true; } $this->output->writeln('Could not patch.'); return false; }