/**
  * @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);
 }
 /**
  * @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
0
 /**
  * {@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();
 }