Changeset 4865

Show
Ignore:
Timestamp:
08/29/08 21:01:19 (10 months ago)
Author:
jwage
Message:

fixes #1081 - Added pre/postValidate() support

Location:
branches/1.0/lib/Doctrine
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/Event.php

    r4494 r4865  
    6565    const RECORD_SERIALIZE   = 25; 
    6666    const RECORD_UNSERIALIZE = 26; 
     67    const RECORD_DQL_DELETE  = 27; 
    6768    const RECORD_DQL_SELECT  = 28; 
    68     const RECORD_DQL_DELETE  = 27; 
    6969    const RECORD_DQL_UPDATE  = 29; 
     70    const RECORD_VALIDATE    = 30; 
    7071 
    7172    /** 
     
    192193            case self::RECORD_DQL_UPDATE: 
    193194                return 'update records'; 
     195            case self::RECORD_VALIDATE: 
     196                return 'validate record'; 
    194197        } 
    195198    } 
  • branches/1.0/lib/Doctrine/Record.php

    r4853 r4865  
    286286 
    287287        // Run validation process 
    288         $validator = new Doctrine_Validator(); 
    289         $validator->validateRecord($this); 
    290         $this->validate(); 
    291         if ($this->_state == self::STATE_TDIRTY || $this->_state == self::STATE_TCLEAN) { 
    292             $this->validateOnInsert(); 
    293         } else { 
    294             $this->validateOnUpdate(); 
    295         } 
     288        $event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE); 
     289        $this->preValidate($event); 
     290        $this->getTable()->getRecordListener()->preValidate($event); 
     291         
     292        if ( ! $event->skipOperation) { 
     293         
     294            $validator = new Doctrine_Validator(); 
     295            $validator->validateRecord($this); 
     296            $this->validate(); 
     297            if ($this->_state == self::STATE_TDIRTY || $this->_state == self::STATE_TCLEAN) { 
     298                $this->validateOnInsert(); 
     299            } else { 
     300                $this->validateOnUpdate(); 
     301            } 
     302        } 
     303 
     304        $this->getTable()->getRecordListener()->postValidate($event); 
     305        $this->postValidate($event); 
    296306 
    297307        return $this->getErrorStack()->count() == 0 ? true : false; 
     
    408418     */ 
    409419    public function postInsert($event) 
     420    { } 
     421 
     422    /** 
     423     * Empty template method to provide concrete Record classes with the possibility 
     424     * to hook into the validation procedure. Useful for cleaning up data before  
     425     * validating it. 
     426     */ 
     427    public function preValidate($event) 
     428    { } 
     429    /** 
     430     * Empty template method to provide concrete Record classes with the possibility 
     431     * to hook into the validation procedure. 
     432     */ 
     433    public function postValidate($event) 
    410434    { } 
    411435 
  • branches/1.0/lib/Doctrine/Record/Listener.php

    r4478 r4865  
    8383    public function postHydrate(Doctrine_Event $event) 
    8484    { } 
     85 
     86    public function preValidate(Doctrine_Event $event) 
     87    { } 
     88     
     89    public function postValidate(Doctrine_Event $event) 
     90    { } 
    8591} 
  • branches/1.0/lib/Doctrine/Record/Listener/Chain.php

    r4612 r4865  
    207207        } 
    208208    } 
     209     
     210    public function preValidate(Doctrine_Event $event) 
     211    {  
     212        foreach ($this->_listeners as $listener) { 
     213            $listener->preValidate($event); 
     214        } 
     215    } 
     216     
     217    public function postValidate(Doctrine_Event $event) 
     218    { 
     219        foreach ($this->_listeners as $listener) { 
     220            $listener->postValidate($event); 
     221        } 
     222    } 
    209223}