validateConstant() public static method

Validates a constant name against PHP naming conventions.
public static validateConstant ( string $name ) : string
$name string the name of the constant to test
return string The validated version of the submitted constant name
Ejemplo n.º 1
0
 /**
  * Implements the loading of the class object
  *
  * @throws Exception if the class is already generated(not null)
  */
 protected function generateClass()
 {
     if ($this->class != null) {
         throw new Exception("The class has already been generated");
     }
     $this->class = new PhpClass($this->phpIdentifier, $this->config->getClassExists());
     $first = true;
     foreach ($this->values as $value) {
         $name = Validator::validateConstant($value);
         if ($first) {
             $this->class->addConstant($name, '__default');
             $first = false;
         }
         $this->class->addConstant($value, $name);
     }
 }
Ejemplo n.º 2
0
 /**
  * Implements the loading of the class object
  *
  * @throws Exception if the class is already generated(not null)
  */
 protected function generateClass()
 {
     if ($this->class != null) {
         throw new Exception("The class has already been generated");
     }
     $this->class = new PhpClass($this->phpIdentifier, false);
     $first = true;
     $names = array();
     foreach ($this->values as $value) {
         $name = Validator::validateConstant($value);
         $name = Validator::validateUnique($name, function ($name) use($names) {
             return !in_array($name, $names);
         });
         if ($first) {
             $this->class->addConstant($name, '__default');
             $first = false;
         }
         $this->class->addConstant($value, $name);
         $names[] = $name;
     }
 }