Development

Changeset 7385

You must first sign up to be able to contribute.

Changeset 7385

Show
Ignore:
Timestamp:
02/06/08 21:20:47 (10 months ago)
Author:
hartym
Message:

sfPropelImpersonatorPlugin: added debug options

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelImpersonatorPlugin/trunk/lib/sfPropelObjectPeerImpersonator.class.php

    r7218 r7385  
    1818class sfPropelObjectPeerImpersonator 
    1919{ 
     20  const DEBUG = false; 
     21  const DEBUG_POPULATE = false; 
     22 
    2023  /** 
    2124   * Relation type constants 
     
    279282    $this->initializeRelations(); 
    280283 
     284    if (self::DEBUG && self::DEBUG_POPULATE) 
     285    { 
     286      $debugRelations = array(); 
     287 
     288      foreach ($this->relations as $from => $fromData) 
     289      { 
     290        $fromClass = get_class($this->objects[$from]); 
     291 
     292        $debugRelations[$fromClass] = array(); 
     293        foreach ($fromData as $to => $relationsData) 
     294        { 
     295          $toClass = get_class($this->objects[$to]); 
     296 
     297          $debugRelations[$fromClass][$toClass] = $relationsData; 
     298        } 
     299      } 
     300 
     301      echo '<script>console.dir('.json_encode(array('sfPropelObjectPeerImpersonator'=>$debugRelations)).');</script>'; 
     302      echo '<pre>'; 
     303    } 
     304 
    281305    $result = array(); 
    282306    $allObjects = array(); 
     
    285309    while ($resultset->next()) 
    286310    { 
     311      if (self::DEBUG && self::DEBUG_POPULATE) 
     312      { 
     313        echo '-------------------- fetch a record --------------------'."\n"; 
     314      } 
     315 
    287316      $startcol = 1; 
    288317      $rowObjects = array(); 
     
    291320      foreach ($this->objects as $index => $object) 
    292321      { 
     322        if (self::DEBUG && self::DEBUG_POPULATE) 
     323        { 
     324          echo '<b>'.get_class($object).'</b>'."\n"; 
     325        } 
     326 
    293327        $rowObjects[$index] = clone $object; 
    294328        $startcol = $rowObjects[$index]->hydrate($resultset, $startcol); 
    295329 
    296330        // if the object was only made of null values, we consider it's inconsistent and forget it. 
    297         if (!$this->testConsistence($rowObjects[$index]->getPrimaryKey())) 
     331/*        if (!$this->testConsistence($rowObjects[$index]->getPrimaryKey())) 
    298332        { 
    299333          unset($rowObjects[$index]); 
    300334          continue; 
    301335        } 
     336        for now, let's say we keep it 
     337        */ 
    302338 
    303339        // initialize our object directory 
     
    330366        // If we're not in our "main" object context but in a sub-object, we're going to 
    331367        // fetch the available relations. 
    332         if ($index&&$isNewObject
     368        if ($index/*&&$isNewObject*/
    333369        { 
    334370          foreach ($this->getRelationsFor($index) as $relation) 
    335371          { 
     372            $currentObject = $rowObjects[$index]; 
     373 
    336374            switch ($relation['type']) 
    337375            { 
     
    340378               */ 
    341379              case self::RELATION_REVERSE: 
     380                if (self::DEBUG && self::DEBUG_POPULATE) 
     381                { 
     382                  echo '  <u>REVERSE</u>: '.$relation['classFrom'].' <-- '.$relation['classTo']."\n"; 
     383                } 
     384 
     385                $foreignClass = $relation['classFrom']; 
     386                $foreignObject = $rowObjects[$this->getIndexByClass($foreignClass)]; 
     387 
    342388                if ($isNewObject) 
    343389                { 
    344                   $rowObjects[$index]->{'init'.$relation['classFrom'].'s'}(); 
    345                 } 
    346  
    347                 $rowObjects[$index]->{'add'.$relation['classFrom']}($rowObjects[$this->getIndexByClass($relation['classFrom'])]); 
    348                 $rowObjects[$this->getIndexByClass($relation['classFrom'])]->{'set'.$relation['classTo']}($rowObjects[$index]); 
     390                  $currentObject->{'init'.$foreignClass.'s'}(); 
     391                } 
     392 
     393                $currentObject->{'add'.$foreignClass}($foreignObject); 
     394                $foreignObject->{'set'.$relation['classTo']}($currentObject); 
    349395                break; 
    350396 
    351               /** 
    352                * RELATION_I18N 
    353                */ 
     397                /** 
     398                 * RELATION_I18N 
     399                 */ 
    354400              case self::RELATION_I18N: 
     401                if (self::DEBUG && self::DEBUG_POPULATE) 
     402                { 
     403                  echo '  <u>I18N</u>: '.$relation['classTo'].' <-- '.$relation['classFrom']."\n"; 
     404                } 
     405 
    355406                if (null !== ($classToIndex = $this->getIndexByClass($relation['classTo']))) 
    356407                { 
     
    362413                break; 
    363414 
    364               /** 
    365                * RELATION_NORMAL 
    366                */ 
     415                /** 
     416                 * RELATION_NORMAL 
     417                 */ 
    367418              case self::RELATION_NORMAL: 
     419                if (self::DEBUG && self::DEBUG_POPULATE) 
     420                { 
     421                  echo '  <u>NORMAL</u>: '.$relation['classFrom'].' --> '.$relation['classTo']."\n"; 
     422                } 
     423 
     424 
    368425                if (null !== ($classToIndex = $this->getIndexByClass($relation['classTo']))) 
    369426                { 
    370                   $foreignObject =& $rowObjects[$classToIndex]; 
     427                  $foreignObject = $rowObjects[$classToIndex]; 
    371428 
    372429                  // local *---- foreign (local object has one foreign object) 
     
    391448        } 
    392449      } 
     450    } 
     451 
     452    if (self::DEBUG && self::DEBUG_POPULATE) 
     453    { 
     454      echo '</pre>'; 
    393455    } 
    394456