public function testConstructorWithValidPath() { $classWriter = new ClassWriter($this->baseClass, $this->fileSystem); /** @var SplFileInfo $path */ $path = $classWriter->getPath(); $this->assertInstanceOf('SpLFileInfo', $path); $this->assertRegExp('/Writers/', $path->getPathname()); }
/** * @Route("/testclass", name="homepage") * * @Method("GET") */ public function indexAction() { $class = new BaseClass('Classes', 'BestClass'); $class->addProperty(new ClassProperty('test', 'string')); $method = new ClassMethod('setTest'); $method->addParameter(new MethodParameter('test', 'string')); $method->setReturnType(null); $class->addMethod($method); $classGenerator = new ClassGenerator($class); $classWriter = new ClassWriter($classGenerator, new Filesystem(), '/Users/justingriffith/Sites/CodeCreator/'); $classWriter->write(); return $this->render('default/index.html.twig'); }
protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getOption('file'); $pwd = trim(`pwd`); if ($file) { // Parse the yaml $yamlParser = new Yaml(); $yaml = $yamlParser->parse(file_get_contents($pwd . '/' . $file)); // translate the yaml $classTranslator = new YamlToClassTranslator($yaml); // get classes $classes = $classTranslator->getClasses(); // write each class to file foreach ($classes as $class) { $classWriter = new ClassWriter($class, new FileSystem(), $pwd . '/GeneratedClasses/'); $classWriter->write(); } } $output->writeln('Files Written'); }