Changeset 4436 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
05/25/08 21:57:32 (8 months ago)
Author:
romanb
Message:

custom/magic accessors + test

Location:
trunk/lib/Doctrine
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine/ClassMetadata.php

    r4429 r4436  
    952952        $columnName = $this->getColumnName($fieldName); 
    953953        return isset($this->_mappedColumns[$columnName]['mutator']) ? 
    954         $this->_mappedColumns[$columnName]['mutator'] : null; 
     954                $this->_mappedColumns[$columnName]['mutator'] : null; 
    955955    } 
    956956 
  • trunk/lib/Doctrine/Entity.php

    r4417 r4436  
    249249        //-- 
    250250         
    251         self::$_useAutoAccessorOverride = false; // @todo read from attribute the first time 
     251        self::$_useAutoAccessorOverride = true; // @todo read from attribute the first time 
    252252    } 
    253253 
     
    995995    public function get($fieldName, $load = false) 
    996996    { 
     997        if ($getter = $this->_getCustomAccessor($fieldName)) { 
     998            return $this->$getter(); 
     999        } 
    9971000        $this->_invokeCustomAccessor($fieldName); 
    9981001         
     
    10281031    } 
    10291032     
    1030     private function _invokeCustomAccessor($fieldName) 
     1033    private function _getCustomMutator($fieldName) 
     1034    { 
     1035        if ( ! isset(self::$_mutatorCache[$this->_entityName][$fieldName])) { 
     1036            if (self::$_useAutoAccessorOverride) { 
     1037                $setterMethod = 'set' . Doctrine::classify($fieldName); 
     1038                if (method_exists($this, $setterMethod)) { 
     1039                    self::$_mutatorCache[$this->_entityName][$fieldName] = $setterMethod; 
     1040                } else { 
     1041                    self::$_mutatorCache[$this->_entityName][$fieldName] = false; 
     1042                } 
     1043            } 
     1044             
     1045            if ($setter = $this->_class->getCustomMutator($fieldName)) { 
     1046                self::$_mutatorCache[$this->_entityName][$fieldName] = $setter; 
     1047            } else if ( ! isset(self::$_mutatorCache[$this->_entityName][$fieldName])) { 
     1048                self::$_mutatorCache[$this->_entityName][$fieldName] = false; 
     1049            } 
     1050        } 
     1051         
     1052        return self::$_mutatorCache[$this->_entityName][$fieldName]; 
     1053    } 
     1054     
     1055    private function _getCustomAccessor($fieldName) 
    10311056    { 
    10321057        if ( ! isset(self::$_accessorCache[$this->_entityName][$fieldName])) { 
     
    10451070            } 
    10461071        } 
    1047         // invoke custom accessor, if it exists. 
    1048         if ($getter = self::$_accessorCache[$this->_entityName][$fieldName]) { 
    1049             return $this->$getter(); 
    1050         } 
     1072         
     1073        return self::$_accessorCache[$this->_entityName][$fieldName]; 
    10511074    } 
    10521075     
     
    10711094     */ 
    10721095    public function set($fieldName, $value, $load = false) 
    1073     {         
     1096    { 
     1097        if ($setter = $this->_getCustomMutator($fieldName)) { 
     1098            return $this->$setter($value); 
     1099        } 
     1100         
    10741101        if ($this->_class->hasField($fieldName)) { 
    10751102            if ($value instanceof Doctrine_Entity) { 
  • trunk/lib/Doctrine/EntityManager.php

    r4375 r4436  
    2020 */ 
    2121 
     22#namespace Doctrine::ORM; 
     23 
    2224/** 
    2325 * The EntityManager is a central access point to ORM functionality.