Chapter 32: Coding Standards 382 Naming Conventions Classes The Doctrine ORM Framework uses the same class naming convention as PEAR and Zend framework, where the names of the classes directly map to the directories in which they are stored. The root level directory of the Doctrine Framework is the "Doctrine/" directory, under which all classes are stored hierarchially. Class names may only contain alphanumeric characters. Numbers are permitted in class names but are discouraged. Underscores are only permitted in place of the path separator, eg. the filename "Doctrine/Table/Exception.php" must map to the class name "Doctrine_Table_Exception". If a class name is comprised of more than one word, the first letter of each new word must be capitalized. Successive capitalized letters are not allowed, e.g. a class "XML_Reader" is not allowed while "Xml_Reader" is acceptable. Interfaces Interface classes must follow the same conventions as other classes (see above). They must also end with the word "Interface" (unless the interface is approved not to contain it such as Doctrine_Overloadable). Some examples: Examples • Doctrine_Adapter_Interface • Doctrine_EventListener_Interface Filenames For all other files, only alphanumeric characters, underscores, and the dash character ("-") are permitted. Spaces are prohibited. Any file that contains any PHP code must end with the extension ".php". These examples show the acceptable filenames for containing the class names from the examples in the section above: • Doctrine/Adapter/Interface.php • Doctrine/EventListener/Interface File names must follow the mapping to class names described above. Functions and Methods Function names may only contain alphanumeric characters and underscores are not permitted. Numbers are permitted in function names but are highly discouraged. They must always start with a lowercase letter and when a function name consists of more than one word, the first letter of each new word must be capitalized. This is commonly called the "studlyCaps" or "camelCaps" method. Verbosity is encouraged and function names should be as verbose as is practical to enhance the understandability of code. For object-oriented programming, accessors for objects should always be prefixed with either "get" or "set". This applies to all classes except for Doctrine_Record which has some accessor methods prefixed with 'obtain' and 'assign'. The reason for this is that since all user defined ActiveRecords inherit Doctrine_Record, it should populate the get / set namespace as little as possible. ----------------- Brought to you by
Chapter 32: Coding Standards 383 Functions in the global scope ("floating functions") are NOT permmitted. All static functions should be wrapped in a static class. Variables Variable names may only contain alphanumeric characters. Underscores are not permitted. Numbers are permitted in variable names but are discouraged. They must always start with a lowercase letter and follow the "camelCaps" capitalization convention. Verbosity is encouraged. Variables should always be as verbose as practical. Terse variable names such as "$i" and "$n" are discouraged for anything other than the smallest loop contexts. If a loop contains more than 20 lines of code, the variables for the indices need to have more descriptive names. Within the framework certain generic object variables should always use the following names: Object type Doctrine_Connection $conn Doctrine_Collection $coll Doctrine_Manager Doctrine_Query $q Variable name $manager There are cases when more descriptive names are more appropriate (for example when multiple objects of the same class are used in same context), in that case it is allowed to use different names than the ones mentioned. Constants Constants may contain both alphanumeric characters and the underscore. They must always have all letters capitalized. For readablity reasons, words in constant names must be separated by underscore characters. For example, ATTR_EXC_LOGGING is permitted but ATTR_EXCLOGGING is not.Constants must be defined as class members by using the "const" construct. Defining constants in the global scope with "define" is NOT permitted. class Doctrine_SomeClass { const MY_CONSTANT = 'something'; } Listing 32-1 echo $Doctrine_SomeClass::MY_CONSTANT; Record Columns All record columns must be in lowercase and usage of underscores(_) are encouraged for columns that consist of more than one word. class User { public function setTableDefinition() { $this->hasColumn('home_address', 'string'); } } Listing 32-2 ----------------- Brought to you by
Doctrine ORM for PHP Guide to Doctr
Table of Contents iii Examples ....
Table of Contents v Sample Queries
Table of Contents vii Component Que
Table of Contents ix Inserting a No
Table of Contents xi Generating Mig
Chapter 1: Introduction 13 Chapter
Chapter 1: Introduction 15 layer de
Chapter 1: Introduction 17 Further
Chapter 2: Getting Started 19 Insta
Chapter 2: Getting Started 21 Downl
Chapter 2: Getting Started 23 In th
Chapter 3: Introduction to Connecti
Chapter 3: Introduction to Connecti
Chapter 3: Introduction to Connecti
Chapter 4: Configuration 31 $table-
Chapter 4: Configuration 33 backtic
Chapter 4: Configuration 35 class M
Chapter 4: Configuration 37 // boot
Chapter 5: Connections 39 Chapter 5
Chapter 5: Connections 41 $conn = D
Chapter 5: Connections 43 This is p
Chapter 6: Introduction to Models 4
Chapter 6: Introduction to Models 4
Chapter 6: Introduction to Models 4
Chapter 6: Introduction to Models 5
Chapter 7: Defining Models 53 Chapt
Chapter 7: Defining Models 55 } } /
Chapter 7: Defining Models 57 class
Chapter 7: Defining Models 59 Strin
Chapter 7: Defining Models 61 class
Chapter 7: Defining Models 63 class
Chapter 7: Defining Models 65 $this
Chapter 7: Defining Models 67 onUpd
Chapter 7: Defining Models 69 // te
Chapter 7: Defining Models 71 First
Chapter 7: Defining Models 73 } } $
Chapter 7: Defining Models 75 In ma
Chapter 7: Defining Models 77 Here
Chapter 7: Defining Models 79 class
Chapter 7: Defining Models 81 Here
Chapter 7: Defining Models 83 } } )
Chapter 7: Defining Models 85 --- #
Chapter 7: Defining Models 87 } { }
Chapter 7: Defining Models 89 } } )
Chapter 7: Defining Models 91 Some
Chapter 7: Defining Models 93 Now w
Chapter 7: Defining Models 95 # ...
Chapter 7: Defining Models 97 Concl
Chapter 8: Working with Models 99 $
Chapter 8: Working with Models 101
Chapter 8: Working with Models 103
Chapter 8: Working with Models 105
Chapter 8: Working with Models 107
Chapter 8: Working with Models 109
Chapter 8: Working with Models 111
Chapter 8: Working with Models 113
Chapter 8: Working with Models 115
Chapter 8: Working with Models 117
Chapter 8: Working with Models 119
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 10: Component Overview 163
Chapter 10: Component Overview 165
Chapter 10: Component Overview 167
Chapter 10: Component Overview 169
Chapter 10: Component Overview 171
Chapter 10: Component Overview 173
Chapter 10: Component Overview 175
Chapter 10: Component Overview 177
Chapter 10: Component Overview 179
Chapter 10: Component Overview 181
Chapter 10: Component Overview 183
Chapter 10: Component Overview 185
Chapter 10: Component Overview 187
Chapter 10: Component Overview 189
Chapter 10: Component Overview 191
Chapter 11: Native SQL 193 $users =
Chapter 12: YAML Schema Files 195 C
Chapter 12: YAML Schema Files 197 D
Chapter 12: YAML Schema Files 199 p
Chapter 12: YAML Schema Files 201 -
Chapter 12: YAML Schema Files 203 O
Chapter 12: YAML Schema Files 205 C
Chapter 12: YAML Schema Files 207 o
Chapter 13: Data Validation 209 Cha
Chapter 13: Data Validation 211 # .
Chapter 13: Data Validation 213 The
Chapter 13: Data Validation 215 if
Chapter 13: Data Validation 217 Her
Chapter 13: Data Validation 219 # .
Chapter 13: Data Validation 221 } e
Chapter 13: Data Validation 223 } }
Chapter 13: Data Validation 225 //
Chapter 14: Data Hydrators 227 Chap
Chapter 14: Data Hydrators 229 echo
Chapter 15: Inheritance 231 Chapter
Chapter 15: Inheritance 233 columns
Chapter 15: Inheritance 235 name: s
Chapter 15: Inheritance 237 // test
Chapter 16: Behaviors 239 Chapter 1
Chapter 16: Behaviors 241 Here is t
Chapter 16: Behaviors 243 } $this->
Chapter 16: Behaviors 245 The imple
Chapter 16: Behaviors 247 } } ); )
Chapter 16: Behaviors 249 $blogPost
Chapter 16: Behaviors 251 Look how
Chapter 16: Behaviors 253 length 25
Chapter 16: Behaviors 255 $ php tes
Chapter 16: Behaviors 257 Searchabl
Chapter 16: Behaviors 259 // test.p
Chapter 16: Behaviors 261 } } elsei
Chapter 16: Behaviors 263 ) [name]
Chapter 16: Behaviors 265 } public
Chapter 17: Searching 267 Chapter 1
Chapter 17: Searching 269 body LONG
Chapter 17: Searching 271 • Strip
Chapter 17: Searching 273 $ php tes
Chapter 17: Searching 275 // test.p
Chapter 18: Hierarchical Data 277 N
Chapter 18: Hierarchical Data 279 i
Chapter 18: Hierarchical Data 281 E
Chapter 18: Hierarchical Data 283 F
Chapter 19: Data Fixtures 285 Chapt
Chapter 19: Data Fixtures 287 class
Chapter 19: Data Fixtures 289 Resou
Chapter 19: Data Fixtures 291 --- #
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 21: Transactions 305 log 43
Chapter 21: Transactions 307 try {
Chapter 22: Event Listeners 309 Cha
Chapter 22: Event Listeners 311 pub
Chapter 22: Event Listeners 313 pos
Chapter 22: Event Listeners 315 } {
Chapter 22: Event Listeners 317 */
Chapter 22: Event Listeners 319 FRO
Chapter 22: Event Listeners 321 Ski
Chapter 23: Caching 323 $cacheDrive
Chapter 23: Caching 325 // bootstra
Chapter 24: Migrations 327 Chapter
Chapter 24: Migrations 329 array('t