Changeset 4456 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
05/30/08 13:09:24 (7 months ago)
Author:
romanb
Message:

some minor refactorings. started to make a draft of the new namespaced folder structure.

Location:
trunk/lib/Doctrine
Files:
32 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine/Access.php

    r4055 r4456  
    2020 */ 
    2121 
     22#namespace Doctrine::ORM; 
     23 
    2224/** 
    2325 * Doctrine_Access 
  • trunk/lib/Doctrine/Cache.php

    r3882 r4456  
    1919 * <http://www.phpdoctrine.org>. 
    2020 */ 
    21 Doctrine::autoload('Doctrine_EventListener'); 
     21 
    2222/** 
    2323 * Doctrine_Cache 
  • trunk/lib/Doctrine/ClassMetadata.php

    r4436 r4456  
    2020 */ 
    2121 
     22#namespace Doctrine::ORM::Mapping; 
     23 
    2224/** 
    2325 * A <tt>ClassMetadata</tt> instance holds all the information (metadata) of an entity and 
     
    2931 * @since 2.0 
    3032 */ 
    31 class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializable 
     33class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable 
    3234{ 
    3335    /** 
     
    19711973    } 
    19721974 
    1973     public function hasAttribute($key) 
    1974     { 
    1975         switch ($key) { 
    1976             case Doctrine::ATTR_SEQCOL_NAME: 
    1977             case Doctrine::ATTR_COLL_KEY: 
    1978             case Doctrine::ATTR_LOAD_REFERENCES: 
    1979             case Doctrine::ATTR_EXPORT: 
    1980             case Doctrine::ATTR_QUERY_LIMIT: 
    1981             case Doctrine::ATTR_VALIDATE: 
    1982                 return true; 
    1983             default: 
    1984                 return false; 
    1985         } 
     1975    public function hasAttribute($name) 
     1976    { 
     1977        return false; 
     1978    } 
     1979     
     1980    public function getAttribute($name) 
     1981    { 
     1982        return null; 
     1983    } 
     1984     
     1985    public function setAttribute($name, $value) 
     1986    { 
     1987        ; 
    19861988    } 
    19871989 
  • trunk/lib/Doctrine/Collection.php

    r4374 r4456  
    2020 */ 
    2121 
     22#namespace Doctrine::ORM; 
     23 
    2224/** 
    2325 * A persistent collection of entities. 
  • trunk/lib/Doctrine/Configurable.php

    r4055 r4456  
    1 <?php 
     1<?php  
    22/* 
    33 *  $Id$ 
     
    2020 */ 
    2121 
     22#namespace Doctrine::Core; 
     23 
    2224/** 
    2325 * Doctrine_Configurable 
    2426 * 
    25  * 
    26  * @package     Doctrine 
    27  * @subpackage  Configurable 
    2827 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL 
    2928 * @link        www.phpdoctrine.org 
    30  * @since       1.0 
     29 * @since       2.0 
    3130 * @version     $Revision$ 
    3231 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi> 
     32 * @author      Roman Borschel <roman@code-factory.org> 
    3333 */ 
    34 abstract class Doctrine_Configurable 
     34interface Doctrine_Configurable 
    3535{ 
    36     /** 
    37      * @var array $attributes               an array of containing all attributes 
    38      */ 
    39     protected $_attributes = array(); 
    40  
    41     /** 
    42      * @var Doctrine_Configurable $parent   the parent of this component 
    43      */ 
    44     protected $parent; 
    45  
    46     /** 
    47      * @var array $_impl                    an array containing concrete implementations for class templates 
    48      *                                      keys as template names and values as names of the concrete 
    49      *                                      implementation classes 
    50      */ 
    51     //protected $_impl = array(); 
    52  
    53     /** 
    54      * @var array $_params                  an array of user defined parameters 
    55      */ 
    56     //protected $_params = array(); 
    57  
    58     /** 
    59      * setAttribute 
    60      * sets a given attribute 
    61      * 
    62      * <code> 
    63      * $manager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL); 
    64      * 
    65      * // or 
    66      * 
    67      * $manager->setAttribute('portability', Doctrine::PORTABILITY_ALL); 
    68      * 
    69      * // or 
    70      * 
    71      * $manager->setAttribute('portability', 'all'); 
    72      * </code> 
    73      * 
    74      * @param mixed $attribute              either a Doctrine::ATTR_* integer constant or a string 
    75      *                                      corresponding to a constant 
    76      * @param mixed $value                  the value of the attribute 
    77      * @see Doctrine::ATTR_* constants 
    78      * @throws Doctrine_Exception           if the value is invalid 
    79      * @return void 
    80      */ 
    81     public function setAttribute($attribute, $value) 
    82     { 
    83         if (is_string($attribute)) { 
    84             $upper = strtoupper($attribute); 
    85  
    86             $const = 'Doctrine::ATTR_' . $upper; 
    87  
    88             if (defined($const)) { 
    89                 $attribute = constant($const); 
    90             } else { 
    91                 throw new Doctrine_Exception('Unknown attribute: "' . $attribute . '"'); 
    92             } 
    93         } 
    94  
    95         if (is_string($value) && isset($upper)) { 
    96             $const = 'Doctrine::' . $upper . '_' . strtoupper($value); 
    97  
    98             if (defined($const)) { 
    99                 $value = constant($const); 
    100             } else { 
    101                 throw new Doctrine_Exception('Unknown attribute value: "' . $value . '"'); 
    102             } 
    103         } 
    104  
    105         switch ($attribute) { 
    106             case Doctrine::ATTR_FETCHMODE: // deprecated 
    107                 throw new Doctrine_Exception('Deprecated attribute. See http://www.phpdoctrine.org/documentation/manual?chapter=configuration'); 
    108             case Doctrine::ATTR_LISTENER: 
    109                 $this->setEventListener($value); 
    110                 break; 
    111             case Doctrine::ATTR_COLL_KEY: // class attribute 
    112                 if ( ! ($this instanceof Doctrine_ClassMetadata)) { 
    113                     throw new Doctrine_Exception("This attribute can only be set at class level."); 
    114                 } 
    115                 if ($value !== null && ! $this->hasField($value)) { 
    116                     throw new Doctrine_Exception("Couldn't set collection key attribute. No such field '$value'"); 
    117                 } 
    118                 break; 
    119             case Doctrine::ATTR_CACHE: // deprecated 
    120             case Doctrine::ATTR_RESULT_CACHE:// manager/session attribute 
    121             case Doctrine::ATTR_QUERY_CACHE: // manager/session attribute 
    122                 if ($value !== null) { 
    123                     if ( ! ($value instanceof Doctrine_Cache_Interface)) { 
    124                         throw new Doctrine_Exception('Cache driver should implement Doctrine_Cache_Interface'); 
    125                     } 
    126                 } 
    127                 break; 
    128             case Doctrine::ATTR_VALIDATE: // manager/session attribute 
    129             case Doctrine::ATTR_QUERY_LIMIT: // manager/session attribute 
    130             case Doctrine::ATTR_QUOTE_IDENTIFIER: // manager/session attribute 
    131             case Doctrine::ATTR_PORTABILITY: // manager/session attribute 
    132             case Doctrine::ATTR_DEFAULT_TABLE_TYPE: // manager/session attribute 
    133             case Doctrine::ATTR_EMULATE_DATABASE: // manager/session attribute 
    134             case Doctrine::ATTR_USE_NATIVE_ENUM: // manager/session attribute 
    135             case Doctrine::ATTR_DEFAULT_SEQUENCE: // ?? 
    136             case Doctrine::ATTR_EXPORT: // manager/session attribute 
    137             case Doctrine::ATTR_DECIMAL_PLACES: // manager/session attribute 
    138             case Doctrine::ATTR_LOAD_REFERENCES: // class attribute 
    139             case Doctrine::ATTR_RECORD_LISTENER: // not an attribute 
    140             case Doctrine::ATTR_THROW_EXCEPTIONS: // manager/session attribute 
    141             case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: 
    142             case Doctrine::ATTR_MODEL_LOADING: // manager/session attribute 
    143  
    144                 break; 
    145             case Doctrine::ATTR_SEQCOL_NAME: // class attribute 
    146                 if ( ! is_string($value)) { 
    147                     throw new Doctrine_Exception('Sequence column name attribute only accepts string values'); 
    148                 } 
    149                 break; 
    150             case Doctrine::ATTR_FIELD_CASE: // manager/session attribute 
    151                 if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER) 
    152                     throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.'); 
    153                 break; 
    154             case Doctrine::ATTR_SEQNAME_FORMAT: // manager/session attribute 
    155             case Doctrine::ATTR_IDXNAME_FORMAT: // manager/session attribute 
    156             case Doctrine::ATTR_TBLNAME_FORMAT: // manager/session attribute 
    157                 if ($this instanceof Doctrine_ClassMetadata) { 
    158                     throw new Doctrine_Exception('Sequence / index name format attributes cannot be set' 
    159                                                . ' at class level (only at connection or global level).'); 
    160                 } 
    161                 break; 
    162             default: 
    163                 throw new Doctrine_Exception("Unknown attribute."); 
    164         } 
    165  
    166         $this->_attributes[$attribute] = $value; 
    167  
    168     } 
    169  
    170     /*public function getParams($namespace = null) 
    171     { 
    172         if ($namespace == null) { 
    173             $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); 
    174         } 
    175  
    176         if ( ! isset($this->_params[$namespace])) { 
    177             return null; 
    178         } 
    179  
    180         return $this->_params[$namespace]; 
    181     }*/ 
    182  
    183     /*public function getParamNamespaces() 
    184     { 
    185         return array_keys($this->_params); 
    186     }*/ 
    187  
    188     /*public function setParam($name, $value, $namespace = null) 
    189     { 
    190         if ($namespace == null) { 
    191             $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); 
    192         } 
    193  
    194         $this->_params[$namespace][$name] = $value; 
    195  
    196         return $this; 
    197     }*/ 
    198  
    199     /*public function getParam($name, $value, $namespace) 
    200     { 
    201         if ($namespace == null) { 
    202             $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); 
    203         } 
    204  
    205         if ( ! isset($this->_params[$name])) { 
    206             if (isset($this->parent)) { 
    207                 return $this->parent->getParam($name); 
    208             } 
    209             return null; 
    210         } 
    211         return $this->_params[$name]; 
    212     }*/ 
    213  
    214     /** 
    215      * setImpl 
    216      * binds given class to given template name 
    217      * 
    218      * this method is the base of Doctrine dependency injection 
    219      * 
    220      * @param string $template      name of the class template 
    221      * @param string $class         name of the class to be bound 
    222      * @return Doctrine_Configurable    this object 
    223      */ 
    224     /*public function setImpl($template, $class) 
    225     { 
    226         $this->_impl[$template] = $class; 
    227  
    228         return $this; 
    229     }*/ 
    230  
    231     /** 
    232      * getImpl 
    233      * returns the implementation for given class 
    234      * 
    235      * @return string   name of the concrete implementation 
    236      */ 
    237     /*public function getImpl($template) 
    238     { 
    239         if ( ! isset($this->_impl[$template])) { 
    240             if (isset($this->parent)) { 
    241                 return $this->parent->getImpl($template); 
    242             } 
    243             return null; 
    244         } 
    245         return $this->_impl[$template]; 
    246     }*/ 
    247  
    248  
    249     /*public function hasImpl($template) 
    250     { 
    251         if ( ! isset($this->_impl[$template])) { 
    252             if (isset($this->parent)) { 
    253                 return $this->parent->hasImpl($template); 
    254             } 
    255             return false; 
    256         } 
    257         return true; 
    258     }*/ 
    259  
    260     /** 
    261      * @param Doctrine_EventListener $listener 
    262      * @return void 
    263      */ 
    264     public function setEventListener($listener) 
    265     { 
    266         return $this->setListener($listener); 
    267     } 
    268  
    269     /** 
    270      * addRecordListener 
    271      * 
    272      * @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener 
    273      * @return mixed        this object 
    274      */ 
    275     public function addRecordListener($listener, $name = null) 
    276     { 
    277         if ( ! isset($this->_attributes[Doctrine::ATTR_RECORD_LISTENER]) || 
    278              ! ($this->_attributes[Doctrine::ATTR_RECORD_LISTENER] instanceof Doctrine_Record_Listener_Chain)) { 
    279  
    280             $this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener_Chain(); 
    281         } 
    282         $this->_attributes[Doctrine::ATTR_RECORD_LISTENER]->add($listener, $name); 
    283  
    284         return $this; 
    285     } 
    286  
    287     /** 
    288      * getListener 
    289      * 
    290      * @return Doctrine_EventListener_Interface|Doctrine_Overloadable 
    291      */ 
    292     public function getRecordListener() 
    293     { 
    294         if ( ! isset($this->_attributes[Doctrine::ATTR_RECORD_LISTENER])) { 
    295             if (isset($this->parent)) { 
    296                 return $this->parent->getRecordListener(); 
    297             } 
    298             $this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener(); 
    299         } 
    300         return $this->_attributes[Doctrine::ATTR_RECORD_LISTENER]; 
    301     } 
    302  
    303     /** 
    304      * setListener 
    305      * 
    306      * @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener 
    307      * @return Doctrine_Configurable        this object 
    308      */ 
    309     public function setRecordListener($listener) 
    310     { 
    311         if ( ! ($listener instanceof Doctrine_Record_Listener_Interface) 
    312             && ! ($listener instanceof Doctrine_Overloadable) 
    313         ) { 
    314             throw new Doctrine_Exception("Couldn't set eventlistener. Record listeners should implement either Doctrine_Record_Listener_Interface or Doctrine_Overloadable"); 
    315         } 
    316         $this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = $listener; 
    317  
    318         return $this; 
    319     } 
    320      
    321     public function removeRecordListeners() 
    322     { 
    323         $this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = null; 
    324     } 
    325  
    326     /** 
    327      * addListener 
    328      * 
    329      * @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener 
    330      * @return mixed        this object 
    331      */ 
    332     public function addListener($listener, $name = null) 
    333     { 
    334         if ( ! isset($this->_attributes[Doctrine::ATTR_LISTENER]) || 
    335              ! ($this->_attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) { 
    336  
    337             $this->_attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain(); 
    338         } 
    339         $this->_attributes[Doctrine::ATTR_LISTENER]->add($listener, $name); 
    340  
    341         return $this; 
    342     } 
    343  
    344     /** 
    345      * getListener 
    346      * 
    347      * @return Doctrine_EventListener_Interface|Doctrine_Overloadable 
    348      */ 
    349     public function getListener() 
    350     { 
    351         if ( ! isset($this->_attributes[Doctrine::ATTR_LISTENER])) { 
    352             if (isset($this->parent)) { 
    353                 return $this->parent->getListener(); 
    354             } 
    355             return null; 
    356         } 
    357         return $this->_attributes[Doctrine::ATTR_LISTENER]; 
    358     } 
    359  
    360     /** 
    361      * setListener 
    362      * 
    363      * @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener 
    364      * @return Doctrine_Configurable        this object 
    365      */ 
    366     public function setListener($listener) 
    367     { 
    368         if ( ! ($listener instanceof Doctrine_EventListener_Interface) 
    369                 && ! ($listener instanceof Doctrine_Overloadable)) { 
    370             throw new Doctrine_EventListener_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable"); 
    371         } 
    372         $this->_attributes[Doctrine::ATTR_LISTENER] = $listener; 
    373  
    374         return $this; 
    375     } 
    376  
    377     /** 
    378      * returns the value of an attribute 
    379      * 
    380      * @param integer $attribute 
    381      * @return mixed 
    382      */ 
    383     public function getAttribute($attribute) 
    384     { 
    385         if (is_string($attribute)) { 
    386             $upper = strtoupper($attribute); 
    387  
    388             $const = 'Doctrine::ATTR_' . $upper;  
    389  
    390             if (defined($const)) { 
    391                 $attribute = constant($const); 
    392             } else { 
    393                 throw new Doctrine_Exception('Unknown attribute: "' . $attribute . '"'); 
    394             } 
    395         } 
    396  
    397         $attribute = (int) $attribute; 
    398  
    399         if ($attribute < 0) { 
    400             throw new Doctrine_Exception('Unknown attribute.'); 
    401         } 
    402  
    403         if (isset($this->_attributes[$attribute])) { 
    404             return $this->_attributes[$attribute]; 
    405         } 
    406  
    407         if (isset($this->parent)) { 
    408             return $this->parent->getAttribute($attribute); 
    409         } 
    410         return null; 
    411     } 
    412  
    413     /** 
    414      * getAttributes 
    415      * returns all attributes as an array 
    416      * 
    417      * @return array 
    418      */ 
    419     public function getAttributes() 
    420     { 
    421         return $this->_attributes; 
    422     } 
    423  
    424     /** 
    425      * Sets a parent for this configurable component 
    426      * the parent must be a configurable component itself. 
    427      * 
    428      * @param Doctrine_Configurable $component 
    429      * @return void 
    430      */ 
    431     public function setConfigurableParent(Doctrine_Configurable $component) 
    432     { 
    433         $this->parent = $component; 
    434     } 
    435  
    436     /** 
    437      * getParent 
    438      * Returns the parent of this component. 
    439      * 
    440      * @return Doctrine_Configurable 
    441      */ 
    442     public function getParent() 
    443     { 
    444         return $this->parent; 
    445     } 
     36    public function getAttribute($name); 
     37    public function setAttribute($name, $value); 
     38    public function hasAttribute($name);     
    44639} 
  • trunk/lib/Doctrine/Connection.php

    r4429 r4456  
    1919 * <http://www.phpdoctrine.org>. 
    2020 */ 
     21 
     22#namespace Doctrine::DBAL::Connections; 
    2123 
    2224/** 
     
    5961 *       Right now, this is the unification of these two classes. 
    6062 */ 
    61 abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable 
     63abstract class Doctrine_Connection implements Doctrine_Configurable, Countable 
    6264{ 
    6365    /** 
     
    6769     */ 
    6870    protected $dbh; 
     71     
     72    /** 
     73     * The attributes. 
     74     * 
     75     * @var array 
     76     */ 
     77    protected $_attributes = array(); 
    6978     
    7079    /** 
     
    145154     */ 
    146155    /** 
    147      * @var array $pendingAttributes            An array of pending attributes. When setting attributes 
    148      *                                          no connection is needed. When connected all the pending 
    149      *                                          attributes are passed to the underlying adapter (usually PDO) instance. 
    150      */ 
    151     protected $pendingAttributes  = array(); 
    152  
    153     /** 
    154156     * @var array $modules                      an array containing all modules 
    155157     *              transaction                 Doctrine_Transaction driver, handles savepoint and transaction isolation abstraction 
     
    185187                             'import'      => false, 
    186188                             'sequence'    => false, 
    187                              'unitOfWork'  => false, 
    188189                             'formatter'   => false, 
    189190                             'util'        => false, 
     
    192193 
    193194    /** 
    194      * the constructor 
     195     * Constructor. 
    195196     * 
    196197     * @param Doctrine_Manager $manager                 the manager object 
     
    222223     
    223224    /** 
    224      * getOption 
    225      * 
    226      * Retrieves option 
    227      * 
    228      * @param string $option 
    229      * @return void 
    230      */ 
    231     public function getOption($option) 
    232     { 
    233         if (isset($this->options[$option])) { 
    234             return $this->options[$option]; 
    235         } 
    236     } 
    237  
    238     /** 
    239      * setOption 
    240      *  
    241      * Set option value 
    242      * 
    243      * @param string $option  
    244      * @return void 
    245      */ 
    246     public function setOption($option, $value) 
    247     { 
    248       return $this->options[$option] = $value; 
    249     } 
    250      
    251     /** 
    252225     * returns an array of available PDO drivers 
    253226     */ 
     
    301274    { 
    302275        //$this->connect(); 
    303          
    304276         
    305277        return $this->dbh; 
     
    11221094    public function getAttribute($attribute) 
    11231095    { 
     1096        if ($attribute == Doctrine::ATTR_QUOTE_IDENTIFIER) { 
     1097            return false; 
     1098        } 
     1099         
     1100        /* legacy */  
    11241101        if ($attribute >= 100) { 
    11251102            if ( ! isset($this->_attributes[$attribute])) { 
    1126                 return parent::getAttribute($attribute); 
     1103                return null; 
    11271104            } 
    11281105            return $this->_attributes[$attribute]; 
     
    11681145        } 
    11691146        return $this; 
     1147    } 
     1148     
     1149    public function hasAttribute($name) 
     1150    { 
     1151        return false; 
    11701152    } 
    11711153