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


PHP PropertyGenerator::setDocblock方法代码示例

本文整理汇总了PHP中Zend\Code\Generator\PropertyGenerator::setDocblock方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyGenerator::setDocblock方法的具体用法?PHP PropertyGenerator::setDocblock怎么用?PHP PropertyGenerator::setDocblock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Code\Generator\PropertyGenerator的用法示例。


在下文中一共展示了PropertyGenerator::setDocblock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addProperty

 /**
  * @param type $name
  * @param type $type
  * @param type $docString
  * @return PhpProperty
  */
 public function addProperty($name, $type, $docString)
 {
     $property = new PropertyGenerator();
     $docblock = new DocBlockGenerator();
     $property->setName($name);
     $property->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
     $docblock->setShortDescription($docString);
     $docblock->setTag(new Tag(array('name' => 'var', 'description' => $type)));
     $property->setDocblock($docblock);
     $this->addPropertyFromGenerator($property);
     return $property;
 }
开发者ID:nfx,项目名称:pugooroo,代码行数:18,代码来源:PhpClass.php

示例2: testPropertyCanHaveDocblock

    /**
     * @group ZF-7205
     */
    public function testPropertyCanHaveDocblock()
    {
        $codeGenProperty = new PropertyGenerator('someVal', 'some string value', PropertyGenerator::FLAG_STATIC | PropertyGenerator::FLAG_PROTECTED);
        $codeGenProperty->setDocblock('@var string $someVal This is some val');
        $expected = <<<EOS
    /**
     * @var string \$someVal This is some val
     */
    protected static \$someVal = 'some string value';
EOS;
        $this->assertEquals($expected, $codeGenProperty->generate());
    }
开发者ID:bradley-holt,项目名称:zf2,代码行数:15,代码来源:PropertyGeneratorTest.php

示例3: buildModel

 public function buildModel($model)
 {
     $class = new ClassGenerator($model->config->name);
     $class->setExtendedClass('\\app\\extensions\\data\\Model');
     $class->setNamespaceName('app\\models');
     $repository = "{$model->config->repository}" == "true" ? "(repositoryClass=\"app\\resources\\repository\\{$model->config->name}Repository\")\n" : null;
     $callback = "{$model->config->callback}" == "true" ? "@HasLifecycleCallbacks\n" : null;
     $table = "@Table(name=\"{$model->config->table}\")";
     $docblock = new DocblockGenerator("@Entity" . $repository . $callback . $table);
     $class->setDocblock($docblock);
     $validations = array();
     foreach ($model->fields->field as $field) {
         $type = "{$field->type}";
         $nullable = isset($field->nullable) ? ", nullable=\"{$field->nullable}\"" : null;
         $length = isset($field->length) ? ", length=\"{$field->length}\"" : null;
         $default = isset($field->default) ? "{$field->default}" : null;
         if ($type == "boolean" && $default) {
             $default = $default == "true" ? true : false;
         }
         $property = new PropertyGenerator("{$field->name}", $default, PropertyGenerator::FLAG_PROTECTED);
         switch ($type) {
             case "index":
                 $docblock = '@Id @Column(type="integer") @GeneratedValue';
                 break;
             case "relation":
                 $mappedBy = isset($field->mappedBy) ? ", mappedBy=\"{$field->mappedBy}\"" : "";
                 $inversedBy = isset($field->inversedBy) ? ", inversedBy=\"{$field->inversedBy}\"" : "";
                 $cascades = '';
                 if (isset($field->cascades->cascade[0])) {
                     $cascades = ", cascade={";
                     foreach ($field->cascades->cascade as $cascade) {
                         $cascades .= "\"{$cascade}\",";
                     }
                     $cascades = substr($cascades, 0, -1) . "}";
                 }
                 $docblock = "@{$field->relation}(targetEntity=\"{$field->targetEntity}\"{$mappedBy}{$inversedBy}{$cascades})";
                 break;
             default:
                 $docblock = "@Column(type=\"{$type}\"{$nullable}{$length})";
         }
         $property->setDocblock($docblock);
         $class->setProperty($property);
     }
     foreach ($model->validations->validation as $validation) {
         $validations["{$validation->field}"] = array();
         foreach ($validation->rules->rule as $rule) {
             $validations["{$validation->field}"][] = array("{$rule->type}", "message" => "{$rule->message}");
         }
     }
     if (!empty($validations)) {
         $class->setProperty(new PropertyGenerator("validations", $validations, PropertyGenerator::FLAG_PROTECTED));
     }
     if ($callback) {
         $beforePersist = new MethodGenerator('beforePersist');
         $beforeUpdate = new MethodGenerator('beforeUpdate');
         $beforePersist->setDocblock("@PrePersist");
         $beforeUpdate->setDocblock("@PreUpdate");
         $beforePersist->setBody("\$this->created = new \\DateTime();");
         $beforeUpdate->setBody("\$this->modified = new \\DateTime();");
         $class->setMethods(array($beforePersist, $beforeUpdate));
     }
     return $class;
 }
开发者ID:ncud,项目名称:sagalaya,代码行数:63,代码来源:Generator.php


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