本文整理匯總了PHP中Zend\Code\Generator\MethodGenerator::setDocblock方法的典型用法代碼示例。如果您正苦於以下問題:PHP MethodGenerator::setDocblock方法的具體用法?PHP MethodGenerator::setDocblock怎麽用?PHP MethodGenerator::setDocblock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Code\Generator\MethodGenerator
的用法示例。
在下文中一共展示了MethodGenerator::setDocblock方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testDocblockGetterAndSetter
public function testDocblockGetterAndSetter()
{
$docblockGenerator = new \Zend\Code\Generator\DocblockGenerator();
$method = new MethodGenerator();
$method->setDocblock($docblockGenerator);
$this->assertTrue($docblockGenerator === $method->getDocblock());
}
示例2: 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;
}