/** * Adds a property to the definition * * @param ClassProperty $property * @throws CompilerException */ public function addProperty(ClassProperty $property) { if (isset($this->properties[$property->getName()])) { throw new CompilerException("Property '" . $property->getName() . "' was defined more than one time", $property->getOriginal()); } $this->properties[$property->getName()] = $property; }
/** * Build property * * @param ClassProperty $property * @param string $indent * @return string */ protected function buildProperty(ClassProperty $property, $indent) { $visibility = $property->isPublic() ? 'public' : $property->isProtected() ? 'protected' : 'private'; if ($property->isStatic()) { $visibility = 'static ' . $visibility; } $source = $visibility . ' $' . $property->getName(); $original = $property->getOriginal(); if (isset($original['default'])) { $source .= ' = ' . $this->wrapPHPValue(array('default' => $original['default'])); } $docBlock = new DocBlock($property->getDocBlock(), $indent); return $docBlock . "\n" . $indent . $source . ';'; }
/** * @param ClassProperty $property * * @return string */ protected function buildProperty(ClassProperty $property) { $visibility = $property->isPublic() ? 'public' : $property->isProtected() ? 'protected' : 'private'; if ($property->isStatic()) { $visibility = 'static ' . $visibility; } $source = $visibility . ' $' . $property->getName(); switch ($property->getType()) { case 'null': // @TODO: Fix getting value // @TODO: Fix getting value case 'static-constant-access': break; case 'string': $source .= ' = "' . $property->getValue() . '"'; break; case 'empty-array': $source .= ' = array()'; break; case 'array': $source .= ' = array(' . implode(', ', $property->getValue()) . ')'; break; default: $source .= ' = ' . $property->getValue(); break; } $docBlock = new DocBlock($property->getDocBlock(), 4); return $docBlock . "\n " . $source . ';'; }