Changeset 4332

Show
Ignore:
Timestamp:
05/02/08 14:29:33 (14 months ago)
Author:
jwage
Message:

Consolidated Doctrine_Manager::getInstance()->getTable() and Doctrine_Manager::table() methods in to one method. Doctrine::getTable() for 1.0 is the authoritative method.

Location:
branches/0.11
Files:
7 modified

Legend:

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

    r4317 r4332  
    951951     * Get the Doctrine_Table object for the passed model 
    952952     * 
    953      * @param string $tableName 
    954      * @return void 
    955      */ 
    956     public static function getTable($tableName) 
    957     { 
    958         return Doctrine_Manager::table($tableName); 
     953     * @param string $componentName 
     954     * @return void 
     955     */ 
     956    public static function getTable($componentName) 
     957    { 
     958        return Doctrine_Manager::getInstance()->getConnectionForComponent($componentName)->getTable($componentName); 
    959959    } 
    960960 
  • branches/0.11/lib/Doctrine/Data/Import.php

    r4301 r4332  
    300300    protected function _loadNestedSetData($model, $nestedSetData, $parent = null) 
    301301    { 
    302         $manager = Doctrine_Manager::getInstance(); 
    303  
    304302        foreach($nestedSetData AS $rowKey => $nestedSet) { 
    305303            $children = array(); 
     
    315313 
    316314            if( ! $parent) { 
    317                 $manager->getTable($model)->getTree()->createRoot($record); 
     315                Doctrine::getTable($model)->getTree()->createRoot($record); 
    318316            } else { 
    319317                $parent->getNode()->addChild($record); 
  • branches/0.11/lib/Doctrine/Hydrator/RecordDriver.php

    r4087 r4332  
    106106        $component = $this->_getClassNameToReturn($data, $component); 
    107107        if ( ! isset($this->_tables[$component])) { 
    108             $this->_tables[$component] = Doctrine_Manager::getInstance()->getTable($component); 
     108            $this->_tables[$component] = Doctrine::getTable($component); 
    109109            $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false); 
    110110        } 
     
    144144    { 
    145145        if ( ! isset($this->_tables[$component])) { 
    146             $this->_tables[$component] = Doctrine_Manager::getInstance()->getTable($component); 
     146            $this->_tables[$component] = Doctrine::getTable($component); 
    147147            $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false); 
    148148        } 
     
    153153         
    154154        foreach ($subclasses as $subclass) { 
    155             $table = Doctrine_Manager::getInstance()->getTable($subclass); 
     155            $table = Doctrine::getTable($subclass); 
    156156            $inheritanceMap = $table->getOption('inheritanceMap'); 
    157157            list($key, $value) = each($inheritanceMap); 
  • branches/0.11/lib/Doctrine/Manager.php

    r4331 r4332  
    5656 
    5757    /** 
    58      * @var string $root                root directory 
    59      */ 
    60     protected $_root; 
    61  
    62     /** 
    6358     * @var Doctrine_Query_Registry     the query registry 
    6459     */ 
     
    7267    private function __construct() 
    7368    { 
    74         $this->_root = dirname(__FILE__); 
    75  
    7669        Doctrine_Locator_Injectable::initNullObject(new Doctrine_Null); 
    7770    } 
     
    122115 
    123116    /** 
    124      * returns the root directory of Doctrine 
    125      * 
    126      * @return string 
    127      */ 
    128     final public function getRoot() 
    129     { 
    130         return $this->_root; 
    131     } 
    132  
    133     /** 
    134      * getInstance 
    135      * returns an instance of this class 
     117     * Returns an instance of this class 
    136118     * (this class uses the singleton pattern) 
    137119     * 
     
    148130 
    149131    /** 
    150      * getQueryRegistry 
    151      * 
    152      * lazy-initializes the query registry object and returns it 
     132     * Lazy-initializes the query registry object and returns it 
    153133     * 
    154134     * @return Doctrine_Query_Registry 
     
    163143 
    164144    /** 
    165      * setQueryRegistry 
    166      * sets the query registry 
     145     * Sets the query registry 
    167146     * 
    168147     * @return Doctrine_Manager     this object 
     
    176155 
    177156    /** 
    178      * fetch 
    179      * fetches data using the provided queryKey and  
    180      * the associated query in the query registry 
    181      * 
    182      * if no query for given queryKey is being found a  
    183      * Doctrine_Query_Registry exception is being thrown 
    184      * 
    185      * @param string $queryKey      the query key 
    186      * @param array $params         prepared statement params (if any) 
    187      * @return mixed                the fetched data 
    188      */ 
    189     public function find($queryKey, $params = array(), $hydrationMode = Doctrine::HYDRATE_RECORD) 
    190     { 
    191         return Doctrine_Manager::getInstance() 
    192                             ->getQueryRegistry() 
    193                             ->get($queryKey) 
    194                             ->execute($params, $hydrationMode); 
    195     } 
    196  
    197     /** 
    198      * fetchOne 
    199      * fetches data using the provided queryKey and  
    200      * the associated query in the query registry 
    201      * 
    202      * if no query for given queryKey is being found a  
    203      * Doctrine_Query_Registry exception is being thrown 
    204      * 
    205      * @param string $queryKey      the query key 
    206      * @param array $params         prepared statement params (if any) 
    207      * @return mixed                the fetched data 
    208      */ 
    209     public function findOne($queryKey, $params = array(), $hydrationMode = Doctrine::HYDRATE_RECORD) 
    210     { 
    211         return Doctrine_Manager::getInstance() 
    212                             ->getQueryRegistry() 
    213                             ->get($queryKey) 
    214                             ->fetchOne($params, $hydrationMode); 
    215     } 
    216  
    217     /** 
    218      * connection 
    219      * 
    220      * if the adapter parameter is set this method acts as 
     157     * Open a new connection. If the adapter parameter is set this method acts as 
    221158     * a short cut for Doctrine_Manager::getInstance()->openConnection($adapter, $name); 
    222159     * 
     
    239176 
    240177    /** 
    241      * openConnection 
    242      * opens a new connection and saves it to Doctrine_Manager->connections 
     178     * Opens a new connection and saves it to Doctrine_Manager->connections 
    243179     * 
    244180     * @param PDO|Doctrine_Adapter_Interface $adapter   database driver 
     
    331267     
    332268    /** 
    333      * parsePdoDsn 
     269     * Parse a pdo style dsn in to an array of parts 
    334270     * 
    335271     * @param array $dsn An array of dsn information 
     
    369305 
    370306    /** 
    371      * buildDsnPartsArray 
    372      * 
     307     * Build the blank dsn parts array used with parseDsn() 
     308     * 
     309     * @see parseDsn() 
    373310     * @param string $dsn  
    374311     * @return array $parts 
    375312     */ 
    376     public function buildDsnPartsArray($dsn) 
     313    protected function _buildDsnPartsArray($dsn) 
    377314    { 
    378315        // fix sqlite dsn so that it will parse correctly 
     
    400337 
    401338    /** 
    402      * parseDsn 
     339     * Parse a Doctrine style dsn string in to an array of parts 
    403340     * 
    404341     * @param string $dsn 
     
    408345    public function parseDsn($dsn) 
    409346    { 
    410         $parts = $this->buildDsnPartsArray($dsn); 
     347        $parts = $this->_buildDsnPartsArray($dsn); 
    411348 
    412349        switch ($parts['scheme']) { 
     
    479416 
    480417    /** 
    481      * getConnection 
     418     * Get the connection instance for the passed name 
     419     * 
    482420     * @param integer $index 
    483421     * @return object Doctrine_Connection 
     
    494432 
    495433    /** 
    496      * getConnectionName 
     434     * Get the name of the passed connection instance 
    497435     * 
    498436     * @param Doctrine_Connection $conn     connection object to be searched for 
     
    505443 
    506444    /** 
    507      * bindComponent 
    508      * binds given component to given connection 
     445     * Binds given component to given connection 
    509446     * this means that when ever the given component uses a connection 
    510447     * it will be using the bound connection instead of the current connection 
     
    520457 
    521458    /** 
    522      * getConnectionForComponent 
     459     * Get the connection instance for the specified component 
    523460     * 
    524461     * @param string $componentName 
     
    537474     
    538475    /** 
    539      * hasConnectionForComponent 
     476     * Check if a component is bound to a connection 
    540477     * 
    541478     * @param string $componentName 
     
    548485 
    549486    /** 
    550      * getTable 
    551      * this is the same as Doctrine_Connection::getTable() except 
    552      * that it works seamlessly in multi-server/connection environment 
    553      * 
    554      * @see Doctrine_Connection::getTable() 
    555      * @param string $componentName 
    556      * @return Doctrine_Table 
    557      */ 
    558     public function getTable($componentName) 
    559     { 
    560         return $this->getConnectionForComponent($componentName)->getTable($componentName); 
    561     } 
    562  
    563     /** 
    564      * table 
    565      * this is the same as Doctrine_Connection::getTable() except 
    566      * that it works seamlessly in multi-server/connection environment 
    567      * 
    568      * @see Doctrine_Connection::getTable() 
    569      * @param string $componentName 
    570      * @return Doctrine_Table 
    571      */ 
    572     public static function table($componentName) 
    573     { 
    574         $manager = Doctrine_Manager::getInstance(); 
    575         return $manager->getConnectionForComponent($componentName)->getTable($componentName); 
    576     } 
    577  
    578     /** 
    579      * closes the connection 
     487     * Closes the specified connection 
    580488     * 
    581489     * @param Doctrine_Connection $connection 
     
    597505 
    598506    /** 
    599      * getConnections 
    600      * returns all opened connections 
     507     * Returns all opened connections 
    601508     * 
    602509     * @return array 
     
    608515 
    609516    /** 
    610      * setCurrentConnection 
    611      * sets the current connection to $key 
     517     * Sets the current connection to $key 
    612518     * 
    613519     * @param mixed $key                        the connection key 
     
    625531 
    626532    /** 
    627      * contains 
    628      * whether or not the manager contains specified connection 
     533     * Whether or not the manager contains specified connection 
    629534     * 
    630535     * @param mixed $key                        the connection key 
     
    637542 
    638543    /** 
    639      * count 
    640      * returns the number of opened connections 
     544     * Returns the number of opened connections 
    641545     * 
    642546     * @return integer 
     
    648552 
    649553    /** 
    650      * getIterator 
    651      * returns an ArrayIterator that iterates through all connections 
     554     * Returns an ArrayIterator that iterates through all connections 
    652555     * 
    653556     * @return ArrayIterator 
     
    659562 
    660563    /** 
    661      * getCurrentConnection 
    662      * returns the current connection 
     564     * Get the current connection instance 
    663565     * 
    664566     * @throws Doctrine_Connection_Exception       if there are no open connections 
     
    675577 
    676578    /** 
    677      * createDatabases 
    678      * 
    679      * Creates databases for connections 
     579     * Creates databases for all existing connections 
    680580     * 
    681581     * @param string $specifiedConnections Array of connections you wish to create the database for 
     
    703603 
    704604    /** 
    705      * dropDatabases 
    706      * 
    707      * Drops databases for connections 
     605     * Drops databases for all existing connections 
    708606     * 
    709607     * @param string $specifiedConnections Array of connections you wish to drop the database for 
     
    731629 
    732630    /** 
    733      * __toString 
    734      * returns a string representation of this object 
     631     * Returns a string representation of this object 
    735632     * 
    736633     * @return string 
  • branches/0.11/lib/Doctrine/Record.php

    r4320 r4332  
    157157            // get the table of this class 
    158158            $class = get_class($this); 
    159             $this->_table = Doctrine_Manager::getInstance()->getTable($class); 
     159            $this->_table = Doctrine::getTable($class); 
    160160            $exists = false; 
    161161        } 
  • branches/0.11/lib/Doctrine/Search/Query.php

    r3884 r4332  
    5555    { 
    5656        if (is_string($table)) { 
    57            $table = Doctrine_Manager::table($table); 
     57           $table = Doctrine::getTable($table); 
    5858        } else { 
    5959            if ( ! $table instanceof Doctrine_Table) { 
  • branches/0.11/tests/Ticket/736TestCase.php

    r3884 r4332  
    3434    public function testForHydrationOverwrintingLocalInstancesWhenItShouldnt() 
    3535    { 
    36         $module = Doctrine_Manager::getInstance()->getTable("T736_Module")->find(1); 
     36        $module = Doctrine::getTable("T736_Module")->find(1); 
    3737        $module->moduledata->content = "foo"; 
    3838        $module->moduledata->save(); 
     
    8585    { 
    8686        $contents = $event->data; 
    87         $delegate = Doctrine_Manager::getInstance()->getTable("T736_ModuleDelegate")->find($contents["moduledelegateid"], ($contents instanceof Doctrine_Record) ? Doctrine::HYDRATE_RECORD :Doctrine::HYDRATE_ARRAY ); 
     87        $delegate = Doctrine::getTable("T736_ModuleDelegate")->find($contents["moduledelegateid"], ($contents instanceof Doctrine_Record) ? Doctrine::HYDRATE_RECORD :Doctrine::HYDRATE_ARRAY ); 
    8888        if ($contents instanceof Doctrine_Record) 
    8989        {