Luxbum.net - Script de galerie photo

Changeset 248

Show
Ignore:
Timestamp:
11/01/07 21:46:56 (1 year ago)
Author:
nicolas
Message:

correct getter & setter

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/api/Pluf/Model.php

    r246 r248  
    308308    function __get($prop) 
    309309    { 
    310         if (isset($this->$prop)) return $this->$prop; 
    311         if (isset($this->_data[$prop])) return $this->_data[$prop]; 
     310        if (isset($this->$prop)){ 
     311           return $this->$prop; 
     312        } 
     313        if (isset($this->_data[$prop])) { 
     314            return $this->_data[$prop]; 
     315        } 
    312316        else try { 
    313317            return $this->__call($prop, array()); 
     
    366370            Pluf::loadFunction($this->_methods_extra[$method][1]); 
    367371            return call_user_func_array($this->_methods_extra[$method][1], $args); 
     372        } 
     373         
     374        // Getter 
     375        $prop = strtolower(substr($method, 3)); 
     376        if (substr($method, 0, 3) === "get") { 
     377            if (isset($this->$prop)){ 
     378                 return $this->$prop; 
     379            } 
     380            if (isset($this->_data[$prop])) { 
     381                 return $this->_data[$prop]; 
     382            } 
     383        } 
     384         
     385        // Setter 
     386        $val = $args[0]; 
     387        if (substr($method, 0, 3) === "set") { 
     388            if (isset($this->$prop)) { 
     389                $this->$prop = $val; 
     390                return; 
     391            } 
     392            elseif (isset($this->_fk[$prop])) { 
     393                $this->_data[$prop] = $val->id; 
     394                return; 
     395            } 
     396            elseif (isset($this->_cols[$prop])) { 
     397                $this->_data[$prop] = $val; 
     398                return; 
     399            } 
    368400        } 
    369401        throw new Exception(sprintf('Method "%s" not available', $method));