Changeset 4590

Show
Ignore:
Timestamp:
06/29/08 03:16:51 (6 months ago)
Author:
jwage
Message:

Fixing generation of setUp() to be cleaner, changed to not generate when it has no contents, and calling parent::setUp() only when necessary.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/lib/Doctrine/Import/Builder.php

    r4556 r4590  
    424424    public function buildSetUp(array $definition) 
    425425    { 
    426         if (isset($definition['inheritance']['type']) && ($definition['inheritance']['type'] == 'simple')) { 
    427             return; 
    428         } 
    429  
    430426        $ret = array(); 
    431427        $i = 0; 
    432  
    433         $ret[$i] = "    parent::setUp();"; 
    434         $i++; 
    435428 
    436429        if (isset($definition['relations']) && is_array($definition['relations']) && ! empty($definition['relations'])) { 
     
    508501        $code = trim($code); 
    509502 
    510         return PHP_EOL . '  public function setUp()' . PHP_EOL . '  {' . PHP_EOL . '    ' . $code . PHP_EOL . '  }'; 
     503        // If the body of the function has contents then we need to  
     504        if ($code) { 
     505            // If the body of the function has contents and we are using inheritance 
     506            // then we need call the parent::setUp() before the body of the function 
     507            if ($code && isset($definition['inheritance']['type'])) { 
     508                $code = "parent::setUp();" . PHP_EOL . '    ' . $code; 
     509            } 
     510        } 
     511 
     512        // If we have some code for the function then lets define it and return it 
     513        if ($code) { 
     514            return PHP_EOL . '  public function setUp()' . PHP_EOL . '  {' . PHP_EOL . '    ' . $code . PHP_EOL . '  }'; 
     515        } 
    511516    } 
    512517