當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FileGenerator::setClass方法代碼示例

本文整理匯總了PHP中Zend\Code\Generator\FileGenerator::setClass方法的典型用法代碼示例。如果您正苦於以下問題:PHP FileGenerator::setClass方法的具體用法?PHP FileGenerator::setClass怎麽用?PHP FileGenerator::setClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Code\Generator\FileGenerator的用法示例。


在下文中一共展示了FileGenerator::setClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: generate

 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();
 }
開發者ID:boyhagemann,項目名稱:crud,代碼行數:34,代碼來源:ControllerGenerator.php

示例2: generate

 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();
 }
開發者ID:boyhagemann,項目名稱:framework,代碼行數:26,代碼來源:ControllerGenerator.php

示例3: getContents

 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();
 }
開發者ID:rafalwrzeszcz,項目名稱:zf2,代碼行數:7,代碼來源:DbTableFile.php

示例4: convert

 protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $generator = new ClassGenerator();
     $generator->setTargetPhpVersion($converter->getTargetPhpVersion());
     $generator->setBaseClass($converter->getBaseClass());
     $pathGenerator = new Psr4PathGenerator($targets);
     $progress = $this->getHelperSet()->get('progress');
     $items = $converter->convert($schemas);
     $progress->start($output, count($items));
     foreach ($items as $item) {
         $progress->advance(1, true);
         $output->write(" Creating <info>" . $output->getFormatter()->escape($item->getFullName()) . "</info>... ");
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         if ($generator->generate($classGen, $item)) {
             $fileGen->setClass($classGen);
             $fileGen->write();
             $output->writeln("done.");
         } else {
             $output->write("skip.");
         }
     }
     $progress->finish();
 }
開發者ID:harold4,項目名稱:xsd2php,代碼行數:26,代碼來源:ConvertToPHP.php

示例5: execute

 /**
  * (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();
 }
開發者ID:slavomirkuzma,項目名稱:itc-bundle,代碼行數:32,代碼來源:Element.php

示例6: getContents

 /**
  * getContents()
  *
  * @return string
  */
 public function getContents()
 {
     $filter = new \Zend\Filter\Word\DashToCamelCase();
     $className = $filter->filter($this->_forControllerName) . 'ControllerTest';
     $codeGenFile = new FileGenerator();
     $codeGenFile->setRequiredFiles(array('PHPUnit/Framework/TestCase.php'));
     $codeGenFile->setClass(new ClassGenerator($className, null, null, 'PHPUnit_Framework_TestCase', array(), array(), array('methods' => array(new MethodGenerator('setUp', array(), MethodGenerator::FLAG_PUBLIC, '        /* Setup Routine */'), new MethodGenerator('tearDown', array(), MethodGenerator::FLAG_PUBLIC, '        /* Tear Down Routine */')))));
     return $codeGenFile->generate();
 }
開發者ID:rafalwrzeszcz,項目名稱:zf2,代碼行數:14,代碼來源:TestApplicationControllerFile.php

示例7: write

 public function write(array $items)
 {
     foreach ($items as $item) {
         $path = $this->pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $fileGen->setClass($item);
         $fileGen->write();
         $this->logger->debug(sprintf("Written PHP class file %s", $path));
     }
     $this->logger->info(sprintf("Written %s STUB classes", count($items)));
 }
開發者ID:goetas-webservices,項目名稱:xsd2php,代碼行數:12,代碼來源:PHPClassWriter.php

示例8: generate

 /**
  * @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();
 }
開發者ID:phpro,項目名稱:soap-client,代碼行數:18,代碼來源:TypeGenerator.php

示例9: convert

 protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $this->setClientMethodDocblocks();
     $generator = new ClassGenerator();
     $pathGenerator = new Psr4PathGenerator($targets);
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'Or', function ($type) use($schemas) {
         return "OrElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'And', function ($type) use($schemas) {
         return "AndElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'EmailAddress', function ($type) use($schemas) {
         return "garethp\\ews\\API\\Type\\EmailAddressType";
     });
     $items = $converter->convert($schemas);
     $progress = new ProgressBar($output, count($items));
     $progress->start(count($items));
     $classMap = [];
     foreach ($items as $item) {
         /** @var PHPClass $item */
         $progress->advance(1, true);
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         $itemClass = $item->getNamespace() . '\\' . $item->getName();
         if (class_exists($itemClass)) {
             $fileGen = FileGenerator::fromReflectedFileName($path);
             $fileGen->setFilename($path);
             $classGen = Generator\ClassGenerator::fromReflection(new ClassReflection($itemClass));
         }
         if ($generator->generate($classGen, $item)) {
             $namespace = $classGen->getNamespaceName();
             $fileGen->setClass($classGen);
             $fileGen->write();
             if (isset($item->type) && $item->type->getName() != "" && $item->getNamespace() !== Enumeration::class) {
                 $classMap[$item->type->getName()] = '\\' . $namespace . '\\' . $classGen->getName();
             }
         } else {
         }
     }
     $mappingClassReflection = new ClassReflection(ClassMap::class);
     $mappingClass = Generator\ClassGenerator::fromReflection($mappingClassReflection);
     $mappingClass->getProperty('classMap')->setDefaultValue($classMap);
     $fileGen = new FileGenerator();
     $fileGen->setFilename($mappingClassReflection->getFileName());
     $fileGen->setClass($mappingClass);
     $fileGen->write();
     $progress->finish();
 }
開發者ID:garethp,項目名稱:php-ews,代碼行數:50,代碼來源:ConvertToPHP.php

示例10: convert

 protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $generator = new ClassGenerator();
     $pathGenerator = new Psr4PathGenerator($targets);
     $progress = $this->getHelperSet()->get('progress');
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'Or', function ($type) use($schemas) {
         return "OrElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'And', function ($type) use($schemas) {
         return "AndElement";
     });
     $converter->addAliasMap('http://schemas.microsoft.com/exchange/services/2006/types', 'EmailAddress', function ($type) use($schemas) {
         return "jamesiarmes\\PEWS\\API\\Type\\EmailAddressType";
     });
     $items = $converter->convert($schemas);
     $progress->start($output, count($items));
     $classMap = [];
     foreach ($items as $item) {
         /** @var PHPClass $item */
         $progress->advance(1, true);
         $output->write(" Creating <info>" . $output->getFormatter()->escape($item->getFullName()) . "</info>... ");
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         $itemClass = $item->getNamespace() . '\\' . $item->getName();
         if (class_exists($itemClass)) {
             $existingClass = Generator\ClassGenerator::fromReflection(new ClassReflection($itemClass));
             $classGen = $existingClass;
         }
         if ($generator->generate($classGen, $item)) {
             $fileGen->setClass($classGen);
             $fileGen->write();
             $output->writeln("done.");
             if (isset($item->type) && $item->type->getName() != "") {
                 $classMap[$item->type->getName()] = '\\' . $classGen->getNamespaceName() . '\\' . $classGen->getName();
             }
         } else {
             $output->write("skip.");
         }
     }
     $mappingClassReflection = new ClassReflection(ClassMap::class);
     $mappingClass = Generator\ClassGenerator::fromReflection($mappingClassReflection);
     $mappingClass->getProperty('classMap')->setDefaultValue($classMap);
     $fileGen = new FileGenerator();
     $fileGen->setFilename($mappingClassReflection->getFileName());
     $fileGen->setClass($mappingClass);
     $fileGen->write();
     $progress->finish();
 }
開發者ID:jchoi926,項目名稱:php-ews,代碼行數:50,代碼來源:ConvertToPHP.php

示例11: generate

 /**
  *
  * @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());
 }
開發者ID:slavomirkuzma,項目名稱:itc-bundle,代碼行數:23,代碼來源:Document.php

示例12: Type

 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');
 }
開發者ID:phpro,項目名稱:soap-client,代碼行數:17,代碼來源:TypeGeneratorSpec.php

示例13: execute

 /**
  * (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());
 }
開發者ID:slavomirkuzma,項目名稱:itc-bundle,代碼行數:26,代碼來源:Document.php

示例14: generate

 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());
     }
 }
開發者ID:slavomirkuzma,項目名稱:itc-bundle,代碼行數:21,代碼來源:Element.php

示例15: writeClass

 /**
  * @param ClassGenerator $class
  */
 protected function writeClass(ClassGenerator $class)
 {
     $generator = new FileGenerator();
     $generator->setClass($class);
     $generator->setFilename('src/Flex/Code/Html/Tag/' . $class->getName() . '.php');
     $generator->write();
 }
開發者ID:elnebuloso,項目名稱:flex-code-html,代碼行數:10,代碼來源:Generator.php


注:本文中的Zend\Code\Generator\FileGenerator::setClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。