コード例 #1
0
 public function generate()
 {
     $modelBuilder = $this->controller->getModelBuilder();
     $className = $modelBuilder->getName() . 'Controller';
     $class = new ClassGenerator();
     $class->setName($className);
     $class->setExtendedClass('CrudController');
     $param = new ParameterGenerator();
     $param->setName('fb')->setType('FormBuilder');
     $body = $this->generateFormBuilderBody();
     $docblock = '@param FormBuilder $fb';
     $class->addMethod('buildForm', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
     $param = new ParameterGenerator();
     $param->setName('mb')->setType('ModelBuilder');
     $body = '';
     $docblock = '@param ModelBuilder $mb';
     $class->addMethod('buildModel', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
     $param = new ParameterGenerator();
     $param->setName('ob')->setType('OverviewBuilder');
     $body = '';
     $docblock = '@param OverviewBuilder $ob';
     $class->addMethod('buildOverview', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
     $this->generator->setClass($class);
     $this->generator->setUses(array('Boyhagemann\\Crud\\CrudController', 'Boyhagemann\\Form\\FormBuilder', 'Boyhagemann\\Model\\ModelBuilder', 'Boyhagemann\\Overview\\OverviewBuilder'));
     return $this->generator->generate();
 }
コード例 #2
0
 public function generate()
 {
     if ($this->controller) {
         $modelBuilder = $this->controller->getModelBuilder();
         $className = $modelBuilder->getName();
     } else {
         $className = $this->class;
     }
     $modelClass = $this->modelClass ? $this->modelClass : $this->class;
     $class = new ClassGenerator();
     $class->setName($className);
     $class->setExtendedClass('CrudController');
     $class->addUse('Boyhagemann\\Crud\\CrudController');
     $class->addUse('Boyhagemann\\Form\\FormBuilder');
     $class->addUse('Boyhagemann\\Model\\ModelBuilder');
     $class->addUse('Boyhagemann\\Overview\\OverviewBuilder');
     $param = new ParameterGenerator();
     $param->setName('fb')->setType('FormBuilder');
     $body = $this->generateFormBuilderBody();
     $docblock = '@param FormBuilder $fb';
     $class->addMethod('buildForm', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
     $param = new ParameterGenerator();
     $param->setName('mb')->setType('ModelBuilder');
     $body = sprintf('$mb->name(\'%s\')->table(\'%s\');' . PHP_EOL, $modelClass, strtolower(str_replace('\\', '_', $modelClass)));
     $docblock = '@param ModelBuilder $mb';
     $class->addMethod('buildModel', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
     $param = new ParameterGenerator();
     $param->setName('ob')->setType('OverviewBuilder');
     $body = '';
     $docblock = '@param OverviewBuilder $ob';
     $class->addMethod('buildOverview', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
     $this->generator->setClass($class);
     return $this->generator->generate();
 }
コード例 #3
0
ファイル: DbTableFile.php プロジェクト: rafalwrzeszcz/zf2
 public function getContents()
 {
     $className = $this->getFullClassName($this->_dbTableName, 'Model\\DbTable');
     $codeGenFile = new FileGenerator($this->getPath());
     $codeGenFile->setClass(new ClassGenerator($className, null, null, '\\Zend\\Db\\Table\\AbstractTable', null, array(new PropertyGenerator('_name', $this->_actualTableName, PropertyGenerator::FLAG_PROTECTED))));
     return $codeGenFile->generate();
 }
コード例 #4
0
    /**
     * getContents()
     *
     * @return string
     */
    public function getContents()
    {
        $codeGenerator = new FileGenerator();
        $codeGenerator->setBody(<<<EOS
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

require_once 'Zend/Loader/StandardAutoloader.php';
\$loader = new Zend\\Loader\\StandardAutoloader(array(
    'fallback_autoloader' => true,
))
\$loader->register();

EOS
);
        return $codeGenerator->generate();
    }
コード例 #5
0
ファイル: Element.php プロジェクト: slavomirkuzma/itc-bundle
 /**
  * (non-PHPdoc)
  *
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $document = $this->getDocument($input->getArgument('document'));
     $items = $document->getElement();
     $directory = sprintf($input->getArgument('elementOutput'), $document->getFileInfo()->getBasename('.dtd'));
     $namespace = sprintf($input->getArgument('elementNamespace'), $document->getFileInfo()->getBasename('.dtd'));
     $parentClass = $input->getArgument('elementParentClass');
     $description = str_replace("\\", " ", $namespace);
     if (!file_exists($directory)) {
         mkdir($directory, 0777, true);
     }
     $progressBar = new ProgressBar($output, $items->count());
     $progressBar->setFormat('verbose');
     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());
         $progressBar->advance();
     }
     $progressBar->finish();
 }
コード例 #6
0
 /**
  * @interitdoc
  */
 public function writeClass($filename, FileGenerator $fileGenerator)
 {
     $dir = dirname($filename);
     if (!@mkdir($dir, 0755, true) && !is_dir($dir)) {
         throw new RuntimeException(sprintf('Could not create "%s" directory.', $dir));
     }
     file_put_contents($filename, $fileGenerator->generate());
 }
コード例 #7
0
ファイル: TestLibraryFile.php プロジェクト: nevvermind/zf2
 /**
  * getContents()
  *
  * @return string
  */
 public function getContents()
 {
     $filter = new \Zend\Filter\Word\DashToCamelCase();
     $className = $filter->filter($this->_forClassName) . 'Test';
     $codeGenFile = new FileGenerator();
     $codeGenFile->setRequiredFiles(array('PHPUnit/Framework/TestCase.php'));
     $codeGenFile->setClasses(array(new ClassGenerator($className, null, null, 'PHPUnit_Framework_TestCase', array(), array(), array(new MethodGenerator('setUp', array(), MethodGenerator::FLAG_PUBLIC, '        /* Setup Routine */'), new MethodGenerator('tearDown', array(), MethodGenerator::FLAG_PUBLIC, '        /* Tear Down Routine */')))));
     return $codeGenFile->generate();
 }
コード例 #8
0
 private function makeSureConfigFileExist()
 {
     if (FALSE === file_exists($this->confPath)) {
         $fileGenerator = new FileGenerator();
         $body = $this->getConfigTemplate();
         $fileGenerator->setBody($body);
         file_put_contents($this->confPath, $fileGenerator->generate());
     }
 }
コード例 #9
0
ファイル: TypeGenerator.php プロジェクト: phpro/soap-client
 /**
  * @param FileGenerator $file
  * @param Type          $type
  *
  * @return string
  */
 public function generate(FileGenerator $file, $type)
 {
     $class = $file->getClass() ?: new ClassGenerator();
     $class->setNamespaceName($type->getNamespace());
     $class->setName($type->getName());
     $this->ruleSet->applyRules(new TypeContext($class, $type));
     foreach ($type->getProperties() as $property) {
         $this->ruleSet->applyRules(new PropertyContext($class, $type, $property));
     }
     $file->setClass($class);
     return $file->generate();
 }
コード例 #10
0
ファイル: Document.php プロジェクト: slavomirkuzma/itc-bundle
 /**
  *
  * @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());
 }
コード例 #11
0
 function it_generates_types(RuleSetInterface $ruleSet, FileGenerator $file, ClassGenerator $class)
 {
     $type = new Type('MyNamespace', 'MyType', ['prop1' => 'string']);
     $property = $type->getProperties()[0];
     $file->generate()->willReturn('code');
     $file->getClass()->willReturn($class);
     $class->setNamespaceName('MyNamespace')->shouldBeCalled();
     $class->setName('MyType')->shouldBeCalled();
     $file->setClass($class)->shouldBeCalled();
     $ruleSet->applyRules(Argument::that(function (ContextInterface $context) use($type) {
         return $context instanceof TypeContext && $context->getType() === $type;
     }))->shouldBeCalled();
     $ruleSet->applyRules(Argument::that(function (ContextInterface $context) use($type, $property) {
         return $context instanceof PropertyContext && $context->getType() === $type && $context->getProperty() === $property;
     }))->shouldBeCalled();
     $this->generate($file, $type)->shouldReturn('code');
 }
コード例 #12
0
ファイル: Element.php プロジェクト: slavomirkuzma/itc-bundle
 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());
     }
 }
コード例 #13
0
ファイル: Document.php プロジェクト: slavomirkuzma/itc-bundle
 /**
  * (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());
 }
コード例 #14
0
 /**
  * generates base controller for given dataSet
  *
  * @param DataSetDescriptorInterface $dataSet
  * @return string generated controller full class name
  */
 protected function generateBaseController(DataSetDescriptorInterface $dataSet)
 {
     $name = $dataSet->getName();
     $className = 'Base' . $this->underscoreToCamelCase->filter($name) . 'Controller';
     $namespace = $this->params->getParam("moduleName") . '\\Controller\\Base';
     $fullClassName = '\\' . $namespace . '\\' . $className;
     $moduleName = $this->params->getParam("moduleName");
     $fileBase = new FileGenerator();
     $fileBase->setFilename($className);
     $fileBase->setNamespace($namespace);
     $class = new ClassGenerator();
     $class->setName($className)->setExtendedClass('\\' . $this->extendedController);
     $docBlock = new \Zend\Code\Generator\DocblockGenerator(sprintf($this->codeLibrary()->get('controller.standardBaseControllerDescription'), $name));
     $docBlock->setTag(new GenericTag('author', $this->params->getParam('author')))->setTag(new GenericTag('project', $this->params->getParam('project')))->setTag(new GenericTag('license', $this->params->getParam('license')))->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
     $class->setDocBlock($docBlock);
     $this->addControllerMethods($class, $dataSet);
     $fileBase->setClass($class);
     $modelClassFilePath = $this->moduleRoot() . "/src/" . $this->params->getParam("moduleName") . "/Controller/Base/" . $className . ".php";
     file_put_contents($modelClassFilePath, $fileBase->generate());
     return $fullClassName;
 }
コード例 #15
0
ファイル: FileGeneratorTest.php プロジェクト: pnaq57/zf2demo
 public function testSetUsesWithGetUses()
 {
     $file = new FileGenerator();
     $uses = array('Your\\Bar', 'My\\Baz', array('use' => 'Another\\Baz', 'as' => 'Baz2'));
     $file->setUses($uses);
     $file->setUses($file->getUses());
     $generated = $file->generate();
     $this->assertContains('use My\\Baz;', $generated);
     $this->assertContains('use Your\\Bar;', $generated);
     $this->assertContains('use Another\\Baz as Baz2;', $generated);
 }
コード例 #16
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;
 }
コード例 #17
0
ファイル: MigrationManager.php プロジェクト: naxel/zfctool
 /**
  * @param null|string $module
  * @param null|string $migrationBody
  * @return string
  */
 public function create($module = null, $migrationBody = null)
 {
     $path = $this->getMigrationsDirectoryPath($module);
     list(, $mSec) = explode(".", microtime(true));
     $migrationName = date('Ymd_His_') . substr($mSec, 0, 2);
     $methodUp = array('name' => 'up', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Upgrade', 'longDescription' => null)));
     $methodDown = array('name' => 'down', 'docblock' => DocBlockGenerator::fromArray(array('shortDescription' => 'Degrade', 'longDescription' => null)));
     if ($migrationBody) {
         if (isset($migrationBody['up'])) {
             $upBody = '';
             foreach ($migrationBody['up'] as $query) {
                 $upBody .= '$this->query("' . $query . '");' . PHP_EOL;
             }
             $methodUp['body'] = $upBody;
         }
         if (isset($migrationBody['down'])) {
             $downBody = '';
             foreach ($migrationBody['down'] as $query) {
                 $downBody .= '$this->query("' . $query . '");' . PHP_EOL;
             }
             $methodDown['body'] = $downBody;
         }
     }
     $class = new ClassGenerator();
     $class->setName('Migration_' . $migrationName)->setExtendedClass('AbstractMigration')->addUse('ZFCTool\\Service\\Migration\\AbstractMigration')->addMethods(array(MethodGenerator::fromArray($methodUp), MethodGenerator::fromArray($methodDown)));
     $file = new FileGenerator(array('classes' => array($class)));
     $code = $file->generate();
     $migrationPath = $path . '/' . $migrationName . '.php';
     file_put_contents($migrationPath, $code);
     return $migrationPath;
 }
コード例 #18
0
ファイル: Form.php プロジェクト: robmlopes/crud-from-doctrine
 /**
  * Método para saida da classe gerada
  * @return string Classe gerada
  */
 public function generate()
 {
     $this->render();
     $fileGenerator = new Generator\FileGenerator(array('classes' => array($this->classGenerator)));
     $ucModule = ucfirst($this->module);
     // cria o arquivo de formulário
     $pathForm = $this->path . "/module/{$ucModule}/src/{$ucModule}/Form/";
     $pathFileForm = $pathForm . ucfirst($this->name) . "Form.php";
     // // cria a pasta form
     @mkdir($pathForm, 0775, true);
     file_put_contents($pathFileForm, $fileGenerator->generate());
     return $fileGenerator->generate();
 }
コード例 #19
0
ファイル: ModuleGenerator.php プロジェクト: ralfeggert/zftool
 /**
  * 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;
 }
コード例 #20
0
 /**
  * @inheritDoc
  */
 public function writeClass(FileGenerator $fileGenerator)
 {
     file_put_contents($fileGenerator->getFilename(), $fileGenerator->generate());
 }
コード例 #21
0
ファイル: Generator.php プロジェクト: naxel/classes-generator
 /**
  * @param string $sourceFile
  * @return string
  */
 protected function generateClass($sourceFile)
 {
     $sourceContent = json_decode(file_get_contents($sourceFile));
     $class = new ClassGenerator();
     $className = null;
     $mappingClasses = array();
     $propNameMap = $this->setPropNameMap($sourceContent);
     $isCollection = false;
     foreach ($sourceContent as $property => $value) {
         $ourPropertyName = array_search($property, $propNameMap);
         if ($ourPropertyName) {
             $property = $ourPropertyName;
         }
         if ($property === '@name') {
             //Class name
             $className = $value;
             if ($this->namespace) {
                 $class->setNamespaceName($this->namespace);
             }
             $class->setName($value);
         } elseif ($property === '@type') {
             continue;
         } elseif ($value === 'number' || $value === 'int' || $value === 'integer') {
             //Create property type number
             $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED);
             $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, 'int')), MethodGenerator::fromArray($this->generateSetMethod($property, 'int'))));
         } elseif ($value === 'float' || $value === 'double' || $value === 'real') {
             //Create property type number
             $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED);
             $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, $value)), MethodGenerator::fromArray($this->generateSetMethod($property, $value))));
         } elseif ($value === 'string') {
             //Create property type string
             $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED);
             $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, $value)), MethodGenerator::fromArray($this->generateSetMethod($property, $value))));
         } elseif ($value === 'date') {
             //Create property type date
             $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED);
             $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, 'string')), MethodGenerator::fromArray($this->generateSetMethod($property, 'string'))));
         } elseif ($value === 'array') {
             //Create property type date
             $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED);
             $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, 'array')), MethodGenerator::fromArray($this->generateSetMethod($property, 'array'))));
         } elseif ($value === 'boolean' || $value === 'bool') {
             //Create property type boolean
             $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED);
             $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, $value)), MethodGenerator::fromArray($this->generateSetMethod($property, $value))));
         } elseif ($property === "@model") {
             if ($this->namespace) {
                 $class->addUse($this->namespace . '\\' . ucfirst($value));
             }
         } elseif ($property === "@collection") {
             $isCollection = true;
             $class->addProperty('collection', array(), PropertyGenerator::FLAG_PROTECTED);
             $class->addMethods($this->getMethodsForCollection($value->model));
         } elseif ($property === "@parent") {
             //"@parent": "\\Classes\\Items",
             $class->setExtendedClass($value);
         } elseif (strpos($value, '@') === 0) {
             if ($className !== ucfirst(substr($value, 1))) {
                 if ($this->namespace) {
                     $class->addUse($this->namespace . '\\' . ucfirst(substr($value, 1)));
                 }
             }
             if ($this->namespace) {
                 $mappingClasses[$property] = $this->namespace . '\\' . ucfirst(substr($value, 1));
             } else {
                 $mappingClasses[$property] = ucfirst(substr($value, 1));
             }
             //Create property type Class
             $class->addProperty($property, null, PropertyGenerator::FLAG_PROTECTED);
             $class->addMethods(array(MethodGenerator::fromArray($this->generateGetMethod($property, ucfirst(substr($value, 1)))), MethodGenerator::fromArray($this->generateSetMethod($property, ucfirst(substr($value, 1))))));
         } else {
             var_dump($value, $property);
             exit;
         }
     }
     if ($isCollection === true) {
         if ($this->rootClassNameForCollection) {
             $class->setExtendedClass($this->rootClassNameForCollection);
             $class->addUse($this->rootClassForCollectionNamespace);
         }
     } else {
         if ($this->rootClassName) {
             $class->setExtendedClass($this->rootClassName);
             $class->addUse($this->rootClassNamespace);
         }
     }
     $class->addProperty($this->mappingClassesPropertyName, $mappingClasses, PropertyGenerator::FLAG_PROTECTED);
     $class->addProperty($this->mappingPropertyName, $propNameMap, PropertyGenerator::FLAG_PROTECTED);
     $file = new FileGenerator(array('classes' => array($class)));
     $code = $file->generate();
     $path = realpath($this->destinationDir) . '/' . ucfirst($className) . '.php';
     $code = str_replace("\n\n}\n", '}', $code);
     file_put_contents($path, $code);
     return $path;
 }
コード例 #22
0
 /**
  * Método para gerar o controller
  * @return void
  */
 public function generate()
 {
     $this->generator->addmethods($this->arrayMethods);
     $file = new Generator\FileGenerator(array('classes' => array($this->generator)));
     return file_put_contents($this->getPathFull(), $file->generate());
 }
コード例 #23
0
 /**
  * @param string $class
  * @param Entity $entity
  *
  * @return string
  */
 protected function generateFileContent($class, $entity)
 {
     $generator = new FileGenerator();
     $descriptor = $entity->getFileDescriptor();
     $generator->setClass($class);
     $generator->setDocblock(DocBlockGenerator::fromArray(array('shortDescription' => 'Generated by Protobuf protoc plugin.', 'longDescription' => 'File descriptor : ' . $descriptor->getName())));
     return $generator->generate();
 }
コード例 #24
0
 /**
  * creates Module class
  */
 protected function createModuleClass()
 {
     $moduleClassFilePath = $this->moduleRoot() . '/Module.php';
     if (!file_exists($moduleClassFilePath)) {
         $this->console('creating Module Class');
         $moduleClassFile = new FileGenerator();
         $moduleClassFile->setNamespace($this->params->getParam('moduleName'));
         $moduleClass = new ClassGenerator();
         $moduleClass->setDocBlock($this->getFileDocBlock())->getDocBlock()->setShortDescription($this->codeLibrary()->get('module.moduleClassDescription'));
         $moduleClass->setName('Module');
         // onbootstrap
         $onBootstrapMethod = new MethodGenerator();
         $onBootstrapMethod->setName('onBootstrap')->setBody($this->codeLibrary()->get('module.onBootstrap.body'));
         $onBootstrapMethod->setDocBlock(new DocBlockGenerator($this->codeLibrary()->get('module.onBootstrap.shortdescription'), $this->codeLibrary()->get('module.onBootstrap.longdescription'), array(new ParamTag('e', '\\Zend\\Mvc\\MvcEvent'))));
         $eventParam = new ParameterGenerator('e', '\\Zend\\Mvc\\MvcEvent');
         $onBootstrapMethod->setParameter($eventParam);
         $moduleClass->addMethodFromGenerator($onBootstrapMethod);
         // config
         $configMethod = new MethodGenerator('getConfig', array(), MethodGenerator::FLAG_PUBLIC, $this->codeLibrary()->get('module.config.body'), new DocBlockGenerator($this->codeLibrary()->get('module.config.shortdescription'), $this->codeLibrary()->get('module.config.longdescription'), array()));
         $moduleClass->addMethodFromGenerator($configMethod);
         // getAutoloaderConfig
         $getAutoloaderConfigMethod = new MethodGenerator('getAutoloaderConfig', array(), MethodGenerator::FLAG_PUBLIC, $this->codeLibrary()->get('module.getAutoloaderConfig.body'), new DocBlockGenerator($this->codeLibrary()->get('module.getAutoloaderConfig.shortdescription'), $this->codeLibrary()->get('module.getAutoloaderConfig.longdescription'), array()));
         $moduleClass->addMethodFromGenerator($getAutoloaderConfigMethod);
         // adding class method and generating file
         $moduleClassFile->setClass($moduleClass);
         file_put_contents($moduleClassFilePath, $moduleClassFile->generate());
     }
 }
コード例 #25
0
 public function controllerAction()
 {
     $config = $this->getServiceLocator()->get('config');
     $moduleName = $config['VisioCrudModeler']['params']['moduleName'];
     $modulePath = $config['VisioCrudModeler']['params']['modulesDirectory'];
     $db = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     $dataSourceDescriptor = new DbDataSourceDescriptor($db, 'K08_www_biedronka_pl');
     $listDataSets = $dataSourceDescriptor->listDataSets();
     $filter = new \Zend\Filter\Word\UnderscoreToCamelCase();
     foreach ($listDataSets as $d) {
         $className = $filter->filter($d) . 'Controller';
         $file = new FileGenerator();
         $file->setFilename($className);
         $file->setNamespace($moduleName)->setUse('Zend\\Mvc\\Controller\\AbstractActionController');
         $foo = new ClassGenerator();
         $docblock = DocBlockGenerator::fromArray(array('shortDescription' => 'Sample generated class', 'longDescription' => 'This is a class generated with Zend\\Code\\Generator.', 'tags' => array(array('name' => 'version', 'description' => '$Rev:$'), array('name' => 'license', 'description' => 'New BSD'))));
         $foo->setName($className);
         $foo->setExtendedClass('Base' . $className);
         $foo->setDocblock($docblock);
         $file->setClass($foo);
         echo '<pre>';
         echo htmlentities($file->generate());
         echo '</pre>';
         $fileView = new FileGenerator();
         $body = "echo '{$className}';";
         $fileView->setBody($body);
         echo '<pre>';
         echo htmlentities($fileView->generate());
         echo '</pre>';
     }
     echo '<hr />';
     foreach ($listDataSets as $d) {
         $className = 'Base' . $filter->filter($d) . 'Controller';
         $fileBase = new FileGenerator();
         $fileBase->setFilename($className);
         $fileBase->setNamespace($moduleName)->setUse('Zend\\Mvc\\Controller\\AbstractActionController');
         $fooBase = new ClassGenerator();
         $docblockBase = DocBlockGenerator::fromArray(array('shortDescription' => 'Sample generated class', 'longDescription' => 'This is a class generated with Zend\\Code\\Generator.', 'tags' => array(array('name' => 'version', 'description' => '$Rev:$'), array('name' => 'license', 'description' => 'New BSD'))));
         $fooBase->setName($className);
         $index = new MethodGenerator();
         $index->setName('indexAction');
         $create = new MethodGenerator();
         $create->setName('createAction');
         $read = new MethodGenerator();
         $read->setName('readAction');
         $update = new MethodGenerator();
         $update->setName('updateAction');
         $delete = new MethodGenerator();
         $delete->setName('deleteAction');
         $fooBase->setExtendedClass('AbstractActionController');
         //$fooBase->set
         $fooBase->setDocblock($docblock);
         $fooBase->addMethodFromGenerator($index);
         $fooBase->addMethodFromGenerator($create);
         $fooBase->addMethodFromGenerator($read);
         $fooBase->addMethodFromGenerator($update);
         $fooBase->addMethodFromGenerator($delete);
         $fileBase->setClass($fooBase);
         echo '<pre>';
         echo htmlentities($fileBase->generate());
         echo '</pre>';
     }
     exit;
 }
コード例 #26
0
 /**
  * generates code for base model and saves in file (overrides file if exists)
  *
  * @param DataSetDescriptorInterface $dataSet
  * @return string name of generated class
  */
 protected function generateBaseModel(DataSetDescriptorInterface $dataSet)
 {
     $name = $dataSet->getName();
     $className = "Base" . $this->underscoreToCamelCase->filter($name);
     $namespace = $this->params->getParam("moduleName") . "\\Model\\BaseModel";
     $fullClassName = '\\' . $namespace . '\\' . $className;
     $class = new ClassGenerator();
     $class->setName($className);
     $class->setNamespaceName($namespace);
     $class->setExtendedClass($this->baseModelParent);
     foreach ($this->baseModelUses as $use) {
         $class->addUse($use);
     }
     $this->addEventsMethods($class);
     foreach ($dataSet->listFields() as $name) {
         $column = $dataSet->getFieldDescriptor($name);
         $this->generateColumnRelatedElements($class, $column);
     }
     $file = new FileGenerator();
     $docBlock = new \Zend\Code\Generator\DocblockGenerator(sprintf($this->codeLibrary()->get('model.generatedConfigDescription'), $name));
     $docBlock->setTag(new GenericTag('author', $this->params->getParam('author')))->setTag(new GenericTag('project', $this->params->getParam('project')))->setTag(new GenericTag('license', $this->params->getParam('license')))->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
     $class->setDocBlock($docBlock);
     $file->setClass($class);
     $modelClassFilePath = $this->moduleRoot() . "/src/" . $this->params->getParam("moduleName") . "/Model/BaseModel/" . $className . ".php";
     file_put_contents($modelClassFilePath, $file->generate());
     return $fullClassName;
 }
コード例 #27
0
 public function testGeneratesNamespaceStatements()
 {
     $file = new FileGenerator();
     $file->setNamespace('Foo\\Bar');
     $generated = $file->generate();
     $this->assertContains('namespace Foo\\Bar', $generated, $generated);
 }
コード例 #28
0
 /**
  * generates file with target grid (if not exists yet)
  *
  * @param DataSetDescriptorInterface $dataSet
  * @param string $extends
  *            base class for grid
  * @return string full name of generated class
  */
 protected function generateGrid(DataSetDescriptorInterface $dataSet, $extends)
 {
     $name = $dataSet->getName();
     $className = $this->underscoreToCamelCase->filter($name) . "Grid";
     $namespace = $this->params->getParam("moduleName") . "\\Grid";
     $fullClassName = '\\' . $namespace . '\\' . $className;
     $gridClassFilePath = $this->moduleRoot() . "/src/" . $this->params->getParam("moduleName") . "/Grid/" . $className . ".php";
     if (file_exists($gridClassFilePath)) {
         return $fullClassName;
     }
     $class = new ClassGenerator();
     $class->setName($className);
     $class->setNamespaceName($namespace);
     $class->setExtendedClass($extends);
     $file = new FileGenerator();
     $docBlock = new \Zend\Code\Generator\DocblockGenerator(sprintf($this->codeLibrary()->get('grid.standardConfigDescription'), $name));
     $docBlock->setTag(new GenericTag('author', $this->params->getParam('author')))->setTag(new GenericTag('project', $this->params->getParam('project')))->setTag(new GenericTag('license', $this->params->getParam('license')))->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
     $file->setClass($class)->setDocBlock($docBlock);
     file_put_contents($gridClassFilePath, $file->generate());
     return $fullClassName;
 }
コード例 #29
0
 /**
  * Método para saida da classe gerada
  * @return string Classe gerada
  */
 public function generate()
 {
     $this->render();
     $fileGenerator = new Generator\FileGenerator(array('classes' => array($this->classGenerator)));
     return $fileGenerator->generate();
 }
コード例 #30
0
 /**
  * @param FileGenerator $file
  * @param TypeMap       $typeMap
  *
  * @return string
  */
 public function generate(FileGenerator $file, $typeMap)
 {
     $this->ruleSet->applyRules(new ClassMapContext($file, $typeMap));
     return $file->generate();
 }