本文整理汇总了PHP中Zend\Code\Generator\FileGenerator::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP FileGenerator::generate方法的具体用法?PHP FileGenerator::generate怎么用?PHP FileGenerator::generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\FileGenerator
的用法示例。
在下文中一共展示了FileGenerator::generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: 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();
}
示例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();
}
示例4: getContents
/**
* 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: 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();
}
示例6: writeClass
/**
* @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: getContents
/**
* 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: makeSureConfigFileExist
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: 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();
}
示例10: 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());
}
示例11: 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');
}
示例12: 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());
}
}
示例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());
}
示例14: generateBaseController
/**
* 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: testSetUsesWithGetUses
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);
}