Changeset 3965

Show
Ignore:
Timestamp:
03/10/08 20:08:13 (16 months ago)
Author:
jwage
Message:

Fixed issue with options not existing in Schema.php. A few minor other changes.

Location:
branches/0.10/lib/Doctrine/Import
Files:
2 modified

Legend:

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

    r3961 r3965  
    6161     */ 
    6262    protected $_packagesPath = ''; 
    63      
     63 
     64    /** 
     65     * _packagesFolderName 
     66     * 
     67     * @var string 
     68     */ 
     69    protected $_packagesFolderName = 'packages'; 
     70 
    6471    /** 
    6572     * _suffix 
     
    104111     */ 
    105112    protected $_baseClassName = 'Doctrine_Record'; 
    106      
     113 
    107114    /** 
    108115     * _tpl 
     
    134141        if ($path) { 
    135142            if ( ! $this->_packagesPath) { 
    136                 $this->setPackagesPath($path . DIRECTORY_SEPARATOR . 'packages'); 
     143                $this->setPackagesPath($path . DIRECTORY_SEPARATOR . $this->_packagesFolderName); 
    137144            } 
    138145 
     
    252259    public function setOptions($options) 
    253260    { 
    254         if (!empty($options)) { 
     261        if ( ! empty($options)) { 
    255262            foreach ($options as $key => $value) { 
    256263                $this->setOption($key, $value); 
  • branches/0.10/lib/Doctrine/Import/Schema.php

    r3961 r3965  
    2121 
    2222/** 
    23  * class Doctrine_Import_Schema 
     23 * Doctrine_Import_Schema 
    2424 * 
    25  * Different methods to import a XML schema. The logic behind using two different 
    26  * methods is simple. Some people will like the idea of producing Doctrine_Record 
    27  * objects directly, which is totally fine. But in fast and growing application, 
    28  * table definitions tend to be a little bit more volatile. importArr() can be used 
    29  * to output a table definition in a PHP file. This file can then be stored 
    30  * independantly from the object itself. 
     25 * Class for importing Doctrine_Record classes from a yaml schema definition 
    3126 * 
    3227 * @package     Doctrine 
     
    4338    protected $_options = array('packagesPrefix'        =>  'Package', 
    4439                                'packagesPath'          =>  '', 
     40                                'packagesFolderName'    =>  'packages', 
     41                                'suffix'                =>  '.php', 
    4542                                'generateBaseClasses'   =>  true, 
     43                                'baseClassesPrefix'     =>  'Base', 
    4644                                'baseClassesDirectory'  =>  'generated', 
    47                                 'baseClassName'         =>  'Doctrine_Record', 
    48                                 'suffix'                =>  '.php'); 
     45                                'baseClassName'         =>  'Doctrine_Record'); 
    4946     
    5047    /** 
     
    9390    public function setOptions($options) 
    9491    { 
    95         if (!empty($options)) { 
     92        if ( ! empty($options)) { 
    9693          $this->_options = $options; 
    9794        } 
     
    10198     * buildSchema 
    10299     * 
    103      * Loop throug directories of schema files and part them all in to one complete array of schema information 
     100     * Loop throug directories of schema files and parse them all in to one complete array of schema information 
    104101     * 
    105102     * @param  string   $schema Array of schema files or single schema file. Array of directories with schema files or single directory 
     
    141138     * 
    142139     * @param  string $schema       The file containing the XML schema 
     140     * @param  string $format       Format of the schema file 
    143141     * @param  string $directory    The directory where the Doctrine_Record class will be written 
    144      * @param  array $models        Optional array of models to import 
     142     * @param  array  $models       Optional array of models to import 
    145143     * 
    146144     * @return void 
     
    170168     * 
    171169     * @param  string $schema   Path to the file containing the schema 
     170     * @param  string $type     Format type of the schema we are parsing 
    172171     * @return array  $build    Built array of schema information 
    173172     */ 
     
    312311     *  
    313312     * Perform some processing on inheritance. 
     313     * Sets the default type and sets some default values for certain types 
    314314     * 
    315315     * @param string $array  
     
    348348 
    349349        // Array of the array keys to move to the parent, and the value to default the child definition to 
    350         // after moving it 
     350        // after moving it. Will also populate the subclasses array for the inheritance parent 
    351351        $moves = array('columns' => array(), 'relations' => array()); 
    352352         
     
    362362                } 
    363363 
     364                // Populate the parents subclasses 
    364365                if ($definition['inheritance']['type'] == 'column_aggregation') { 
    365366                    $array[$extends]['inheritance']['subclasses'][$definition['className']] = array($definition['inheritance']['keyField'] => $definition['inheritance']['keyValue']); 
     
    375376     * 
    376377     * Loop through an array of schema information and build all the necessary relationship information 
    377      * Will attempt to auto complete relationships and simplify the amount of information required for defining a relationship 
     378     * Will attempt to auto complete relationships and simplify the amount of information required  
     379     * for defining a relationship 
    378380     * 
    379381     * @param  string $array  
     
    387389            if (isset($properties['columns']) && ! empty($properties['columns']) && isset($properties['detect_relations']) && $properties['detect_relations']) { 
    388390                foreach ($properties['columns'] as $column) { 
     391                    // Check if the column we are inflecting has a _id on the end of it before trying to inflect it and find 
     392                    // the class name for the column 
    389393                    if (strpos($column['name'], '_id')) { 
    390394                        $columnClassName = Doctrine_Inflector::classify(str_replace('_id', '', $column['name'])); 
     
    445449        // Make sure we do not have any duplicate relations 
    446450        $this->_fixDuplicateRelations(); 
    447          
     451 
     452        // Set the full array of relationships for each class to the final array 
    448453        foreach ($this->_relations as $className => $relations) { 
    449454            $array[$className]['relations'] = $relations; 
     
    485490                    } 
    486491                } 
    487                  
     492 
     493                // Make sure it doesn't already exist 
    488494                if ( ! isset($this->_relations[$relation['class']][$newRelation['alias']])) { 
    489495                    $newRelation['key'] = $this->_buildUniqueRelationKey($newRelation); 
     
    506512                } else { 
    507513                    // check to see if this relationship is not autogenerated, if it's not, then the user must have explicitly declared it 
    508                     if (!isset($relation['autogenerated']) || $relation['autogenerated'] != true) { 
     514                    if ( ! isset($relation['autogenerated']) || $relation['autogenerated'] != true) { 
    509515                        $uniqueRelations = array_merge($uniqueRelations, array($relation['alias'] => $relation)); 
    510516                    } 
     
    519525     * _buildUniqueRelationKey 
    520526     * 
     527     * Build a unique key to identify a relationship by 
     528     * Md5 hash of all the relationship parameters 
     529     * 
    521530     * @param string $relation  
    522531     * @return void 
     
    524533    protected function _buildUniqueRelationKey($relation) 
    525534    { 
    526       return md5($relation['local'].$relation['foreign'].$relation['class'].(isset($relation['refClass']) ? $relation['refClass']:null)); 
     535        return md5($relation['local'].$relation['foreign'].$relation['class'].(isset($relation['refClass']) ? $relation['refClass']:null)); 
    527536    } 
    528537}