Changeset 902

Show
Ignore:
Timestamp:
09/11/07 18:11:53 (1 year ago)
Author:
mikey
Message:

use new return type feature for better mapping of return types when method is not annotated

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/rdbms/persistence/creator/stubDatabaseCreator.php

    r899 r902  
    109109                continue; 
    110110            } else { 
    111                 // well, if we could check the return value this could be customized a bit... 
    112111                $column     = new stubDatabaseTableColumn(); 
    113112                $columnName = str_replace('get', '', $method->getName()); 
    114113                $column->setName(strtolower($columnName{0}) . substr($columnName, 1)); 
    115                 $column->setType('VARCHAR'); 
    116                 $column->setSize(255); 
     114                $returnType = $method->getReturnType(); 
     115                if (null === $returnType) { 
     116                    // no type hint or returns null -> ignore method 
     117                    continue; 
     118                } 
     119                 
     120                if ($returnType instanceof stubReflectionClass) { 
     121                    // not supported yet 
     122                    throw new stubDatabaseCreatorException('Returning classes from entity getter methods is currently not supported. Sorry. :('); 
     123                } 
     124                 
     125                switch (strtolower($returnType)) { 
     126                    case 'int': 
     127                    case 'integer': 
     128                        $column->setType('INT'); 
     129                        $column->setSize(10); 
     130                        break; 
     131                     
     132                    case 'double': 
     133                    case 'float': 
     134                        $column->setType('FLOAT'); 
     135                        $column->setSize(10); 
     136                        break; 
     137                     
     138                    case 'bool': 
     139                    case 'boolean': 
     140                        $column->setType('TINYINT'); 
     141                        $column->setSize(1); 
     142                        break; 
     143                     
     144                    default: 
     145                        $column->setType('VARCHAR'); 
     146                        $column->setSize(255); 
     147                } 
    117148            } 
    118149             
     
    123154            $this->connection->query(stubDatabaseQueryBuilderFactory::create($this->connection)->createTable($tableDescription)); 
    124155        } catch (stubException $se) { 
    125             throw new stubDatabaseCreatorException('Can not create table for ' . $fqClassName, $se); 
     156            throw new stubDatabaseCreatorException('Can not create table for ' . $entityClass->getFullQualifiedClassName(), $se); 
    126157        } 
    127158    } 
  • trunk/src/test/php/net/stubbles/rdbms/persistence/MockNoTableAnnotationPersistable.php

    r899 r902  
    6464    /** 
    6565     * method that has a no annotation 
     66     * 
     67     * @return string 
    6668     */ 
    6769    public function getDefaultValue() 
    6870    { 
    6971        return $this->defaultValue; 
     72    } 
     73 
     74    /** 
     75     * method that has a no annotation 
     76     * 
     77     * @return int 
     78     */ 
     79    public function getIntValue() 
     80    { 
     81        return 313; 
     82    } 
     83 
     84    /** 
     85     * method that has a no annotation 
     86     * 
     87     * @return  bool 
     88     */ 
     89    public function getBoolValue() 
     90    { 
     91        return true; 
     92    } 
     93 
     94    /** 
     95     * method that has a no annotation 
     96     * 
     97     * @return  float 
     98     */ 
     99    public function getFloatValue() 
     100    { 
     101        return 3.13; 
    70102    } 
    71103 
     
    80112        return 'ignored'; 
    81113    } 
     114 
     115    /** 
     116     * this method is ignored because it has no return doc annotation 
     117     */ 
     118    public function getIgnored2() 
     119    { 
     120        return 'ignored2'; 
     121    } 
    82122} 
    83123?> 
  • trunk/src/test/php/net/stubbles/rdbms/persistence/creator/stubDatabaseCreatorTestCase.php

    r899 r902  
    116116        $this->assertEqual($tableDescription->getName(), 'MockNoTableAnnotationPersistables'); 
    117117        $columns = $tableDescription->getColumns(); 
    118         $this->assertEqual(count($columns), 3); 
     118        $this->assertEqual(count($columns), 6); 
    119119        $this->assertEqual($columns[1]->getName(), 'id'); 
    120120        $this->assertEqual($columns[1]->getType(), 'INT'); 
     
    126126        $this->assertEqual($columns[3]->getType(), 'VARCHAR'); 
    127127        $this->assertEqual($columns[3]->getSize(), 255); 
     128        $this->assertEqual($columns[4]->getName(), 'intValue'); 
     129        $this->assertEqual($columns[4]->getType(), 'INT'); 
     130        $this->assertEqual($columns[4]->getSize(), 10); 
     131        $this->assertEqual($columns[5]->getName(), 'boolValue'); 
     132        $this->assertEqual($columns[5]->getType(), 'TINYINT'); 
     133        $this->assertEqual($columns[5]->getSize(), 1); 
     134        $this->assertEqual($columns[6]->getName(), 'floatValue'); 
     135        $this->assertEqual($columns[6]->getType(), 'FLOAT'); 
     136        $this->assertEqual($columns[6]->getSize(), 10); 
    128137    } 
    129138