public function compile(File $out, $flags = 0) { // 0x000000 geht leider noch nicht $this->cClass = clone $this->gClass; // mit leerer oder mit clone anfangen? $this->processExtensions(); $this->classWriter->setClass($this->cClass, $this->classReader); $this->classWriter->write($out, array(), ClassWriter::OVERWRITE); $this->classWriter->syntaxCheck($out); return $this; }
public function create($overwrite = false) { try { $this->class->elevateClass(); // @todo das mal konfigurieren und fixen } catch (\Exception $e) { $this->log('Klasse für den Test kann nicht elevated werden: ' . $e->getMessage()); } catch (\Psc\Code\Generate\ReflectionException $e) { $this->log('Klasse für den Test kann nicht elevated werden: ' . $e->getMessage()); } $class = new GClass(); $class->setName($this->class->getClassName() . 'Test'); $class->setNamespace($this->class->getNamespace()); $class->setParentClass($this->testClass); $writer = new ClassWriter(); $writer->setClass($class); $class = $this->createStub($class); $file = $this->getTestFile(); if (isset($this->createCallback)) { $class = call_user_func($this->createCallback, $class, $this, $writer, $file); } $writer->addImport($this->class); // not really necessary (weil ist ja derselbe NS, aber who knows) $file->getDirectory()->create(); $writer->write($file, array(), $overwrite); return $file; }
/** * @return File */ public function writeRepository(File $file = NULL, $overwrite = NULL) { $gClass = $this->getRepositoryGClass(); $this->classWriter->setClass($gClass); if (!isset($file)) { $autoLoadRoot = $this->module->getEntitiesPath()->sub(str_repeat('../', count(explode('\\', $this->module->getEntitiesNamespace()))))->resolvePath(); $file = Code::mapClassToFile($gClass->getFQN(), $autoLoadRoot); } $this->classWriter->write($file, array(), $overwrite); $this->classWriter->syntaxCheck($file); return $file; }
protected function execute(InputInterface $input, OutputInterface $output) { $overwrite = $input->getOption('overwrite') ? ClassWriter::OVERWRITE : NULL; $controllerName = $input->getArgument('name'); $entityClass = $this->getDoctrineModule()->getEntityName($controllerName); $gClass = new GClass(); $gClass->setClassName($controllerName . 'Controller'); $gClass->setNamespace($this->getProject()->getNamespace() . '\\Controllers'); // siehe auch EntityService $gClass->setParentClass(new GClass('Psc\\CMS\\Controller\\AbstractEntityController')); $classBuilder = new ClassBuilder($gClass); $classBuilder->createProtectedMethod('setUp', array(), array("parent::setUp();")); $classBuilder->createMethod('getEntityName', array(), array(sprintf("return '%s';", $entityClass))); $imports = array(new GClass($entityClass)); $classWriter = new ClassWriter(); $classWriter->setClass($gClass); $classWriter->write($file = $this->getProject()->getClassFile($gClass), $imports, $overwrite); $output->writeLn('Controller in Datei: "' . $file . '" geschrieben'); return 0; }
/** * @expectedException Psc\Code\Generate\Exception */ public function testUseImplicitDoubleAlias() { $writer = new ClassWriter(); $writer->setClass(new GClass('TestClass')); $writer->addImport(new GClass('Webforge\\Common\\System\\File')); $writer->addImport(new GClass('Webforge\\Common\\ArrayUtilnother\\File')); }