本文整理匯總了PHP中Zend\Code\Generator\MethodGenerator::setStatic方法的典型用法代碼示例。如果您正苦於以下問題:PHP MethodGenerator::setStatic方法的具體用法?PHP MethodGenerator::setStatic怎麽用?PHP MethodGenerator::setStatic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Code\Generator\MethodGenerator
的用法示例。
在下文中一共展示了MethodGenerator::setStatic方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testMethodWithStaticModifierIsEmitted
/**
* @group ZF-6444
*/
public function testMethodWithStaticModifierIsEmitted()
{
$methodGenerator = new MethodGenerator();
$methodGenerator->setName('foo');
$methodGenerator->setParameters(array('one'));
$methodGenerator->setStatic(true);
$expected = <<<EOS
public static function foo(\$one)
{
}
EOS;
$this->assertEquals($expected, $methodGenerator->generate());
}
示例2: postRun
public function postRun(PartInterface $part)
{
/**
* @var $part \Model\Generator\Part\Entity
*/
/**
* @var $file \Model\Code\Generator\FileGenerator
*/
$file = $part->getFile();
$tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
$tags = array(array('name' => 'return', 'description' => '\\Model\\' . $tableNameAsCamelCase . 'Model экземпляр модели'));
$docblock = new DocBlockGenerator('Получить экземпляр модели ' . $tableNameAsCamelCase);
$docblock->setTags($tags);
$method = new MethodGenerator();
$method->setName('getInstance');
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
$method->setStatic(true);
$method->setDocBlock($docblock);
$method->setBody(<<<EOS
return parent::getInstance();
EOS
);
$file->getClass()->addMethodFromGenerator($method);
}
示例3: postRun
public function postRun(PartInterface $part)
{
/**
* @var $part \Model\Generator\Part\Entity
*/
/**
* @var $file \Model\Code\Generator\FileGenerator
*/
$file = $part->getFile();
$columnCollection = $part->getTable()->getColumn();
$template = '';
/** @var $column Column */
foreach ($columnCollection as $column) {
$name = $column->getName();
$requiredFlag = !($column->isNullable() || $column->getName() == 'id');
if ($columnConfig = $part->getColumntConfig($column)) {
if ($columnConfig && isset($columnConfig['validators'])) {
foreach ($columnConfig['validators'] as $validator) {
if (isset($validator['params'])) {
$validatorParams = $this->prepareValidatorParams($validator['params'], $column);
$validatorParams = $this->varExportMin($validatorParams, true);
} else {
$validatorParams = null;
}
if ($validatorParams && $validatorParams != 'NULL') {
$template .= "\$this->addValidatorRule('{$name}', Model::getValidatorAdapter()->getValidatorInstance('{$validator['name']}', {$validatorParams}), " . ($requiredFlag ? 'true' : 'false') . ");\n";
} else {
$template .= "\$this->addValidatorRule('{$name}', Model::getValidatorAdapter()->getValidatorInstance('{$validator['name']}'), " . ($requiredFlag ? 'true' : 'false') . ");\n";
}
}
}
}
}
$template = rtrim($template, "\r\n, ");
//$tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
$tags = array(array('name' => 'return', 'description' => 'array Model массив с фильтрами по полям'));
$docblock = new DocBlockGenerator('Получить правила для фильтрации ');
$docblock->setTags($tags);
$method = new MethodGenerator();
$method->setName('initValidatorRules');
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
$method->setStatic(false);
$method->setFinal(true);
$method->setDocBlock($docblock);
$method->setBody(<<<EOS
{$template}
\$this->setupValidatorRules();
EOS
);
$file->getClass()->addMethodFromGenerator($method);
}
示例4: buildClass
private function buildClass($replacement)
{
$type = $this->splitNsandClass($replacement['originalFullyQualifiedType']);
$class = new ClassGenerator();
$class->setName($type['class']);
$class->setNamespaceName($type['ns']);
$class->setExtendedClass('\\Brads\\Ppm\\Proxy');
$properties = [];
$methods = [];
$implementedInterfaces = [];
foreach ($versions as $version => $info) {
foreach ($info['files'] as $file) {
echo "Parsing: " . $this->vendorDir . '/' . $package . '/' . $version . '/' . $file . "\n";
$parsedFile = new ReflectionFile($this->vendorDir . '/' . $package . '/' . $version . '/' . $file);
$parsedClass = $parsedFile->getFileNamespace($info['toNs'])->getClass($info['toNs'] . '\\' . $type['class']);
if ($parsedClass->getInterfaceNames() != null) {
$implementedInterfaces = array_merge($implementedInterfaces, $parsedClass->getInterfaceNames());
}
foreach ($parsedClass->getMethods() as $method) {
if ($method->isPublic()) {
$generatedMethod = new MethodGenerator();
$generatedMethod->setName($method->name);
$generatedMethod->setBody('echo "Hello world!";');
$generatedMethod->setAbstract($method->isAbstract());
$generatedMethod->setFinal($method->isFinal());
$generatedMethod->setStatic($method->isStatic());
$generatedMethod->setVisibility(MethodGenerator::VISIBILITY_PUBLIC);
foreach ($method->getParameters() as $param) {
$generatedParam = new ParameterGenerator();
$generatedParam->setName($param->name);
if ($param->hasType()) {
$generatedParam->setType($param->getType());
}
//$generatedParam->setDefaultValue($param->getDefaultValue());
$generatedParam->setPosition($param->getPosition());
$generatedParam->setVariadic($param->isVariadic());
$generatedParam->setPassedByReference($param->isPassedByReference());
$generatedMethod->setParameter($generatedParam);
}
$existingMethod = Linq::from($methods)->firstOrDefault(null, function (MethodGenerator $v) use($method) {
return $v->getName() == $method->name;
});
if ($existingMethod != null) {
$existingParams = $existingMethod->getParameters();
foreach ($generatedMethod->getParameters() as $newParam) {
$existingParam = Linq::from($existingParams)->firstOrDefault(function (ParameterGenerator $v) {
return $v->getName() == $newParam->getName();
});
if ($existingParam == null) {
$existingMethod->setParameter($newParam);
}
}
} else {
$methods[] = $generatedMethod;
}
}
}
foreach ($parsedClass->getProperties() as $prop) {
//$properties[] = PropertyGenerator::fromReflection($prop);
}
}
}
$class->setImplementedInterfaces($implementedInterfaces);
$class->addMethods($methods);
$class->addProperties($properties);
return (new FileGenerator(['classes' => [$class]]))->generate();
}
示例5: getStaticCreateMethod
/**
* Build a ::create() method for each data class
* @param string $class - The name of the class returned (self)
* @return \Zend\Code\Generator\MethodGenerator $method
*/
private function getStaticCreateMethod($class)
{
$method = new Generator\MethodGenerator();
$method->setDocBlock('@return ' . $class . ' $instance');
$method->setBody('return new self();');
$method->setName('create');
$method->setStatic(true);
return $method;
}
示例6: generateMethodsByLink
public function generateMethodsByLink($part)
{
/** @var $part \Model\Generator\Part\Model */
/** @var $file \Model\Code\Generator\FileGenerator */
$file = $part->getFile();
$table = $part->getTable();
$tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
$indexList = $table->getIndex();
/* $userStat = $part->getTable()->getSchema()->getTable('user');
$indexList = $userStat->getIndex();
foreach ($indexList as $index) {
print_r($index->toArray());
$column = reset($index);
if ($index->count() > 1 || !($link = $table->getLinkByColumn($column))) {
}
}
die;*/
$methods = array();
foreach ($indexList as $index) {
if ($index->getName() == 'PRIMARY') {
continue;
}
$column = reset($index);
if ($index->count() > 1 || !($link = $table->getLinkByColumn($column, $table->getName()))) {
continue;
}
if ($link->getLocalTable() == $table->getName()) {
$direct = true;
} else {
$direct = false;
}
$columnAsCamelCase = $link->getForeignTable()->getnameAsCamelCase();
$columnAsVar = $link->getForeignTable()->getnameAsVar();
$columnName = $link->getForeignTable()->getName();
$localColumnName = $link->getLocalColumn()->getName();
$localTableName = $link->getLocalTable()->getName();
$type = "{$columnAsCamelCase}Entity|{$columnAsCamelCase}Collection|array|string|integer";
$file->addUse('\\Model\\Entity\\' . $columnAsCamelCase . 'Entity');
$file->addUse('\\Model\\Collection\\' . $columnAsCamelCase . 'Collection');
$tags[] = array('name' => 'param', 'description' => "{$type} \$" . $columnAsVar);
$params[] = new \Zend\Code\Generator\ParameterGenerator($columnAsVar);
$docblock = new DocBlockGenerator('Получить один элемен по ');
$docblock->setTags($tags);
$method = new \Zend\Code\Generator\MethodGenerator();
$method->setName('getBy' . $columnAsCamelCase);
$method->setParameters($params);
$method->setVisibility(\Zend\Code\Generator\AbstractMemberGenerator::VISIBILITY_PUBLIC);
$method->setStatic(true);
$method->setDocBlock($docblock);
// print_r($link->toArray());z
if (($link->getLinkType() == AbstractLink::LINK_TYPE_ONE_TO_ONE || $link->getLinkType() == AbstractLink::LINK_TYPE_MANY_TO_ONE) && $direct) {
$method->setBody(<<<EOS
\$cond = \$this->prepareCond(\$cond);
\${$columnAsVar}Ids = {$columnAsCamelCase}Model::getInstance()->getIdsFromMixed(\${$columnAsVar});
if (!\${$columnAsVar}Ids) {
return \$cond->getEmptySelectResult();
}
\$cond->where(array('`{$localTableName}`.`{$localColumnName}`' => \${$columnAsVar}Ids));
return \$this->get(\$cond);
EOS
);
} elseif (($link->getLinkType() == AbstractLink::LINK_TYPE_ONE_TO_ONE || $link->getLinkType() == AbstractLink::LINK_TYPE_MANY_TO_ONE) && !$direct) {
$localTableName = $link->getLocalTable()->getName();
$localColumnName = $link->getLocalColumn()->getName();
$localTableNameAsVar = $link->getLocalTable()->getNameAsVar();
$localTableNameAsCamelCase = $link->getLocalTable()->getNameAsCamelCase();
$method->setBody(<<<EOS
\$cond = \$this->prepareCond(\$cond);
\${$columnAsVar}Collection = {$columnAsCamelCase}Model::getInstance()->getCollectionBy{$columnAsCamelCase}(\${$columnAsVar});
\${$localTableNameAsVar}Ids = array();
foreach (\${$columnAsVar}Collection as \${$columnAsVar}) {
\${$localTableNameAsVar}Ids[] = \${$columnAsVar}->get{$localTableNameAsCamelCase}Id();
}
\${$localTableNameAsVar}Ids = \$this->getIdsFromMixed(\${$localTableNameAsVar}Ids);
if (!\${$localTableNameAsVar}Ids) {
return \$cond->getEmptySelectResult();
}
\$cond->where(array('`{$localTableName}`.`{$localColumnName}`' => \${$localTableNameAsVar}Ids));
return \$this->get(\$cond);
EOS
);
} elseif ($link->getLinkType() == AbstractLink::LINK_TYPE_MANY_TO_MANY) {
die('ok');
}
$methods[] = $method;
}
return $methods;
}
示例7: getFactoryMethod
protected function getFactoryMethod(\ReflectionMethod $method, $classConfig)
{
$factoryMethod = new Generator\MethodGenerator($this->dic->getFactoryMethodName($method->name));
$factoryMethod->setParameter(new Generator\ParameterGenerator('object'));
$factoryMethod->setStatic(true);
$arguments = $method->getParameters();
$body = '$i = 0;' . PHP_EOL;
$methodArgumentStringParts = array();
if (count($arguments) > 0) {
$factoryMethod->setParameter(new \Zend\Code\Generator\ParameterGenerator('parameters', 'array', array()));
foreach ($arguments as $argument) {
/** @var \ReflectionParameter $argument */
$argumentName = $argument->name;
$methodArgumentStringParts[] = '$' . $argumentName;
}
$body .= 'if (!$parameters) {' . PHP_EOL;
foreach ($arguments as $argument) {
/** @var \ReflectionParameter $argument */
$injectionParameter = new \rg\injektor\generators\InjectionParameter($argument, $classConfig, $this->config, $this->dic, InjectionParameter::MODE_NO_ARGUMENTS);
try {
if ($injectionParameter->getClassName()) {
$this->factoryGenerator->processFileForClass($injectionParameter->getClassName());
}
if ($injectionParameter->getFactoryName()) {
$this->usedFactories[] = $injectionParameter->getFactoryName();
}
$body .= ' ' . $injectionParameter->getProcessingBody();
} catch (\Exception $e) {
$body .= ' ' . $injectionParameter->getDefaultProcessingBody();
}
}
$body .= '}' . PHP_EOL;
$body .= 'else if (array_key_exists(0, $parameters)) {' . PHP_EOL;
foreach ($arguments as $argument) {
/** @var \ReflectionParameter $argument */
$injectionParameter = new \rg\injektor\generators\InjectionParameter($argument, $classConfig, $this->config, $this->dic, InjectionParameter::MODE_NUMERIC);
try {
if ($injectionParameter->getClassName()) {
$this->factoryGenerator->processFileForClass($injectionParameter->getClassName());
}
if ($injectionParameter->getFactoryName()) {
$this->usedFactories[] = $injectionParameter->getFactoryName();
}
$body .= ' ' . $injectionParameter->getProcessingBody();
} catch (\Exception $e) {
$body .= ' ' . $injectionParameter->getDefaultProcessingBody();
}
}
$body .= '}' . PHP_EOL;
$body .= 'else {' . PHP_EOL;
foreach ($arguments as $argument) {
/** @var \ReflectionParameter $argument */
$injectionParameter = new \rg\injektor\generators\InjectionParameter($argument, $classConfig, $this->config, $this->dic, InjectionParameter::MODE_STRING);
try {
if ($injectionParameter->getClassName()) {
$this->factoryGenerator->processFileForClass($injectionParameter->getClassName());
}
if ($injectionParameter->getFactoryName()) {
$this->usedFactories[] = $injectionParameter->getFactoryName();
}
$body .= ' ' . $injectionParameter->getProcessingBody();
} catch (\Exception $e) {
$body .= ' ' . $injectionParameter->getDefaultProcessingBody();
}
}
$body .= '}' . PHP_EOL;
}
$body .= '$result = $object->' . $method->name . '(' . implode(', ', $methodArgumentStringParts) . ');' . PHP_EOL . PHP_EOL;
$body .= PHP_EOL . 'return $result;';
$factoryMethod->setBody($body);
return $factoryMethod;
}
示例8: postRun
public function postRun(PartInterface $part)
{
/**
* @var $part \Model\Generator\Part\Entity
*/
/**
* @var $file \Model\Code\Generator\FileGenerator
*/
$file = $part->getFile();
$file->addUse('Model\\Filter\\Filter');
$columnCollection = $part->getTable()->getColumn();
$template = '';
/** @var $column Column */
foreach ($columnCollection as $column) {
$name = $column->getName();
if ($columnConfig = $part->getColumntConfig($column)) {
if ($columnConfig && isset($columnConfig['filters'])) {
foreach ($columnConfig['filters'] as $filter) {
$filterParams = isset($validator['params']) ? $this->varExportMin($validator['params'], true) : null;
if ($filterParams && $filterParams != 'NULL') {
$template .= "\$this->addFilterRule('{$name}', Filter::getFilterInstance('{$filter['name']}', {$filterParams}));\n";
} else {
$template .= "\$this->addFilterRule('{$name}', Filter::getFilterInstance('{$filter['name']}'));\n";
}
}
}
}
/*
$filterArray = $column->getFilter();
foreach ($filterArray as $filter) {
if (empty($filter['params'])) {
$template .= "\$this->addFilterRule('$name', Filter::getFilterInstance('{$filter['name']}'));\n";
} else {
$filterParams = $this->varExportMin($filter['params'], true);
$template .= "\$this->addFilterRule('$name', Filter::getFilterInstance('{$filter['name']}', {$filterParams}));\n";
}
}
*/
if ($column->isNullable()) {
$template .= "\$this->addFilterRule('{$name}', Filter::getFilterInstance('\\Model\\Filter\\Null'));\n";
}
}
//$tableNameAsCamelCase = $part->getTable()->getNameAsCamelCase();
$tags = array(array('name' => 'return', 'description' => 'array Model массив с фильтрами по полям'));
$docblock = new DocBlockGenerator('Получить правила для фильтрации ');
$docblock->setTags($tags);
$method = new MethodGenerator();
$method->setName('initFilterRules');
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
$method->setStatic(false);
$method->setFinal(true);
$method->setDocBlock($docblock);
$method->setBody(<<<EOS
{$template}
\$this->setupFilterRules();
return \$this->getFilterRules();
EOS
);
$file->getClass()->addMethodFromGenerator($method);
}