Author: smarr
Date: Thu Dec 27 12:51:30 2007
New Revision: 7039

Log:
- fixed bug in delegation handling and getProperty
- added simple test for ezcReflectionClass::__call

Added:
    experimental/Reflection/tests/test_classes/MyReflectionClass.php
Modified:
    experimental/Reflection/src/class.php
    experimental/Reflection/tests/class_test.php
    experimental/Reflection/tests/suite.php

Modified: experimental/Reflection/src/class.php
==============================================================================
--- experimental/Reflection/src/class.php [iso-8859-1] (original)
+++ experimental/Reflection/src/class.php [iso-8859-1] Thu Dec 27 12:51:30 2007
@@ -57,10 +57,10 @@
      */
     public function __call( $method, $arguments )
     {
-        if ( !$this->class instanceof ReflectionClass )
-        {
-            // query external reflection object
-            return call_user_method( $this->class, $method, $arguments );
+        if ( $this->class instanceof ReflectionClass )
+        {
+            // query external reflection object
+            return call_user_func_array( array($this->class, $method), 
$arguments );
         } else {
             throw new Exception( 'Call to undefined method ' . __CLASS__ . 
'::' . $method );
         }
@@ -116,9 +116,9 @@
     public function getConstructor() {
         if ($this->class instanceof ReflectionClass) {
             // query external reflection object
-            $constructorName = $this->class->getConstructor();
-        } else {
-            $constructorName = parent::getConstructor();
+            $constructor = $this->class->getConstructor();
+        } else {
+            $constructor = parent::getConstructor();
         }
         if ($constructor != null) {
             $extCon = new ezcReflectionMethod($this->class, 
$constructor->getName());
@@ -167,9 +167,9 @@
         } else {
             $parentClass = parent::getParentClass();
         }
-        //TODO: continue work with external reflection object
-        if (is_object($class)) {
-            return new ezcReflectionClassType($class->getName());
+        
+        if (is_object($parentClass)) {
+            return new ezcReflectionClassType($parentClass->getName());
         }
         else {
             return null;
@@ -182,9 +182,22 @@
      * @throws RelectionException if property doesn't exists
      */
     public function getProperty($name) {
-        //FIXME: unused variable $pro
-        $pro = parent::getProperty($name);
-        return new ezcReflectionProperty($this->getName(), $name);
+               if ( $this->class instanceof ReflectionClass )
+        {
+            // query external reflection object
+            $prop = $this->class->getProperty($name);
+        } else {
+            $prop = parent::getProperty($name);
+        }
+        
+               if (is_object($prop)) {
+                       return new ezcReflectionProperty($prop, $name);
+        }
+        else {
+                       // TODO: may be we should throw an exception here
+            return null;
+        }
+        
     }
 
     /**

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] Thu Dec 27 
12:51:30 2007
@@ -26,6 +26,11 @@
     public function testGetName() {
         self::assertEquals($this->class->getName(), 'ezcReflectionClass');
     }
+       
+       public function testCall() {
+               $myRefClass = new ezcReflectionClass(new 
MyReflectionClass('MyReflectionClass'));
+               self::assertTrue($myRefClass->doSomeMetaProgramming());
+       }
 
     public function testGetMethod() {
         $method = $this->class->getMethod('getMethod');

Modified: experimental/Reflection/tests/suite.php
==============================================================================
--- experimental/Reflection/tests/suite.php [iso-8859-1] (original)
+++ experimental/Reflection/tests/suite.php [iso-8859-1] Thu Dec 27 12:51:30 
2007
@@ -29,6 +29,7 @@
 require_once 'test_classes/methods.php';
 require_once 'test_classes/methods2.php';
 require_once 'test_classes/functions.php';
+require_once 'test_classes/MyReflectionClass.php';
 
 /** Helper Lib */
 require_once 'test_helper.php';

Added: experimental/Reflection/tests/test_classes/MyReflectionClass.php
==============================================================================
--- experimental/Reflection/tests/test_classes/MyReflectionClass.php (added)
+++ experimental/Reflection/tests/test_classes/MyReflectionClass.php 
[iso-8859-1] Thu Dec 27 12:51:30 2007
@@ -1,0 +1,11 @@
+<?php
+
+class MyReflectionClass extends ReflectionClass {
+
+    public function doSomeMetaProgramming() 
+       {
+               return true;
+       }
+}
+
+?>


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to