/** * Exports the PHP code * * @return string */ public function exportCode() { $code_lines = array(); $code_lines[] = '<?php'; // Export the namespace if ($this->_reflection_class->getNamespaceName()) { $code_lines[] = ''; $code_lines[] = 'namespace ' . $this->_reflection_class->getNamespaceName() . ';'; $code_lines[] = ''; } // Export the class' signature $code_lines[] = sprintf('%s%s%s %s%s%s', $this->_reflection_class->isAbstract() ? 'abstract ' : '', $this->_reflection_class->isFinal() ? 'final ' : '', $this->_reflection_class->isInterface() ? 'interface' : ($this->_reflection_class->isTrait() ? 'trait' : 'class'), $this->getClassName(), $this->_getParentClassName() ? " extends {$this->_getParentClassName()}" : '', $this->_getInterfaceNames() ? " implements " . join(', ', $this->_getInterfaceNames()) : ''); $code_lines[] = '{'; $code_lines[] = ''; // Export constants foreach ($this->_reflection_class->getConstants() as $name => $value) { $reflection_constant = new ReflectionConstant($name, $value); $code_lines[] = "\t" . $reflection_constant->exportCode(); $code_lines[] = ''; } // Export properties foreach ($this->_reflection_class->getProperties() as $property) { $reflection_property = new ReflectionProperty($property); $code_lines[] = "\t" . $reflection_property->exportCode(); $code_lines[] = ''; } // Export methods foreach ($this->_reflection_class->getMethods() as $method) { $reflection_method = new ReflectionMethod($method); $code_lines[] = "\t" . $reflection_method->exportCode(); $code_lines[] = ''; } $code_lines[] = '}'; return join("\n", $code_lines); }