本文整理匯總了PHP中Zend\Code\Generator\PropertyGenerator::generate方法的典型用法代碼示例。如果您正苦於以下問題:PHP PropertyGenerator::generate方法的具體用法?PHP PropertyGenerator::generate怎麽用?PHP PropertyGenerator::generate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Code\Generator\PropertyGenerator
的用法示例。
在下文中一共展示了PropertyGenerator::generate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: postRun
public function postRun(PartInterface $part)
{
/**
* @var $part \Model\Generator\Part\Entity
*/
/**
* @var $file \Model\Code\Generator\FileGenerator
*/
$file = $part->getFile();
$table = $part->getTable();
$tags = array(array('name' => 'return', 'description' => 'array'));
$docblock = new DocBlockGenerator('Initialize indexes');
$docblock->setTags($tags);
$resultIndexList = array();
$indexList = $table->getIndex();
foreach ($indexList as $index) {
$resIndex = $index->toArray();
$resIndex['column_list'] = array();
switch ($index->getType()) {
case AbstractIndex::TYPE_PRIMARY:
$resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_PRIMARY', ValueGenerator::TYPE_CONSTANT);
break;
case AbstractIndex::TYPE_KEY:
$resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_KEY', ValueGenerator::TYPE_CONSTANT);
break;
case AbstractIndex::TYPE_UNIQUE:
$resIndex['type'] = new ValueGenerator('AbstractModel::INDEX_UNIQUE', ValueGenerator::TYPE_CONSTANT);
break;
}
foreach ($resIndex['columns'] as $col) {
$resIndex['column_list'][] = $col['column_name'];
}
unset($resIndex['columns']);
$resultIndexList[$index->getName()] = $resIndex;
}
$property = new PropertyGenerator('indexList', $resultIndexList, PropertyGenerator::FLAG_PROTECTED);
$body = preg_replace("#^(\\s*)protected #", "\\1", $property->generate()) . "\n";
$method = new MethodGenerator();
$method->setName('initIndexList');
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PUBLIC);
$method->setFinal(true);
$method->setDocBlock($docblock);
$method->setBody(<<<EOS
{$body}
\$this->indexList = \$indexList;
\$this->setupIndexList();
EOS
);
$file->getClass()->addMethodFromGenerator($method);
}
示例2: testOtherTypesThrowExceptionOnGenerate
public function testOtherTypesThrowExceptionOnGenerate()
{
$codeGenProperty = new PropertyGenerator('someVal', new \stdClass());
$this->setExpectedException('Zend\\Code\\Generator\\Exception\\RuntimeException', 'Type "stdClass" is unknown or cannot be used as property default value');
$codeGenProperty->generate();
}
示例3: postRun
public function postRun(PartInterface $part)
{
/**
* @var $part \Model\Generator\Part\Entity
*/
/**
* @var $file \Model\Code\Generator\FileGenerator
*/
$file = $part->getFile();
$table = $part->getTable();
$tags = array(array('name' => 'var', 'description' => ' array связи'));
$docblock = new \Zend\Code\Generator\DocBlockGenerator('Связи');
$docblock->setTags($tags);
$linkList = $table->getLink();
/*if ($table->getColumn('parent_id')) {
echo $table->getName();
print_r($linkList);
die;
}*/
$relation = array();
foreach ($linkList as $link) {
$linkLocalColumnName = $link->getLocalColumn()->getName();
if ($link->getForeignTable() == $link->getLocalTable() && $link->getLocalColumn() == $link->getForeignColumn()) {
continue;
}
$foreignAliasName = $link->getForeignEntity();
$rel = $link->toArray();
unset($rel['name']);
switch ($link->getLinkType()) {
case AbstractLink::LINK_TYPE_ONE_TO_ONE:
$rel['type'] = new ValueGenerator('AbstractModel::ONE_TO_ONE', ValueGenerator::TYPE_CONSTANT);
break;
case AbstractLink::LINK_TYPE_ONE_TO_MANY:
$rel['type'] = new ValueGenerator('AbstractModel::ONE_TO_MANY', ValueGenerator::TYPE_CONSTANT);
break;
case AbstractLink::LINK_TYPE_MANY_TO_ONE:
$rel['type'] = new ValueGenerator('AbstractModel::MANY_TO_ONE', ValueGenerator::TYPE_CONSTANT);
break;
case AbstractLink::LINK_TYPE_MANY_TO_MANY:
$rel['type'] = new ValueGenerator('AbstractModel::MANY_TO_MANY', ValueGenerator::TYPE_CONSTANT);
break;
}
if ($link->getLocalColumn()->getName() != 'id' && !$link->getLinkTable() || $link->getLocalColumn()->getName() == 'id' && !$link->getLinkTable() && !$link->getLocalColumn()->isAutoincrement()) {
$rel['required_link'] = !$link->getLocalColumn()->isNullable();
$rel['link_method'] = 'link' . $link->getLocalEntityAsCamelCase() . 'To' . $link->getForeignEntityAsCamelCase();
$rel['unlink_method'] = 'deleteLink' . $link->getLocalEntityAsCamelCase() . 'To' . $link->getForeignEntityAsCamelCase();
} else {
if ($table->getName() == 'tag') {
if ($link->getLocalEntityAlias() != $link->getLocalTable()->getName()) {
$foreignAliasName .= '_as_' . $link->getLocalEntityAlias();
}
}
$rel['required_link'] = false;
$rel['link_method'] = 'link' . $link->getLocalEntityAsCamelCase() . 'To' . $link->getForeignEntityAsCamelCase();
$rel['unlink_method'] = 'deleteLink' . $link->getLocalEntityAsCamelCase() . 'To' . $link->getForeignEntityAsCamelCase();
}
$rel['local_entity'] = $link->getLocalEntity();
$rel['foreign_entity'] = $link->getForeignEntity();
$relation[$foreignAliasName] = $rel;
$relation[$foreignAliasName]['foreign_model'] = '\\Model\\' . $link->getForeignTable()->getNameAsCamelCase() . 'Model';
}
$property = new PropertyGenerator('relation', $relation, PropertyGenerator::FLAG_PROTECTED);
//$property->setDocBlock($docblock);
$method = new MethodGenerator();
$method->setName('initRelation');
$method->setFinal(true);
$method->setVisibility(AbstractMemberGenerator::VISIBILITY_PROTECTED);
$body = preg_replace("#^(\\s*)protected #", "\\1", $property->generate()) . "\n";
$body .= "\$this->setRelation(\$relation); \n";
$body .= "\$this->setupRelation();";
$docblock = new DocBlockGenerator('Настройка связей');
$method->setDocBlock($docblock);
$method->setBody($body);
//$file->getClass()->addPropertyFromGenerator($property);
$file->getClass()->addMethodFromGenerator($method);
}