Debugger.php 5.76 KB
Newer Older
doctrine's avatar
doctrine committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
Doctrine::autoload("EventListener");

class Doctrine_DebugMessage {
    private $code;
    private $object;
    public function __construct($object, $code) {
        $this->object = $object;
        $this->code   = $code;
    }
    final public function getCode() {
        return $this->code;
    }
    final public function getObject() {
        return $this->object;
    }
}
class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
19

doctrine's avatar
doctrine committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    const EVENT_LOAD            = 1;
    const EVENT_PRELOAD         = 2;
    const EVENT_SLEEP           = 3;
    const EVENT_WAKEUP          = 4;
    const EVENT_UPDATE          = 5;
    const EVENT_PREUPDATE       = 6;
    const EVENT_CREATE          = 7;
    const EVENT_PRECREATE       = 8;

    const EVENT_SAVE            = 9;
    const EVENT_PRESAVE         = 10;
    const EVENT_INSERT          = 11;
    const EVENT_PREINSERT       = 12;
    const EVENT_DELETE          = 13;
    const EVENT_PREDELETE       = 14;
    const EVENT_EVICT           = 15;
    const EVENT_PREEVICT        = 16;
    const EVENT_CLOSE           = 17;
    const EVENT_PRECLOSE        = 18;

    const EVENT_OPEN            = 19;
    const EVENT_COMMIT          = 20;
    const EVENT_PRECOMMIT       = 21;
    const EVENT_ROLLBACK        = 22;
    const EVENT_PREROLLBACK     = 23;
    const EVENT_BEGIN           = 24;
    const EVENT_PREBEGIN        = 25;
    const EVENT_COLLDELETE      = 26;
    const EVENT_PRECOLLDELETE   = 27;
    private $debug;
    
    public function getMessages() {
        return $this->debug;                              	
    }


    public function onLoad(Doctrine_Record $record) {
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_LOAD);
    }
    public function onPreLoad(Doctrine_Record $record) {
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRELOAD);
    }

    public function onSleep(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_SLEEP);
    }

    public function onWakeUp(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_WAKEUP);
    }

    public function onUpdate(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_UPDATE);
    }
    public function onPreUpdate(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREUPDATE);
    }

    public function onCreate(Doctrine_Record $record) {
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_CREATE);
    }
    public function onPreCreate(Doctrine_Record $record) {
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRECREATE);
    }

    public function onSave(Doctrine_Record $record) {
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_SAVE);
    }
    public function onPreSave(Doctrine_Record $record) {
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRESAVE);
    }

    public function onInsert(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_INSERT);
    }
    public function onPreInsert(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREINSERT);
    }

    public function onDelete(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_DELETE);
    }
    public function onPreDelete(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREDELETE);
    }

    public function onEvict(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_EVICT);
    }
    public function onPreEvict(Doctrine_Record $record) { 
        $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREEVICT);
    }

zYne's avatar
zYne committed
113 114
    public function onClose(Doctrine_Connection $connection) { 
         $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_CLOSE);
doctrine's avatar
doctrine committed
115
    }
zYne's avatar
zYne committed
116 117
    public function onPreClose(Doctrine_Connection $connection) { 
         $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PRECLOSE);
doctrine's avatar
doctrine committed
118 119
    }

zYne's avatar
zYne committed
120 121
    public function onOpen(Doctrine_Connection $connection) { 
         $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_OPEN);
doctrine's avatar
doctrine committed
122 123
    }

zYne's avatar
zYne committed
124 125
    public function onTransactionCommit(Doctrine_Connection $connection) { 
         $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_COMMIT);
doctrine's avatar
doctrine committed
126
    }
zYne's avatar
zYne committed
127 128
    public function onPreTransactionCommit(Doctrine_Connection $connection) { 
        $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PRECOMMIT);
doctrine's avatar
doctrine committed
129 130
    }

zYne's avatar
zYne committed
131 132
    public function onTransactionRollback(Doctrine_Connection $connection) {
        $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_ROLLBACK);
doctrine's avatar
doctrine committed
133
    }
zYne's avatar
zYne committed
134 135
    public function onPreTransactionRollback(Doctrine_Connection $connection) {
        $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PREROLLBACK);
doctrine's avatar
doctrine committed
136 137
    }

zYne's avatar
zYne committed
138 139
    public function onTransactionBegin(Doctrine_Connection $connection) {
        $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_BEGIN);
doctrine's avatar
doctrine committed
140
    }
zYne's avatar
zYne committed
141 142
    public function onPreTransactionBegin(Doctrine_Connection $connection) {
        $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PREBEGIN);
doctrine's avatar
doctrine committed
143 144 145 146 147 148 149 150 151
    }
    
    public function onCollectionDelete(Doctrine_Collection $collection) { 
        $this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_COLLDELETE);
    }
    public function onPreCollectionDelete(Doctrine_Collection $collection) {
        $this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_PRECOLLDELETE);
    }
}
152