當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。