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