Doctrine_Record::invokeSaveHooks PHP Метод

invokeSaveHooks() публичный Метод

$this->invokeSaveHooks('pre', 'save');
public invokeSaveHooks ( string $when, string $type, Doctrine_Event $event = null ) : Doctrine_Event
$when string 'post' or 'pre'
$type string serialize, unserialize, save, delete, update, insert, validate, dqlSelect, dqlDelete, hydrate
$event Doctrine_Event event raised
Результат Doctrine_Event the event generated using the type, if not specified
    public function invokeSaveHooks($when, $type, $event = null)
    {
        $func = $when . ucfirst($type);
        if (is_null($event)) {
            $constant = constant('Doctrine_Event::RECORD_' . strtoupper($type));
            //echo $func . " - " . 'Doctrine_Event::RECORD_' . strtoupper($type) . "\n";
            $event = new Doctrine_Event($this, $constant);
        }
        if (!isset($this->_invokedSaveHooks[$func])) {
            $this->{$func}($event);
            $this->getTable()->getRecordListener()->{$func}($event);
            $this->_invokedSaveHooks[$func] = $event;
        } else {
            $event = $this->_invokedSaveHooks[$func];
        }
        return $event;
    }

Usage Example

Пример #1
0
 /**
  * Inserts a record into database.
  *
  * This method inserts a transient record in the database, and adds it
  * to the identity map of its correspondent table. It proxies to @see 
  * processSingleInsert(), trigger insert hooks and validation of data
  * if required.
  *
  * @param Doctrine_Record $record   
  * @return boolean                  false if record is not valid
  */
 public function insert(Doctrine_Record $record)
 {
     $event = $record->invokeSaveHooks('pre', 'insert');
     if ($record->isValid(false, false)) {
         $table = $record->getTable();
         if (!$event->skipOperation) {
             if ($table->getOption('joinedParents')) {
                 // just for bc!
                 $this->_insertCTIRecord($table, $record);
                 //--
             } else {
                 $this->processSingleInsert($record);
             }
         }
         $table->addRecord($record);
         $record->invokeSaveHooks('post', 'insert', $event);
         return true;
     }
     return false;
 }