tbrehm
2012-06-11 897af06af9522ded99b1e0f46730299e89856ffe
commit | author | age
b64955 1 Some guidelines for web development with php.
P 2 -----------------------------------------------------
316369 3 * Unix Line Breaks Only, NO windows breaks please.
P 4 * Tabs set at 4 spaces either as tabs or spaces.
5 * no accidental _<?php space before, within or after a file
6 * every php file starts and end with <?php ?> no spaces before or after
7 * error_reporting(E_ALL|E_STRICT) , yep php5
8 * Magic quotes is gone in php6, get used to it now. config = magic_quotes_gpc() Everything must be quoted
1a2876 9 * Don't use ereg,split and other old function -> gone in php 5.4 or 6 (different information on php.net) http://www.php.net/manual/en/migration53.deprecated.php
X 10 * Don't use shorttags. A Shorttag is <? and that is confusing with <?xml -> always <?php
b64955 11
3eeed9 12 please mark any section that need review or work on with
316369 13 // TODO 
3eeed9 14 * Add documentation about access levels (public, private, protected).
B 15 * Make function / var names on the following way, first word lower, next word(s) first letter upper like. getFirstResult();
b64955 16
c9e9cd 17 Pear coding guidelines
b64955 18
P 19 //*****************************************************************************
20 // Commenting style
21 //*****************************************************************************
22 phpdoc is used for creating and autogenerating the documentation, this means that
23 some of the comments can be formatted to be included in documentation.
24 ie the source files are scanned then processed and html docs are created. 
25
26 The comments break down into the following types
27 // is uses for removing lines and debug dev etc
28 //** and //* are used as "sub comments"
29 /* 
30     is used to comment out blocks
31 */
32 /** is used to create documentaion
33 * thats over 
34 * lines
35 */
36
37 If you need to block out a section then use
38 /*
39 function redundant_code(){
40     something here
41 }
42 */
43
44 To block out single lines use // and all // are assumed to be redundant test code and NOT comments
45
46 // print_r($foo);
47
72a844 48 For inline comment use //** and //* eg
b64955 49
P 50 //** Decide what do do
51 switch($decide){
52     //* blow it up
53     case 'baloon':
54         $foo->gas(+1);
55         // test_pressure(); << inline comment
56         break;
57
58     //* Do default action
59     default:
60         do_land();
61         get_gps();
62         //* following grant greaceful exit
63         //basket_exit_crash();
64         basket_exit();
65
66 }
67
68 Do not use the phpdoc on every function, eg 
69
70 /**
72a844 71 * Login a user
b64955 72 * @param string user  username
P 73 * @param string password of user
74 */
75 >>
76 function login($user, $pass){
77 .......
78 }
79 <<
72a844 80 as this function explains its self, the following clean code will suffice
b64955 81 >>
P 82 function login($user, $pass){
83 .......
84 }
85
86 If you do need to explain a function then put un the summary syntax eg
87
88 /** Pass an array of values where third param is bar
72a844 89 * $foo['bar'] = 1; // allow a user
b64955 90 * $foo['bar'] = 2; // destroy user
P 91 * $foo['bar'] = -1; // recreate
92 */
93 public function do_something($x, $y, $foo){
94 ... do something interesting    
95 }
96
5f8086 97 //*****************************************************************************
T 98 // Where to store custom settings
99 //*****************************************************************************
100
101 -- Interface settings
102
103 The recommended place to store global interface settings is the ini style global config system 
104 (see system.ini.master file in install/tpl/ to set defaults). The settings file 
105 gets stored inside the ispconfig database. Settings can be accessed with the function:
106
107 $app->uses('ini_parser,getconf');
108 $interface_settings = $app->getconf->get_global_config('modulename');
109
110 where modulename corresponds to the config section in the system.ini.master file.
111 To make the settings editable under System > interface config, add the new configuration
112 fields to the file interface/web/admin/form/system_config.tform.php and the corresponding
113 tempalte file in the templates subfolder of the admin module.
114
115 -- Server settings
116
117 Server settings are stored in the ini style server config system (see server.ini.master template file)
118 The settings file gets stored inside the ispconfig database in the server table. Settings can be 
119 accessed with the function $app->getconf->get_server_config(....)
120
121 Example to access the web configuration:
122
123 $app->uses('ini_parser,getconf');
124 $web_config = $app->getconf->get_server_config($server_id,'web');
125
b64955 126
d85c3d 127 //*****************************************************************************
L 128 // Learn about the form validators
129 //*****************************************************************************
130 There are form validators in interface/lib/classes/tform.inc.php to make validating forms easier.
131 Read about: REGEX,UNIQUE,NOTEMPTY,ISEMAIL,ISINT,ISPOSITIVE,ISIPV4,CUSTOM
b64955 132