Changeset 4357

Show
Ignore:
Timestamp:
05/10/08 04:09:24 (14 months ago)
Author:
jwage
Message:

Tabs to spaces and trimmed trailing whitespace.

Files:
1 modified

Legend:

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

    r4340 r4357  
    4141    /** 
    4242     * _path 
    43      *  
     43     * 
    4444     * the path where imported files are being generated 
    4545     * 
     
    4747     */ 
    4848    protected $_path = ''; 
    49      
     49 
    5050    /** 
    5151     * _packagesPrefix 
     
    7171    /** 
    7272     * _suffix 
    73      *  
     73     * 
    7474     * File suffix to use when writing class definitions 
    7575     * 
     
    8080    /** 
    8181     * _generateBaseClasses 
    82      *  
     82     * 
    8383     * Bool true/false for whether or not to generate base classes 
    8484     * 
     
    107107    /** 
    108108     * _baseClassesDirectory 
    109      *  
     109     * 
    110110     * Directory to put the generate base classes in 
    111111     * 
     
    113113     */ 
    114114    protected $_baseClassesDirectory = 'generated'; 
    115      
     115 
    116116    /** 
    117117     * _baseClassName 
     
    163163        } 
    164164    } 
    165      
     165 
    166166    /** 
    167167     * setPackagePath 
    168168     * 
    169      * @param string $packagesPrefix  
     169     * @param string $packagesPrefix 
    170170     * @return void 
    171171     */ 
     
    178178     * setPackagesPath 
    179179     * 
    180      * @param string $packagesPath  
     180     * @param string $packagesPath 
    181181     * @return void 
    182182     */ 
     
    187187        } 
    188188    } 
    189      
     189 
    190190    /** 
    191191     * generateBaseClasses 
     
    225225     * Generate physical accessors for columns and relationships 
    226226     * 
    227      * @param boolean $bool  
     227     * @param boolean $bool 
    228228     * @return boolean $generateAccessors 
    229229     */ 
     
    240240     * setBaseClassPrefix 
    241241     * 
    242      * @param string $prefix  
     242     * @param string $prefix 
    243243     * @return void 
    244244     */ 
     
    247247        $this->_baseClassPrefix = $prefix; 
    248248    } 
    249      
     249 
    250250    /** 
    251251     * getBaseClassPrefix 
     
    257257        return $this->_baseClassPrefix; 
    258258    } 
    259      
     259 
    260260    /** 
    261261     * setBaseClassesDirectory 
     
    267267        $this->_baseClassesDirectory = $baseClassesDirectory; 
    268268    } 
    269      
     269 
    270270    /** 
    271271     * setBaseClassName 
     
    277277        $this->_baseClassName = $className; 
    278278    } 
    279      
     279 
    280280    /** 
    281281     * setSuffix 
    282282     * 
    283      * @param string $suffix  
     283     * @param string $suffix 
    284284     * @return void 
    285285     */ 
     
    302302     * setOptions 
    303303     * 
    304      * @param string $options  
     304     * @param string $options 
    305305     * @return void 
    306306     */ 
     
    317317     * setOption 
    318318     * 
    319      * @param string $key  
    320      * @param string $value  
     319     * @param string $key 
     320     * @param string $value 
    321321     * @return void 
    322322     */ 
     
    324324    { 
    325325        $name = 'set' . Doctrine_Inflector::classify($key); 
    326          
     326 
    327327        if (method_exists($this, $name)) { 
    328328            $this->$name($value); 
     
    335335    /** 
    336336     * loadTemplate 
    337      *  
     337     * 
    338338     * Loads the class template used for generating classes 
    339339     * 
    340340     * @return void 
    341341     */ 
    342     public function loadTemplate()  
     342    public function loadTemplate() 
    343343    { 
    344344        if (isset(self::$_tpl)) { 
     
    368368            return; 
    369369        } 
    370          
     370 
    371371        $ret = array(); 
    372          
     372 
    373373        $i = 0; 
    374          
     374 
    375375        if (isset($definition['inheritance']['type']) && $definition['inheritance']['type'] == 'concrete') { 
    376376            $ret[$i] = "    parent::setTableDefinition();"; 
    377377            $i++; 
    378378        } 
    379          
     379 
    380380        if (isset($definition['tableName']) && !empty($definition['tableName'])) { 
    381381            $ret[$i] = "    ".'$this->setTableName(\''. $definition['tableName'].'\');'; 
    382382            $i++; 
    383383        } 
    384          
     384 
    385385        if (isset($definition['columns']) && is_array($definition['columns']) && !empty($definition['columns'])) { 
    386386            $ret[$i] = $this->buildColumns($definition['columns']); 
    387387            $i++; 
    388388        } 
    389          
     389 
    390390        if (isset($definition['indexes']) && is_array($definition['indexes']) && !empty($definition['indexes'])) { 
    391391            $ret[$i] = $this->buildIndexes($definition['indexes']); 
    392392            $i++; 
    393393        } 
    394          
     394 
    395395        if (isset($definition['attributes']) && is_array($definition['attributes']) && !empty($definition['attributes'])) { 
    396396            $ret[$i] = $this->buildAttributes($definition['attributes']); 
    397397            $i++; 
    398398        } 
    399          
     399 
    400400        if (isset($definition['options']) && is_array($definition['options']) && !empty($definition['options'])) { 
    401401            $ret[$i] = $this->buildOptions($definition['options']); 
    402402            $i++; 
    403403        } 
    404          
     404 
    405405        if (isset($definition['inheritance']['subclasses']) && ! empty($definition['inheritance']['subclasses'])) { 
    406406            $ret[$i] = "    ".'$this->setSubClasses('. $this->varExport($definition['inheritance']['subclasses']).');'; 
    407407            $i++; 
    408408        } 
    409          
     409 
    410410        $code = implode(PHP_EOL, $ret); 
    411411        $code = trim($code); 
    412          
     412 
    413413        return PHP_EOL . "  public function setTableDefinition()" . PHP_EOL . '  {' . PHP_EOL . '    ' . $code . PHP_EOL . '  }'; 
    414414    } 
     
    417417     * buildSetUp 
    418418     * 
    419      * @param  array $options  
    420      * @param  array $columns  
    421      * @param  array $relations  
     419     * @param  array $options 
     420     * @param  array $columns 
     421     * @param  array $relations 
    422422     * @return string 
    423423     */ 
     
    443443                } 
    444444 
    445                 if ($relation['type'] === Doctrine_Relation::ONE ||  
     445                if ($relation['type'] === Doctrine_Relation::ONE || 
    446446                    $relation['type'] === Doctrine_Relation::ONE_COMPOSITE) { 
    447447                    $ret[$i] = "    ".'$this->hasOne(\'' . $class . $alias . '\''; 
     
    449449                    $ret[$i] = "    ".'$this->hasMany(\'' . $class . $alias . '\''; 
    450450                } 
    451              
     451 
    452452                $a = array(); 
    453453 
     
    455455                    $a[] = '\'refClass\' => ' . $this->varExport($relation['refClass']); 
    456456                } 
    457              
     457 
    458458                if (isset($relation['deferred']) && $relation['deferred']) { 
    459459                    $a[] = '\'default\' => ' . $this->varExport($relation['deferred']); 
    460460                } 
    461              
     461 
    462462                if (isset($relation['local']) && $relation['local']) { 
    463463                    $a[] = '\'local\' => ' . $this->varExport($relation['local']); 
    464464                } 
    465              
     465 
    466466                if (isset($relation['foreign']) && $relation['foreign']) { 
    467467                    $a[] = '\'foreign\' => ' . $this->varExport($relation['foreign']); 
    468468                } 
    469              
     469 
    470470                if (isset($relation['onDelete']) && $relation['onDelete']) { 
    471471                    $a[] = '\'onDelete\' => ' . $this->varExport($relation['onDelete']); 
    472472                } 
    473              
     473 
    474474                if (isset($relation['onUpdate']) && $relation['onUpdate']) { 
    475475                    $a[] = '\'onUpdate\' => ' . $this->varExport($relation['onUpdate']); 
    476476                } 
    477              
    478                 if (isset($relation['equal']) && $relation['equal']) {  
    479                     $a[] = '\'equal\' => ' . $this->varExport($relation['equal']);  
    480                 } 
    481              
     477 
     478                if (isset($relation['equal']) && $relation['equal']) { 
     479                    $a[] = '\'equal\' => ' . $this->varExport($relation['equal']); 
     480                } 
     481 
    482482                if ( ! empty($a)) { 
    483483                    $ret[$i] .= ', ' . 'array('; 
     
    485485                    $ret[$i] .= implode(',' . PHP_EOL . str_repeat(' ', $length), $a) . ')'; 
    486486                } 
    487              
     487 
    488488                $ret[$i] .= ');'.PHP_EOL; 
    489489                $i++; 
     
    503503        $code = implode(PHP_EOL, $ret); 
    504504        $code = trim($code); 
    505          
     505 
    506506        return PHP_EOL . '  public function setUp()' . PHP_EOL . '  {' . PHP_EOL . '    ' . $code . PHP_EOL . '  }'; 
    507507    } 
     
    510510     * buildColumns 
    511511     * 
    512      * @param string $array  
     512     * @param string $array 
    513513     * @return void 
    514514     */ 
     
    519519            $columnName = isset($column['name']) ? $column['name']:$name; 
    520520            $build .= "    ".'$this->hasColumn(\'' . $columnName . '\', \'' . $column['type'] . '\''; 
    521      
     521 
    522522            if ($column['length']) { 
    523523                $build .= ', ' . $column['length']; 
     
    541541                $build .= ', ' . $this->varExport($options); 
    542542            } 
    543      
     543 
    544544            $build .= ');' . PHP_EOL; 
    545545        } 
    546          
     546 
    547547        return $build; 
    548548    } 
     
    555555     * So we do some string replacing to clean it up 
    556556     * 
    557      * @param string $var  
     557     * @param string $var 
    558558     * @return void 
    559559     */ 
     
    581581            $accessors[] = $name; 
    582582        } 
    583          
     583 
    584584        foreach ($definition['relations'] as $relation) { 
    585585            $accessors[] = $relation['alias']; 
    586586        } 
    587          
     587 
    588588        $ret = ''; 
    589589        foreach ($accessors as $name) { 
     
    596596            // setters 
    597597            $ret .= PHP_EOL . '  public function set' . Doctrine_Inflector::classify(Doctrine_Inflector::tableize($name)) . "(\${$name}, \$load = true)" . PHP_EOL; 
    598                 $ret .= "  {" . PHP_EOL; 
     598            $ret .= "  {" . PHP_EOL; 
    599599            $ret .= "    return \$this->set('{$name}', \${$name}, \$load);" . PHP_EOL; 
    600600            $ret .= "  }" . PHP_EOL; 
     
    607607     * buildTemplates 
    608608     * 
    609      * @param string $array  
     609     * @param string $array 
    610610     * @return void 
    611611     */ 
     
    614614        $build = ''; 
    615615        foreach ($templates as $name => $options) { 
    616              
     616 
    617617            if (is_array($options) && !empty($options)) { 
    618618                $optionsPhp = $this->varExport($options); 
    619              
     619 
    620620                $build .= "    \$this->loadTemplate('" . $name . "', " . $optionsPhp . ");" . PHP_EOL; 
    621621            } else { 
     
    627627            } 
    628628        } 
    629          
     629 
    630630        return $build; 
    631631    } 
     
    634634     * buildActAs 
    635635     * 
    636      * @param string $array  
     636     * @param string $array 
    637637     * @return void 
    638638     */ 
     
    643643            if (is_array($options) && !empty($options)) { 
    644644                $optionsPhp = $this->varExport($options); 
    645                  
     645 
    646646                $build .= "    \$this->actAs('" . $name . "', " . $optionsPhp . ");" . PHP_EOL; 
    647647            } else { 
     
    653653            } 
    654654        } 
    655          
     655 
    656656        return $build; 
    657657    } 
     
    660660     * buildAttributes 
    661661     * 
    662      * @param string $array  
     662     * @param string $array 
    663663     * @return void 
    664664     */ 
     
    667667        $build = PHP_EOL; 
    668668        foreach ($attributes as $key => $value) { 
    669            
     669 
    670670            if (is_bool($value)) 
    671671            { 
     
    675675                    $value = array($value); 
    676676                } 
    677              
     677 
    678678                $values = ''; 
    679679                foreach ($value as $attr) { 
    680680                    $values .= "Doctrine::" . strtoupper($key) . "_" . strtoupper($attr) . ' ^ '; 
    681681                } 
    682                  
     682 
    683683                // Trim last ^ 
    684684                $values = substr($values, 0, strlen($values) - 3); 
    685685            } 
    686              
     686 
    687687            $build .= "    \$this->setAttribute(Doctrine::ATTR_" . strtoupper($key) . ", " . $values . ");" . PHP_EOL; 
    688688        } 
    689          
     689 
    690690        return $build; 
    691691    } 
    692      
     692 
    693693    /** 
    694694     * buildTableOptions 
    695695     * 
    696      * @param string $array  
     696     * @param string $array 
    697697     * @return void 
    698698     */ 
     
    703703            $build .= "    \$this->option('$name', " . $this->varExport($value) . ");" . PHP_EOL; 
    704704        } 
    705          
     705 
    706706        return $build; 
    707707    } 
     
    710710     * buildIndexes 
    711711     * 
    712      * @param string $array  
     712     * @param string $array 
    713713     * @return void 
    714714     */ 
     
    755755 
    756756        $accessorsCode = (isset($definition['generate_accessors']) && $definition['generate_accessors'] === true) ? $this->buildAccessors($definition):null; 
    757          
     757 
    758758        $content = sprintf(self::$_tpl, $abstract, 
    759759                                       $className, 
     
    762762                                       $setUpCode, 
    763763                                       $accessorsCode); 
    764          
     764 
    765765        return $content; 
    766766    } 
     
    769769     * buildRecord 
    770770     * 
    771      * @param array $options  
    772      * @param array $columns  
    773      * @param array $relations  
    774      * @param array $indexes  
    775      * @param array $attributes  
    776      * @param array $templates  
    777      * @param array $actAs  
     771     * @param array $options 
     772     * @param array $columns 
     773     * @param array $relations 
     774     * @param array $indexes 
     775     * @param array $attributes 
     776     * @param array $templates 
     777     * @param array $actAs 
    778778     * @return void= 
    779779     */ 
     
    783783            throw new Doctrine_Import_Builder_Exception('Missing class name.'); 
    784784        } 
    785          
     785 
    786786        $definition['topLevelClassName'] = $definition['className']; 
    787          
     787 
    788788        if ($this->generateBaseClasses()) { 
    789789            $definition['is_package'] = (isset($definition['package']) && $definition['package']) ? true:false; 
    790              
     790 
    791791            if ($definition['is_package']) { 
    792792                $e = explode('.', trim($definition['package'])); 
    793793                $definition['package_name'] = $e[0]; 
    794                  
     794 
    795795                $definition['package_path'] = ! empty($e) ? implode(DIRECTORY_SEPARATOR, $e):$definition['package_name']; 
    796796            } 
     
    798798            $topLevel = $definition; 
    799799            unset($topLevel['tableName']); 
    800              
     800 
    801801            // If we have a package then we need to make this extend the package definition and not the base definition 
    802802            // The package definition will then extends the base definition 
     
    809809            // Package level definition that extends from the base definition 
    810810            if (isset($definition['package'])) { 
    811                  
     811 
    812812                $packageLevel = $definition; 
    813813                $packageLevel['className'] = $topLevel['inheritance']['extends']; 
     
    819819                $packageLevel['is_package_class'] = true; 
    820820                unset($packageLevel['connection']); 
    821                  
     821 
    822822                $packageLevel['tableClassName'] = $packageLevel['className'] . 'Table'; 
    823823                $packageLevel['inheritance']['tableExtends'] = isset($definition['inheritance']['extends']) ? $definition['inheritance']['extends'] . 'Table':'Doctrine_Table'; 
    824                  
     824 
    825825                $topLevel['tableClassName'] = $topLevel['topLevelClassName'] . 'Table'; 
    826826                $topLevel['inheritance']['tableExtends'] = $packageLevel['className'] . 'Table'; 
     
    837837 
    838838            $this->writeDefinition($baseClass); 
    839              
     839 
    840840            if ( ! empty($packageLevel)) { 
    841841                $this->writeDefinition($packageLevel); 
    842842            } 
    843              
     843 
    844844            $this->writeDefinition($topLevel); 
    845845        } else { 
     
    878878     * writeDefinition 
    879879     * 
    880      * @param array $options  
    881      * @param array $columns  
    882      * @param array $relations  
    883      * @param array $indexes  
    884      * @param array $attributes  
    885      * @param array $templates  
    886      * @param array $actAs  
     880     * @param array $options 
     881     * @param array $columns 
     882     * @param array $relations 
     883     * @param array $indexes 
     884     * @param array $attributes 
     885     * @param array $templates 
     886     * @param array $actAs 
    887887     * @return void 
    888888     */