Exemple #1
0
 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;
 }
Exemple #2
0
 public function testMethodOrdering()
 {
     $gClass = new GClass(__NAMESPACE__ . '\\OrderedMethods');
     $gClass->setParentClass(new GClass(__NAMESPACE__ . '\\MyDocTestClass'));
     $gClass->createMethod('getIdentifier');
     $gClass->createMethod('getObjectName');
     $gClass->createMethod('setLabel', array(new GParameter('label')));
     $gClass->createMethod('getLabel');
     $gClass->addMethod(new GMethod('__construct'), GClass::PREPEND);
     $classWriter = new ClassWriter($gClass);
     $classWriter->write($out = $this->newFile('class.OrderedMethods.php'), array(), ClassWriter::OVERWRITE);
     require $out;
     $gClass = GClass::factory(__NAMESPACE__ . '\\OrderedMethods');
     $getMethodNames = function (array $methods) {
         $methodNames = array();
         foreach ($methods as $method) {
             $methodNames[] = $method->getName();
         }
         return $methodNames;
     };
     $this->assertEquals(array('__construct', 'getIdentifier', 'getObjectName', 'setLabel', 'getLabel'), $getMethodNames($gClass->getMethods()));
     $this->assertEquals(array('__construct', 'getIdentifier', 'getObjectName', 'setLabel', 'getLabel', 'getName'), $getMethodNames($gClass->getAllMethods()));
     // parent methods behind
     $gClass->setMethodOrder($gClass->getMethod('getLabel'), 1);
     $this->assertEquals(array('__construct', 'getLabel', 'getIdentifier', 'getObjectName', 'setLabel'), $getMethodNames($gClass->getMethods()));
 }
Exemple #3
0
 /**
  * @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;
 }
 public function createClassMetadata(GClass $gClass)
 {
     // da wir gClass mehrmals im Test evalen könnten, erzeugen wir einen unique hash für den classname und übergeben den
     // der class metadata
     $className = uniqid($gClass->getClassName());
     $gClass->setClassName($className);
     $gClass->createDocBlock()->addAnnotation(Annotation::createDC('Entity'));
     $classWriter = new ClassWriter($gClass);
     $classWriter->setUseStyle('lines');
     $classWriter->addImport(new GClass('Doctrine\\ORM\\Mapping'), 'ORM');
     // braucht einen AnnotationReader nicht SimpleAnnotationReader
     $classWriter->write($file = $this->newFile('entity.' . $gClass->getClassName() . '.php'));
     require $file;
     $cm = new ClassMetadata($gClass->getFQN());
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->annotationDriver->loadMetadataForClass($gClass->getFQN(), $cm);
     $file->delete();
     return $cm;
 }
 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;
 }
Exemple #6
0
    public function testBugWithUse()
    {
        $gClass = new GClass('TestClass');
        $gClass->setNamespace('\\Psc\\habe\\keinen');
        $writer = new ClassWriter();
        $writer->setClass($gClass);
        $writer->write($f = $this->newFile('buguse2.php'), array(new GClass('\\Psc\\using\\that')), ClassWriter::OVERWRITE);
        $this->assertFileExists((string) $f);
        $this->assertEquals(<<<'FILE_CODE'
<?php

namespace Psc\habe\keinen;

use Psc\using\that;

class TestClass {
}
?>
FILE_CODE
, $f->getContents());
    }
 public function testAcceptance()
 {
     $gClass = new GClass(__NAMESPACE__ . '\\Table' . uniqid('table'));
     $this->extension->compile($gClass);
     // quicktest
     $this->test->gClass($gClass)->hasProperty('columns')->hasMethod('getColumns')->hasMethod('setColumns', array('columns'))->hasMethod('removeColumn', array('column'))->hasMethod('getColumn', array('key'))->hasMethod('addColumn', array('column'))->hasMethod('hasColumn', array('column'));
     // acceptance
     $classWriter = new ClassWriter($gClass);
     $classWriter->write($file = $this->newFile('out.php'), array(), ClassWriter::OVERWRITE);
     require $file;
     $table = $gClass->newInstance();
     $c1 = new Column('c1', Type::create('String'), 'Spalte 1');
     $c2 = new Column('c2', Type::create('Integer'), 'Spalte 2');
     $this->assertInternalType('array', $table->getColumns(), 'getColumns gibt keinen Array zurück');
     $this->assertCount(0, $table->getColumns());
     $table->setColumns(array($c1, $c2));
     $this->assertEquals(array($c1, $c2), $table->getColumns(), 'setColumns() funktioniert nicht richtig');
     $this->assertTrue($table->hasColumn($c1), 'hasColumn(c1) gibt nicht true zurück');
     $this->assertTrue($table->hasColumn($c2), 'hasColumn(c2) gibt nicht true zurück');
     $table->removeColumn($c1);
     $this->assertEquals(array($c2), $table->getColumns(), 'c2 wurde nicht entfernt');
     $this->assertFalse($table->hasColumn($c1), 'hasColumn(c1) muss false sein nach removen');
     $this->assertTrue($table->hasColumn($c2), 'hasColumn(c2) muss noch true sein nach dem removen von c1');
 }
Exemple #8
0
    $class->generateSetters();
    $class->generateDocBlocks();
    $optionsCode = array();
    $optionsCode[] = '$options = new \\stdClass;';
    $optionsCode[] = sprintf('foreach (%s as $option) {', $class->getCodeWriter()->exportList($properties));
    $optionsCode[] = sprintf('  if ($this->$option !== "%s") {', $undefined);
    $optionsCode[] = sprintf('    $options->$option = $this->$option;');
    $optionsCode[] = '  }';
    $optionsCode[] = '}';
    $optionsCode[] = 'return $options;';
    $class->createMethod('getWidgetOptions', array(), $optionsCode)->createDocBlock()->setSummary('Gibt alle gesetzten Optionen des Widgets zurück')->addSimpleAnnotation('return stdClass');
    $class->getClassDocBlock()->addSimpleAnnotation('compiled jqx-widget-specification console-command on ' . date('d.m.Y H:i'));
    $cw = new ClassWriter($gClass = $class->getGClass());
    $cw->setUseStyle(ClassWriter::USE_STYLE_LINES);
    $phpFile = $command->getProject()->getClassFile($gClass);
    $cw->write($phpFile, array(), $overwrite = ClassWriter::OVERWRITE);
    $output->writeln($phpFile . ' written.');
});
$createCommand('tests:build-from-json', array($arg('file')), function ($input, $output, $command) {
    $jsonc = JSONConverter::create();
    $root = Dir::factoryTS(__DIR__)->sub('../');
    $json = $root->getFile($input->getArgument('file'))->getContents();
    $json = '[' . str_replace('}{', '},{', $json) . ']';
    try {
        $report = $jsonc->parse($json);
    } catch (\Webforge\Common\JS\JSONParsingException $e) {
        $parser = new JsonParser();
        $parsingException = $parser->lint($root->getFile('output.json')->getContents());
        throw $parsingException;
    }
    $toRun = array();