Example #1
0
 /**
  * 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);
 }
 /**
  */
 public function testValue()
 {
     $this->assertEquals("testValue", $this->object->getValue());
     $this->object->setValue("newValue");
     $this->assertEquals("newValue", $this->object->getValue());
 }
 /**
  * Tests export.
  */
 public function testToString()
 {
     $tests = array('noNamespace' => "Constant [ string NO_NAMESPACE ] { no-namespace }\n", 'typeString' => "Constant [ string TYPE_STRING ] { string }\n", 'typeInteger' => "Constant [ integer TYPE_INTEGER ] { 1 }\n", 'typeIntegerNegative' => "Constant [ integer TYPE_INTEGER_NEGATIVE ] { -1 }\n", 'typeFloat' => "Constant [ double TYPE_FLOAT ] { 1.1 }\n", 'typeFloatNegative' => "Constant [ double TYPE_FLOAT_NEGATIVE ] { -1.1 }\n", 'typeBoolean' => "Constant [ boolean TYPE_BOOLEAN ] { 1 }\n", 'typeNull' => "Constant [ null TYPE_NULL ] {  }\n");
     foreach ($tests as $test => $expected) {
         $this->assertSame($expected, $this->getConstantTokenReflection($test)->__toString());
         $this->assertSame($expected, ReflectionConstant::export($this->getBroker(), $this->getClassName($test), $this->getConstantName($test), true));
         // Test loading from a string
         $this->assertSame($expected, $this->getConstantTokenReflection($test, true)->__toString());
     }
     $this->assertSame("Constant [ integer E_NOTICE ] { 8 }\n", ReflectionConstant::export($this->getBroker(), null, 'E_NOTICE', true));
 }