Changeset 103

Show
Ignore:
Timestamp:
09/21/07 14:10:12 (1 year ago)
Author:
mikey
Message:

added implicit and explicit call to set as well as possibility for setting public properties
whitespace fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/XJConf/converters/AbstractObjectValueConverter.php

    r95 r103  
    3434        $children = $tag->getChildren(); 
    3535        foreach ($children as $child) { 
    36                if (!$child instanceof ValueModifier) { 
    37                    continue; 
    38                
     36            if (!$child instanceof ValueModifier) { 
     37                continue; 
     38           
    3939        } 
    4040    } 
     
    6161 
    6262            try { 
    63                 $method = $class->getMethod($att->getSetterMethod($tag)); 
    64                 $method->invoke($instance, $val); 
     63                if ($class->hasMethod($att->getSetterMethod($tag)) == true) { 
     64                    $method = $class->getMethod($att->getSetterMethod($tag)); 
     65                } elseif ($class->hasMethod('__set') == true) { 
     66                    $method = $class->getMethod('__set'); 
     67                } elseif ($class->hasProperty($att->getName()) == true) { 
     68                    $property = $class->getProperty($att->getName()); 
     69                    if ($property->isPublic() == true) { 
     70                        $property->setValue($instance, $val); 
     71                        continue; 
     72                    } 
     73                     
     74                    throw new ValueConversionException('Could not add attribute "' . $att->getName() . '" to "' . $this->getType() . '" using "' . $att->getSetterMethod($tag) . '()" or "__set()" or public property "' . $att->getName() . '", no such method defined.'); 
     75                } else { 
     76                    throw new ValueConversionException('Could not add attribute "' . $att->getName() . '" to "' . $this->getType() . '" using "' . $att->getSetterMethod($tag) . '()" or "__set()" or public property "' . $att->getName() . '", no such method defined.'); 
     77                } 
     78                 
     79                if ($method->getName() != '__set') { 
     80                    $method->invoke($instance, $val); 
     81                } else { 
     82                    $method->invokeArgs($instance, array($att->getName(), $val)); 
     83                } 
    6584            } catch (ReflectionException $re) { 
    66                 throw new ValueConversionException('Could not set attribute "' . $att->getName() . '" of "' . $this->getType() . '" using "' . $att->getSetterMethod($tag) . '()", exception message: "' . $re->getMessage() . '".'); 
     85                throw new ValueConversionException('Could not set attribute "' . $att->getName() . '" of "' . $this->getType() . '" using "' . $att->getSetterMethod($tag) . '()" or "__set()" or public property "' . $att->getName() . '", exception message: "' . $re->getMessage() . '".'); 
    6786            } 
    6887        } 
     
    97116                continue; 
    98117            } 
     118             
    99119            try { 
    100                 $class->getMethod($child->getSetterMethod())->invoke($instance, $child->getConvertedValue()); 
     120                if ($class->hasMethod($child->getSetterMethod()) == true) { 
     121                    $method = $class->getMethod($child->getSetterMethod()); 
     122                } elseif ($class->hasMethod('__set') == true) { 
     123                    $method = $class->getMethod('__set'); 
     124                } elseif ($class->hasProperty($child->getKey()) == true) { 
     125                    $property = $class->getProperty($child->getKey()); 
     126                    if ($property->isPublic() == true) { 
     127                        $property->setValue($instance, $child->getConvertedValue()); 
     128                        continue; 
     129                    } 
     130                     
     131                    throw new ValueConversionException('Could not add attribute "' . $child->getKey() . '" to "' . $this->getType() . '" using "' . $child->getSetterMethod() . '()" or "__set()" or public property "' . $child->getKey() . '", no such method defined.'); 
     132                } else { 
     133                    throw new ValueConversionException('Could not add attribute "' . $child->getKey() . '" to "' . $this->getType() . '" using "' . $child->getSetterMethod() . '()" or "__set()" or public property "' . $child->getKey() . '", no such method defined.'); 
     134                } 
     135                 
     136                if ($method->getName() != '__set') { 
     137                    $method->invoke($instance, $child->getConvertedValue()); 
     138                } else { 
     139                    $method->invokeArgs($instance, array($child->getName(), $child->getConvertedValue())); 
     140                } 
    101141            } catch (ReflectionException $re) { 
    102                 throw new ValueConversionException('Could not add child "' . $child->getKey() . '" to "' . $this->getType() . '" using "' . $child->getSetterMethod() . '()", exception message: "' . $re->getMessage() . '".'); 
     142                throw new ValueConversionException('Could not add child "' . $child->getKey() . '" to "' . $this->getType() . '" using "' . $child->getSetterMethod() . '()" or "__set()" or public property "' . $child->getKey() . '", exception message: "' . $re->getMessage() . '".'); 
    103143            } 
    104144        } 
  • trunk/autopackage2.php

    r92 r103  
    2525 * current version 
    2626 */ 
    27 $version       = $baseVersion . 'dev' . $argv[1]; 
    28 $dir           = dirname( __FILE__ ); 
     27$version    = $baseVersion . 'dev' . $argv[1]; 
     28$dir        = dirname( __FILE__ ); 
    2929 
    3030/** 
     
    5454- Added possibility to package XJConfForPHP as a STAR archive (mikey, schst) 
    5555- Added new value type "xjonf:auto-primitive" to guess the type of a scalar value (schst) 
     56- Added implicit and explicit call to __set as well as possibility for setting public properties (mikey) 
    5657Bugfixes: 
    5758- Fixed bug #6: Enable factory methods without parameters in PHP 5.0.x (schst) 
     
    7879    'packagedirectory'  => './', 
    7980    'dir_roles'         => array( 
    80                                                                 'docs' => 'doc', 
     81                                'docs' => 'doc', 
    8182                                 'examples' => 'doc', 
    8283                                 'tests' => 'test', 
  • trunk/package.php

    r92 r103  
    4848- Added possibility to package XJConfForPHP as a STAR archive (mikey, schst) 
    4949- Added new value type "xjonf:auto-primitive" to guess the type of a scalar value (schst) 
     50- Added implicit and explicit call to __set as well as possibility for setting public properties (mikey) 
    5051Bugfixes: 
    5152- Fixed bug #6: Enable factory methods without parameters in PHP 5.0.x (schst) 
     
    7273    'packagedirectory'  => './', 
    7374    'dir_roles'         => array( 
    74                                                                 'docs' => 'doc', 
     75                                'docs' => 'doc', 
    7576                                 'examples' => 'doc', 
    7677                                 'tests' => 'test', 
  • trunk/tests/runIntegration.php

    r91 r103  
    3030        $test->addTestFile(TEST_CWD . '/integration/ExampleCollectionTestCase.php'); 
    3131        $test->addTestFile(TEST_CWD . '/integration/ExampleExtensionTestCase.php'); 
     32        $test->addTestFile(TEST_CWD . '/integration/Test__setExplicitTestCase.php'); 
     33        $test->addTestFile(TEST_CWD . '/integration/Test__setImplicitTestCase.php'); 
     34        $test->addTestFile(TEST_CWD . '/integration/Test__setPublicPropertiesTestCase.php'); 
    3235        $test->addTestFile(TEST_CWD . '/integration/TestAttributesRequiredTestCase.php'); 
    3336        $test->addTestFile(TEST_CWD . '/integration/TestCDataSetterTestCase.php');