Ejemplo n.º 1
0
 /**
  *
  * @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());
 }
Ejemplo n.º 2
0
 /**
  * (non-PHPdoc)
  *
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $document = $this->getDocument($input->getArgument('document'));
     $directory = $input->getArgument('output');
     $namespace = $input->getArgument('namespace');
     $parentClass = $input->getArgument('parentClass');
     if (!file_exists($directory)) {
         mkdir($directory, 0777, true);
     }
     $name = ucfirst($document->getFileInfo()->getBasename('.dtd'));
     $output->writeln("Generating Document " . $name);
     $filename = sprintf("%s/%s.php", $directory, $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());
 }
Ejemplo n.º 3
0
 /**
  * Update module class with class map autoloading
  *
  * @return bool
  * @throws \Zend\Code\Generator\Exception
  */
 public function updateModuleWithClassmapAutoloader()
 {
     // get needed options to shorten code
     $path = realpath($this->requestOptions->getPath());
     $directory = $this->requestOptions->getDirectory();
     $destination = $this->requestOptions->getDestination();
     $moduleFile = $directory . '/Module.php';
     $moduleClass = str_replace($path . '/module/', '', $directory) . '\\Module';
     $moduleName = str_replace($path . '/module/', '', $directory);
     // check for module file
     if (!file_exists($moduleFile)) {
         return false;
     }
     // get file and class reflection
     $fileReflection = new FileReflection($moduleFile, true);
     $classReflection = $fileReflection->getClass($moduleClass);
     // setup class generator with reflected class
     $code = ClassGenerator::fromReflection($classReflection);
     // check for action method
     if ($code->hasMethod('getAutoloaderConfig')) {
         $code->removeMethod('getAutoloaderConfig');
     }
     // add getAutoloaderConfig method with class map
     $code->addMethodFromGenerator($this->generateGetAutoloaderConfigMethod($destination, $moduleName));
     // create file with file generator
     $file = new FileGenerator();
     $file->setClass($code);
     // add optional doc block
     if ($this->flagCreateApiDocs) {
         $file->setDocBlock(new DocBlockGenerator('This file was generated by FrilleZFTool.', null, array($this->generatePackageTag($moduleName), $this->generateSeeTag())));
     }
     // create file with file generator
     $file = new FileGenerator();
     $file->setClass($code);
     // add optional doc block
     if ($this->flagCreateApiDocs) {
         $file->setDocBlock(new DocBlockGenerator('This file was generated by FrilleZFTool.', null, array($this->generatePackageTag($moduleName), $this->generateSeeTag())));
     }
     // write module class
     if (!file_put_contents($moduleFile, $file->generate())) {
         return false;
     }
     return true;
 }
 /**
  * creates module config files
  *
  * @return string returns config path
  */
 protected function createModuleConfig()
 {
     $config = array();
     $configPath = $this->moduleRoot() . '/config/module.config.php';
     if (file_exists($configPath)) {
         $config = (require $configPath);
     }
     $moduleConfig = new FileGenerator();
     $moduleConfig->setDocBlock($this->getFileDocBlock());
     $moduleConfig->getDocBlock()->setShortDescription(sprintf($this->codeLibrary()->get('module.standardConfigDescription'), $this->params->getParam('moduleName')));
     $moduleConfig->setBody('return ' . var_export($config, true) . ';');
     $this->console('writing module config file');
     file_put_contents($this->moduleRoot() . '/config/module.config.php', $moduleConfig->generate());
     return $configPath;
 }
Ejemplo n.º 5
0
 /**
  * Generate Madel class from metadata
  *
  * @param  stdClass                      $metadata
  * @return Generator\ClassGenerator|null
  */
 protected function generateModelFromMetadata($metadata)
 {
     $console = $this->getServiceLocator()->get('console');
     $name = $metadata->Name;
     $ucName = ucfirst($name);
     // Create Api Class
     $class = new Generator\ClassGenerator($ucName, 'Mailjet\\Model');
     $class->setImplementedInterfaces(array('ModelInterface'))->setDocBlock(new Generator\DocBlockGenerator($class->getName() . ' Model', $metadata->Description, array()));
     $this->addProperties($class, $metadata->Properties);
     // Create and Write Api Class File
     $file = new Generator\FileGenerator();
     $file->setClass($class);
     $file->setDocBlock(new Generator\DocBlockGenerator('MailJet Model', self::LICENSE));
     $file->setFilename(dirname(__DIR__) . '/Model/' . $class->getName() . '.php');
     if (file_put_contents($file->getFilename(), $file->generate())) {
         $console->writeLine(sprintf("The Model '%s' has been created.", $class->getName()), Color::GREEN);
         return $class;
     } else {
         $console->writeLine(sprintf("There was an error during '%s' Model creation.", $class->getName()), Color::RED);
     }
     return $class;
 }
 /**
  * writes module config
  *
  * @param array $config
  * @param string $path
  */
 protected function writeModuleConfig(array $config, $path)
 {
     $moduleName = $this->params->getParam('moduleName');
     $generatorConfig = new FileGenerator();
     $docBlock = new DocBlockGenerator();
     $docBlock->setTag(new GenericTag('author', $this->params->getParam('author')));
     $docBlock->setTag(new GenericTag('project', $this->params->getParam('project')));
     $docBlock->setTag(new GenericTag('license', $this->params->getParam('license')));
     $docBlock->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
     $docBlock->setShortDescription(sprintf($this->codeLibrary()->get('module.generatedConfigDescription'), $moduleName));
     $generatorConfig->setDocBlock($docBlock);
     $configString = var_export($config, true);
     $configString = str_replace("'/../view'", '__DIR__ . \'/../view\'', $configString);
     $generatorConfig->setBody('return ' . $configString . ';');
     file_put_contents($path, $generatorConfig->generate());
 }