当前位置: 首页>>代码示例>>PHP>>正文


PHP PropertyGenerator::generate方法代码示例

本文整理汇总了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);
    }
开发者ID:meniam,项目名称:model,代码行数:50,代码来源:IndexList.php

示例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();
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:6,代码来源:PropertyGeneratorTest.php

示例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);
 }
开发者ID:meniam,项目名称:model,代码行数:77,代码来源:Relationdefine.php


注:本文中的Zend\Code\Generator\PropertyGenerator::generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。