Author: smarr Date: Fri Jan 4 12:18:45 2008 New Revision: 7068 Log: - fixed default value for filter param of getMethods and getProperties - fixed bugs in ezcReflectionExtension not returning parent:: values - fixed missing delegation in ezcReflectionExtension TODO: - discuss handling of missing types in the type system, using stings of the typename or dummy objects instead reflection objects? - documentation of methods derifed from reflection classes interfaces
Modified: experimental/Reflection/src/class.php experimental/Reflection/src/extension.php experimental/Reflection/src/property.php experimental/Reflection/tests/class_external_test.php experimental/Reflection/tests/class_test.php experimental/Reflection/tests/extension_test.php experimental/Reflection/tests/test_classes/MyReflectionClass.php experimental/Reflection/tests/test_classes/MyReflectionExtension.php Modified: experimental/Reflection/src/class.php ============================================================================== --- experimental/Reflection/src/class.php [iso-8859-1] (original) +++ experimental/Reflection/src/class.php [iso-8859-1] Fri Jan 4 12:18:45 2008 @@ -145,7 +145,7 @@ * ReflectionMethod::IS_FINAL * @return ezcReflectionMethod[] */ - public function getMethods($filter = null) { + public function getMethods($filter = -1) { $extMethods = array(); if ( $this->class instanceof ReflectionClass ) { $methods = $this->class->getMethods($filter); @@ -225,7 +225,7 @@ * ReflectionProperty::IS_PRIVATE * @return ezcReflectionProperty[] */ - public function getProperties($filter = null) { + public function getProperties($filter = -1) { if ( $this->class instanceof ReflectionClass ) { $props = $this->class->getProperties($filter); } else { Modified: experimental/Reflection/src/extension.php ============================================================================== --- experimental/Reflection/src/extension.php [iso-8859-1] (original) +++ experimental/Reflection/src/extension.php [iso-8859-1] Fri Jan 4 12:18:45 2008 @@ -72,7 +72,7 @@ if ( $this->reflectionSource ) { return $this->reflectionSource->getName(); } else { - parent::getName(); + return parent::getName(); } } @@ -80,7 +80,7 @@ if ( $this->reflectionSource ) { return $this->reflectionSource->getVersion(); } else { - parent::getVersion(); + return parent::getVersion(); } } @@ -88,7 +88,7 @@ if ( $this->reflectionSource ) { return $this->reflectionSource->getConstants(); } else { - parent::getConstants(); + return parent::getConstants(); } } @@ -96,7 +96,7 @@ if ( $this->reflectionSource ) { return $this->reflectionSource->getINIEntries(); } else { - parent::getINIEntries(); + return parent::getINIEntries(); } } @@ -104,7 +104,7 @@ if ( $this->reflectionSource ) { return $this->reflectionSource->getClassNames(); } else { - parent::getClassNames(); + return parent::getClassNames(); } } @@ -112,9 +112,25 @@ if ( $this->reflectionSource ) { return $this->reflectionSource->info(); } else { - parent::info(); + return parent::info(); } } + /** + * Use overloading to call additional methods + * of the reflection instance given to the constructor + * + * @param string $method Method to be called + * @param array(integer => mixed) $arguments Arguments that were passed + * @return mixed + */ + public function __call( $method, $arguments ) + { + if ( $this->reflectionSource ) { + return call_user_func_array( array($this->reflectionSource, $method), $arguments ); + } else { + throw new Exception( 'Call to undefined method ' . __CLASS__ . '::' . $method ); + } + } } ?> Modified: experimental/Reflection/src/property.php ============================================================================== --- experimental/Reflection/src/property.php [iso-8859-1] (original) +++ experimental/Reflection/src/property.php [iso-8859-1] Fri Jan 4 12:18:45 2008 @@ -32,8 +32,8 @@ * @param mixed $class * @param string $name */ - public function __construct($class, $name) { - if (!$class instanceof ReflectionProperty) { + public function __construct($class, $name = null) { + if ( !$class instanceof ReflectionProperty ) { parent::__construct($class, $name); } $this->reflectionSource = $class; Modified: experimental/Reflection/tests/class_external_test.php ============================================================================== --- experimental/Reflection/tests/class_external_test.php [iso-8859-1] (original) +++ experimental/Reflection/tests/class_external_test.php [iso-8859-1] Fri Jan 4 12:18:45 2008 @@ -81,7 +81,9 @@ public function testGetExtension() { parent::testGetExtension(); - $ext = $this->class->getExtension(); + self::assertNull($this->class->getExtension()); + $c = new ezcReflectionClass( new MyReflectionClass( 'ReflectionClass' ) ); + $ext = $c->getExtension(); self::assertTrue($ext->change()); } Modified: experimental/Reflection/tests/class_test.php ============================================================================== --- experimental/Reflection/tests/class_test.php [iso-8859-1] (original) +++ experimental/Reflection/tests/class_test.php [iso-8859-1] Fri Jan 4 12:18:45 2008 @@ -54,7 +54,8 @@ $methods = $this->class->getMethods(); - $expectedMethods = array('__construct', 'helloWorld'); + $expectedMethods = array('__construct', 'helloWorld', 'doSomeMetaProgramming'); + self::assertEquals(count($expectedMethods), count($methods)); foreach ($methods as $method) { self::assertType('ezcReflectionMethod', $method); self::assertContains($method->getName(), $expectedMethods); Modified: experimental/Reflection/tests/extension_test.php ============================================================================== --- experimental/Reflection/tests/extension_test.php [iso-8859-1] (original) +++ experimental/Reflection/tests/extension_test.php [iso-8859-1] Fri Jan 4 12:18:45 2008 @@ -43,8 +43,8 @@ } public function testGetName() { + self::assertEquals('SPL', $this->extSpl->getName()); self::assertEquals('Reflection', $this->extRef->getName()); - self::assertEquals('SPL', $this->extSpl->getName()); } public function testGetVersion() { Modified: experimental/Reflection/tests/test_classes/MyReflectionClass.php ============================================================================== --- experimental/Reflection/tests/test_classes/MyReflectionClass.php [iso-8859-1] (original) +++ experimental/Reflection/tests/test_classes/MyReflectionClass.php [iso-8859-1] Fri Jan 4 12:18:45 2008 @@ -19,7 +19,7 @@ return new MyReflectionMethod($this->getName(), $name); } - public function getMethods($filter = null) { + public function getMethods($filter = -1) { $methods = parent::getMethods($filter); $result = array(); @@ -33,7 +33,7 @@ return new MyReflectionProperty($this->getName(), $name); } - public function getProperties($filter = null) { + public function getProperties($filter = -1) { $props = parent::getProperties($filter); $result = array(); @@ -63,7 +63,12 @@ } public function getExtension() { - return new MyReflectionExtension(parent::getExtensionName()); + $extName = parent::getExtensionName(); + if ($extName) { + return new MyReflectionExtension($extName); + } else { + return NULL; + } } } Modified: experimental/Reflection/tests/test_classes/MyReflectionExtension.php ============================================================================== --- experimental/Reflection/tests/test_classes/MyReflectionExtension.php [iso-8859-1] (original) +++ experimental/Reflection/tests/test_classes/MyReflectionExtension.php [iso-8859-1] Fri Jan 4 12:18:45 2008 @@ -20,5 +20,9 @@ } return $result; } + + public function change() { + return true; + } } ?> -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components