/**
  *
  * @param DTDDocument $document        	
  * @param string $outputDirectory        	
  * @param string $namespace        	
  * @param string $parentClass        	
  */
 public function generate(DTDDocument $document, $outputDirectory, $namespace, $parentClass)
 {
     if (!file_exists($outputDirectory)) {
         mkdir($outputDirectory, 0777, true);
     }
     $name = ucfirst($document->getFileInfo()->getBasename('.dtd'));
     $filename = sprintf("%s/%s.php", $outputDirectory, $name);
     $classGenerator = new ClassGenerator($name, $namespace, null, $parentClass);
     $fileGenerator = new FileGenerator();
     $fileGenerator->setClass($classGenerator);
     $fileDocblock = new DocBlockGenerator(sprintf("%s %s", str_replace("\\", " ", $namespace), $name));
     $fileDocblock->setTag(new Tag("author", "Generator"));
     $fileDocblock->setTag(new Tag("licence", "LGPL"));
     $fileGenerator->setDocBlock($fileDocblock);
     file_put_contents($filename, $fileGenerator->generate());
 }
Exemple #2
0
 public function generate(DTDDocument $document, $outputDirectory, $namespace, $parentClass)
 {
     $items = $document->getElement();
     $directory = sprintf($outputDirectory, $document->getFileInfo()->getBasename('.dtd'));
     $namespace = sprintf($namespace, $document->getFileInfo()->getBasename('.dtd'));
     $description = str_replace("\\", " ", $namespace);
     if (!file_exists($directory)) {
         mkdir($directory, 0777, true);
     }
     foreach ($items as $item) {
         $name = sprintf("%sElement", Source::camelCase($item->getName()));
         $filename = sprintf("%s/%s.php", $directory, $name);
         $classDescription = sprintf("%s %s", $description, $name);
         $datetime = new \DateTime();
         $properties = array((new PropertyGenerator("name", $item->getName()))->setDocBlock(new DocBlockGenerator(sprintf("%s Name", $classDescription), "", array(new Tag("var", "string")))), (new PropertyGenerator("value", $item->getValue()))->setDocBlock(new DocBlockGenerator(sprintf("%s Value", $classDescription), "", array(new Tag("var", "string")))));
         $docblock = new DocBlockGenerator($classDescription, "", array(new Tag("author", "ITC Generator " . $datetime->format("d.m.Y h:m:s")), new Tag("copyright", "LGPL")));
         $fileGenerator = new FileGenerator();
         $fileGenerator->setClass(new ClassGenerator($name, $namespace, null, $parentClass, array(), $properties, array(), $docblock));
         file_put_contents($filename, $fileGenerator->generate());
     }
 }