sintonia/livesupport/doc/developmentEnvironment/phpFileConventions.html

137 lines
5.3 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8"
http-equiv="content-type">
<title>PHP file conventions</title>
<meta content="$Author: tomas $" name="author">
</head>
<body>
<h1>Preface</h1>
This document is part of the <a href="http://livesupport.campware.org/">LiveSupport</a>
project, Copyright &#169; 2004 <a href="http://www.mdlf.org/">Media
Development Loan Fund</a>, under the GNU <a
href="http://www.gnu.org/licenses/gpl.html">GPL</a>.<br>
<ul>
<li>Author: $Author: tomas $</li>
<li>Version: $Revision: 1.1 $</li>
<li>Location: $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/doc/developmentEnvironment/phpFileConventions.html,v $</li>
</ul>
<h1>Scope</h1>
This document describes the PHP script file conventions for the LiveSupport
project. See also the generic description of the <a
href="fileConventions.html">file conventions</a> in the LiveSupport
project.<br>
<h1>Introduction</h1>
PHP scripts are text-based files containing PHP class definitions and/or commands.<br/>
They should adhere to the <a
href="http://pear.php.net/manual/en/standards.php">PEAR coding standards
conventions</a>.<br>
As text based files, they should adhere to the <a
href="fileConventions.html#textConventions">generic text-based
conventions</a>.<br>
<h1>Naming</h1>
A PHP script containing only class definition should have filename which reflects the class,
it is implementing.
Class names begin with a capital letter, followed by lower case letters.
In case of a multiple word file name, the first letter of each word is
capitalized.<br/>
Other PHP scripts should have name starting with lowecase letter.<br/>
PHP script files are named by the following rules:<br>
<ul>
<li>there are no spaces in the file name</li>
<li>for file names containing multiple words, each additional word
begins with a capital letter</li>
<li>the extension of the file is <code>.php</code><br>
</li>
</ul>
<h1>Structure</h1>
PHP scripts are partitioned by using the following 80 column wide partitioning comments:<br/>
<pre>
/* ==================================================== name of the partition */
</pre>
and
<pre>
/* ------------------------------------------------- name of the subpartition */
</pre>
The file has the following mandatory structure:<br>
<ul>
<li>PHP starting tag <code>&lt;?php </code></li>
<li>Header</li>
<li>Defines&nbsp;?</li>
<li>Include files&nbsp;?</li>
<li>Code sections&nbsp;+</li>
<li>PHP ending tag <code>?&gt; </code></li>
</ul>
Because PHP is in-HTML embedable script language, it is possible to mix PHP and HTML code
using PHP tags <code>&lt;?php</code> and <code>?&gt;</code>. This mixing approach is little bit
obsolete and it is better to use pure PHP (with structure described above) and some template system to generate HTML.
<h2>Header</h2>
The header holds all information mandated by the <a
href="fileConventions.html#header">generic guidelines</a>, but
are enclosed in the PHP multiline comments <code>/* */</code>. Note the 80
column wide partitioning delimiter enclosing the header.<br>
<pre>
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/doc/developmentEnvironment/phpFileConventions.html,v $
------------------------------------------------------------------------------*/
</pre>
<h2>Defines<br>
</h2>
This section contains all the constant defines, similar as:<br/>
<br/>
<code>define('CONSTAT_NAME', 10);</code><br/>
<br/>
<h2>Include files<br>
</h2>
This section contains all the include files that the script needs
to include.
The include files are listed in
a most generic to most specific order: first PEAR classes, then
other LiveSupport module include files, and finally include files from
the same module / product are listed.<br>
Is much safer to use <code>include_once</code> or <code>require_once</code>, not the original versions
of this statement.<br/>
<br>
<h2>Code sections</h2>
This sections contain class definitions, function definitions or runable PHP commands.<br/>
<h1>Template</h1>
See a generic <a href="templates/phpScriptTemplate.phps">template
for PHP scripts</a>.
You may freely <a href="templates/phpScriptTemplate.php.txt">download</a> and copy this
template when starting to create a new script.<br>
<br>
</body>
</html>