1
0
mirror of synced 2024-12-16 08:06:02 +03:00
doctrine2/manual/new/docs/en/coding-standards/naming-conventions.txt
jepso 5329c3827c * Converted most of the docs to the new format.
* Fixed a few layout bugs in new documentation
* Fixed documentation table of contents indentation bug in IE6 (fixes #344)
* Fixed a parser bug in Sensei_Doc_Section
* Restructrured a bit some files of the documentation.
2007-06-13 21:30:32 +00:00

69 lines
4.6 KiB
Plaintext

+++ 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), however must end with the word "{{Interface}}" (unless the interface is approved not to contain it such as {{Doctrine_Overloadable}}). Some examples:
* {{Doctrine_Db_EventListener_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/Db.php}}
* {{Doctrine/Connection/Transaction.php}}
* File names must follow the mapping to class names described above.
+++ Functions and methods
* Function names may only contain alphanumeric characters. Underscores are not permitted. Numbers are permitted in function names but are discouraged.
* Function names must always start with a lowercase letter. 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. 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.
* Functions in the global scope ("floating functions") are NOT permmitted. All static functions should be wrapped in a static class.
+++ Variables
All variables must satisfy the following conditions:
* Variable names may only contain alphanumeric characters. Underscores are not permitted. Numbers are permitted in variable names but are discouraged.
* Variable names 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 ||~ Variable name ||
|| {{Doctrine_Connection}} || {{$conn}} ||
|| {{Doctrine_Collection}} || {{$coll}} ||
|| {{Doctrine_Manager}} || {{$manager}} ||
|| {{Doctrine_Query}} || {{$query}} ||
|| {{Doctrine_Db}} || {{$db}} ||
* 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
Following rules must apply to all constants used within Doctrine framework:
* Constants may contain both alphanumeric characters and the underscore.
* Constants 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.
<code type="php">
class Doctrine_SomeClass {
const MY_CONSTANT = 'something';
}
print Doctrine_SomeClass::MY_CONSTANT;
</code>
+++ Record columns