本文整理匯總了PHP中Zend\Code\Generator\PropertyGenerator::setConst方法的典型用法代碼示例。如果您正苦於以下問題:PHP PropertyGenerator::setConst方法的具體用法?PHP PropertyGenerator::setConst怎麽用?PHP PropertyGenerator::setConst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Code\Generator\PropertyGenerator
的用法示例。
在下文中一共展示了PropertyGenerator::setConst方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addMessageConstant
/**
* @param $className
*/
protected function addMessageConstant($className)
{
// generate property
$property = new PropertyGenerator();
$property->setName('INVALID');
$property->setDefaultValue('invalid' . $className);
$property->setConst(true);
// check for api docs
if ($this->config['flagAddDocBlocks']) {
$property->setDocBlock(new DocBlockGenerator('', '', [new GenericTag('const')]));
}
// add property
$this->addPropertyFromGenerator($property);
}
示例2: testPropertyCanProduceContstantModifierWithSetter
/**
* @group PR-704
*/
public function testPropertyCanProduceContstantModifierWithSetter()
{
$codeGenProperty = new PropertyGenerator('someVal', 'some string value');
$codeGenProperty->setConst(true);
$this->assertEquals(' const someVal = \'some string value\';', $codeGenProperty->generate());
}
示例3: createEnum
/**
* {@inheritdoc}
*/
public function createEnum(Type $type)
{
$class = $this->createClassFromType($type);
$parentType = $type->getParent()->getBase();
// set the parent class
if ($parentType->getSchema()->getTargetNamespace() !== SchemaReader::XSD_NS) {
// this enum extends another, it will indirectly extend \SplEnum
$class->setExtendedClass($parentType->getName());
} elseif ($this->config->isSplEnums()) {
// this enum has no parent, so make it extend \SplEnum
$class->setExtendedClass('\\SplEnum');
}
// create the class constants
$checks = $type->getRestriction()->getChecks();
foreach ($checks['enumeration'] as $enum) {
$property = new PropertyGenerator();
$property->setName(filter_var($enum['value'], FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName'))));
$property->setName(filter_var($property->getName(), FILTER_CALLBACK, array('options' => array($this, 'sanitizeConstantName'))));
$property->setConst(true);
$property->setDefaultValue($enum['value']);
if ($enum['doc']) {
$docDescription = new Html2Text($enum['doc']);
$property->setDocBlock(new DocBlockGenerator($docDescription->getText()));
}
$class->addPropertyFromGenerator($property);
}
$this->serializeClass($class);
// register the class in the classmap
$this->classmap[$class->getName()] = $class->getNamespaceName() . '\\' . $class->getName();
return $class->getName();
}