diff --git a/Tests/autoload.php b/Tests/autoload.php index 3ed1e23..a59cf32 100644 --- a/Tests/autoload.php +++ b/Tests/autoload.php @@ -1,5 +1,5 @@ */ + +/** Test the outputjson.php file */ class test_outputjson extends PHPUnit_Framework_TestCase { + /** Entry null */ public function testoutputjson1 () { $this->expectOutputString("\"\""); @@ -8,6 +14,7 @@ class test_outputjson extends PHPUnit_Framework_TestCase $output->out (""); } + /** Entry string */ public function testoutputjson2 () { $this->expectOutputString("\"string\""); @@ -15,6 +22,7 @@ class test_outputjson extends PHPUnit_Framework_TestCase $output->out ("string"); } + /** Entry array */ public function testoutputjson3 () { $this->expectOutputString("[1,2,3]"); diff --git a/auth.php b/auth.php index d596baf..4610ca8 100644 --- a/auth.php +++ b/auth.php @@ -1,10 +1,16 @@ */ +/** User authentication (abstract class) */ class auth { /** Display the authentication page The message is displayed to the user in case of error - The url is the caller url to go back if authentication is correct */ + The url is the caller url to go back if authentication is correct + @param string|null $message Message to display to the user + @param string|null $url URL to go back after successful authentication */ public function pageHTML ($message="", $url="") { $res = ""; @@ -72,7 +78,9 @@ class auth /** Check if the email and password are correct Return TRUE if the authentication is correct - Return an exception if there is a problem */ + Return an exception if there is a problem + @param string $email Email to authenticate + @param string $password Password to authenticate */ public function authentication ($email, $password) { throw new exception (_("No authentication available"), 405); @@ -84,7 +92,10 @@ class auth throw new exception (_("No getdetails available"), 405); } - /** Method to change the password */ + /** Method to change the password + @param string $oldpassword The old password (to check if the user have the + rights to change the password) + @param string $newpassword The new password to be recorded */ public function changepassword ($oldpassword, $newpassword) { throw new exception (_("No password change available"), 405); diff --git a/authldap.php b/authldap.php index a2e5f8f..ec6cde1 100644 --- a/authldap.php +++ b/authldap.php @@ -1,24 +1,36 @@ */ + /** User authentication against LDAP server */ class authldap extends auth { /** LDAP server : can be ldaps://server.domain.tld if LDAPS */ public $ldapserver="localhost"; + /** LDAP TCP Port (389 by default) */ public $ldapport=389; + /** LDAP Connection timeout (5s by default) */ public $ldaptimeout=5; /** LDAP authentication to search user */ public $ldapauth = ""; + /** LDAP authentication password */ public $ldappwd = ""; + /** LDAP Search base */ public $ldapbase = ""; /** Filter used to search user */ public $ldapfilter = "(mail=%s)"; + /** Field used to identify a user */ public $ldapfield = "mail"; /** Filter used to find the available datas of an authenticated user */ public $ldapfiltersearch = "(objectClass=inetOrgPerson)"; + /** The opened LDAP connection identifier */ private $ldapconn = NULL; + /** The DN of the user when found */ private $ldapdnuser = NULL; + /** Check the availability of LDAP functions in PHP */ function __construct () { if (!function_exists ("ldap_connect")) @@ -41,7 +53,9 @@ class authldap extends auth throw new Exception ("Authentication error in pre-auth LDAP", 500); } - /** Try to authenticate the email/password of the user */ + /** Try to authenticate the email/password of the user + @param string $email Email to authenticate + @param string $password Password to authenticate */ public function authentication ($email, $password) { $filter = sprintf ($this->ldapfilter, $email, $email, $email, $email); @@ -60,7 +74,7 @@ class authldap extends auth $this->ldapdnuser = $dn; } - /** Return all the parameters recorded for the authenticate user */ + /** Return all the parameters recorded for the authenticate user */ public function getdetails () { if ($this->ldapdnuser === NULL) @@ -81,7 +95,10 @@ class authldap extends auth return $res; } - /** Method to change the password */ + /** Method to change the password + @param string $oldpassword The old password (to check if the user have the + rights to change the password) + @param string $newpassword The new password to be recorded */ public function changepassword ($oldpassword, $newpassword) { throw new Exception (_("The password can't be change for LDAP users"), 405); @@ -117,6 +134,7 @@ class authldap extends auth return $datas; } + /** Close the LDAP connection when closing the object or PHP */ function __destruct () { if (isset ($this->ldapconn)) diff --git a/authorization.php b/authorization.php index 21181a5..de1c7b2 100644 --- a/authorization.php +++ b/authorization.php @@ -1,8 +1,13 @@ */ + /** All the needed functions to authorize or deny access to an authenticated user */ class authorization { + /** Separator between differents modules/objects */ private $separator = "/"; /** Establish a connexion to the authorization database */ @@ -11,53 +16,69 @@ class authorization } /** Return if the user right is NONE, READ, WRITE, EXECUTE - if the object doesn't exists, or is not readable, throw an exception */ + if the object doesn't exists, or is not readable, throw an exception + @param string $object The object path to examine + @return NONE, READ, WRITE, EXECUTE */ public function validate ($object) { } - /** Add a new object, with owner and group, and mode bits */ + /** Add a new object, with owner and group, and mode bits + @param string $object Object path to add + @param integer $owner Owner ID of the object + @param integer $group Group ID of the object + @param integer $modbits Bits of authorization */ public function add ($object, $owner, $group, $modbits) { } - /** Remove the informations about an object */ + /** Remove the informations about an object + @param string $object Object path to drop */ public function drop ($object) { } /** Change the owner of an object - Need to be the root administrator */ + Need to be the root administrator + @param string $object Object path to add + @param integer $owner Owner ID of the object */ public function chown ($object, $owner) { } /** Change the group of an object - Need to be the owner of the object or the root administrator */ + Need to be the owner of the object or the root administrator + @param string $object Object path to add + @param integer $group Group ID of the object */ public function chgrp ($object, $group) { } /** Change mode bits for an object - Need to be the owner of the object or the root administrator */ + Need to be the owner of the object or the root administrator + @param string $object Object path to change + @param integer $mod Bits of authorization */ public function chmod ($object, $mod) { } /** Return the mode bits for an object if all his parents are readable for - the user */ + the user + @param string $object Object path to examine */ public function lsmod ($object) { } /** Return the owner for an object if all his parents are readable for - the user */ + the user + @param string $object Object path to examine */ public function lsown ($object) { } /** Return the owner for an object if all his parents are readable for - the user */ + the user + @param string $object Object path to examine */ public function lsgrp ($object) { } diff --git a/authparams.php b/authparams.php index 22927e8..53624ce 100644 --- a/authparams.php +++ b/authparams.php @@ -1,4 +1,8 @@ */ + /** Takes the email and the password of the user */ class authparams { diff --git a/authsession.php b/authsession.php index af561f0..853fef6 100644 --- a/authsession.php +++ b/authsession.php @@ -1,7 +1,13 @@ */ + /** User authentication against SESSION */ class authsession extends auth { + /** Check if there is already a session or the user can not be authenticated + */ function __construct () { if (!isset ($_SESSION)) @@ -14,7 +20,9 @@ class authsession extends auth return TRUE; } - /** Try to authenticate the email/password of the user */ + /** Try to authenticate the email/password of the user + @param string $email Email to authenticate + @param string $password Password to authenticate */ public function authentication ($email, $password) { if (!isset ($_SESSION["auth"]["email"]) || @@ -26,6 +34,7 @@ class authsession extends auth throw new Exception ("Bad password for '$email'", 401); } + /** Return all the parameters recorded for the authenticate user */ public function getdetails () { return array ("lastname"=>$_SESSION["auth"]["lastname"], @@ -33,6 +42,10 @@ class authsession extends auth "email"=>$_SESSION["auth"]["email"]); } + /** Method to change the password : unavailable in SESSION auth + @param string $oldpassword The old password (to check if the user have the + rights to change the password) + @param string $newpassword The new password to be recorded */ public function changepassword ($oldpassword, $newpassword) { throw new Exception (_("The password can't be change for SESSION users"), diff --git a/authsympa.php b/authsympa.php index 6376f99..21bb9a1 100644 --- a/authsympa.php +++ b/authsympa.php @@ -1,4 +1,9 @@ */ + +require_once ("auth.php"); /** User authentication against SYMPA server Sympa is a mailling list server. It can handle authentication with - a username (a email adress) @@ -7,31 +12,39 @@ - a Sympa SOAP server WSDL - the part of list which should be test : subscriber, owner, editor It use the SOAP protocol. So the PHP SOAP library is needed and the network - must be open between the Web server and the Sympa server. */ -/* POC : + must be open between the Web server and the Sympa server. +POC : $auth = new authsympa (); $auth->wsdl = "https://lists.domain.tld/sympa/wsdl"; $auth->list = "listtest@lists.domain.tld"; $auth->connect (); var_dump ($auth->authentication ("user@domain.tld", "Pa$$word!")); */ -require_once ("auth.php"); class authsympa extends auth { + /** URL of the WSDL Sympa server */ public $wsdl = null; + /** Mailling list to be checked if user is present */ public $list = null; - public $function = "subscriber"; // can be subscriber, owner, editor + /** Function of the user in the mailling list + can be subscriber, owner, editor */ + public $function = "subscriber"; + /** Soap Client identifier */ private $client = null; + /** Temporary auth key used betwwen commands */ private $authkey = null; + /** Email of the user if the authentication is correct */ private $email = null; + /** Check if the SOAP module is available in PHP */ public function __construct () { if (! class_exists ("SoapClient")) throw new Exception (_("No SOAP PHP library available"), 500); } + /** Connect to the Sympa server */ public function connect () { if ($this->wsdl === null) @@ -39,6 +52,9 @@ class authsympa extends auth $this->client = new SoapClient($this->wsdl); } + /** Try to authenticate the email/password of the user + @param string $email Email to authenticate + @param string $password Password to authenticate */ public function authentication ($email, $password) { if ($this->client === null) @@ -58,11 +74,16 @@ class authsympa extends auth return $rc; } + /** Return all the parameters recorded for the authenticate user */ public function getdetails () { throw new Exception (_("The details can't be provided by Sympa"), 404); } + /** Method to change the password + @param string $oldpassword The old password (to check if the user have the + rights to change the password) + @param string $newpassword The new password to be recorded */ public function changepassword ($oldpassword, $newpassword) { throw new Exception (_("The password can't be change for SYMPA users"), diff --git a/cli.php b/cli.php index 4ae1c44..f5f958f 100644 --- a/cli.php +++ b/cli.php @@ -1,41 +1,45 @@ */ + +/** Allow to interract with controllers and models from the CLI */ class cli { - /** Run in CLI mode with parameters */ - /* Example of cli code : -#!/usr/bin/php5 -run(); */ - - public function run () - { - global $argv; - $launcher = $argv[0]; - chdir (dirname ($argv[0])."/.."); - array_shift ($argv); - - if (isset ($argv[0]) && $argv[0] === "-h") + /** Run in CLI mode with parameters + Example of cli code : + #!/usr/bin/php5 + run(); */ + public function run () { - echo "Execute in CLI a controller or a model (in expert mode)\n"; - echo " $launcher -h : display this help\n"; - echo " $launcher -list : display controllers\n"; - echo " $launcher -expert -list : display controllers and models\n"; - echo " $launcher -listmethods : \n"; - echo " display the methods available the controller class\n"; - echo " $launcher -expert -listmethods :\n"; - echo " display the methods available the model or controller class\n"; - echo " $launcher -listmethodsdetails : \n"; - echo " display the methods available the controller class\n"; - echo " $launcher -expert -listmethodsdetails :\n"; - echo " display the methods available the model or controller class\n"; - echo " $launcher [args]\n"; - echo " execute the method with the provided args\n"; - echo " $launcher -expert [args]\n"; - echo " execute the method with the provided args\n"; - echo "You can replace ONE arg by a dash (-) to read from stdin\n"; - exit; + global $argv; + $launcher = $argv[0]; + chdir (dirname ($argv[0])."/.."); + array_shift ($argv); + + if (isset ($argv[0]) && $argv[0] === "-h") + { + echo "Execute in CLI a controller or a model (in expert mode)\n"; + echo " $launcher -h : display this help\n"; + echo " $launcher -list : display controllers\n"; + echo " $launcher -expert -list : display controllers and models\n"; + echo " $launcher -listmethods : \n"; + echo " display the methods available the controller class\n"; + echo " $launcher -expert -listmethods :\n"; + echo " display the methods available the model or controller class\n"; + echo " $launcher -listmethodsdetails : \n"; + echo " display the methods available the controller class\n"; + echo " $launcher -expert -listmethodsdetails :\n"; + echo " display the methods available the model or controller class\n"; + echo " $launcher [args]\n"; + echo " execute the method with the provided args\n"; + echo " $launcher -expert [args]\n"; + echo " execute the method with the provided args\n"; + echo "You can replace ONE arg by a dash (-) to read from stdin\n"; + exit; } $EXPERT = FALSE; diff --git a/config.php b/config.php index 3c896a9..f15ae00 100644 --- a/config.php +++ b/config.php @@ -1,4 +1,8 @@ */ + /** Manage the configurations of the module done by administrator in a config file It is based on the module configuration defaults @@ -11,11 +15,10 @@ $var = $config->get ("param"); */ class config { - public $default = array (); // All the parameters allowed with their default - // value - public $confFile = "./datas/configuration.php"; // Use the .php to protect - // the informations by adding a killing feature in - // the file + /** All the parameters allowed with their default value */ + public $default = array (); + /** Use the .php to protect the informations */ + public $confFile = "./datas/configuration.php"; /** List all the parameters configurable in the software */ public function params () @@ -24,8 +27,9 @@ class config } - /** Get the value of the provided parameter recorded in .ini file - If it is not set in .ini file, use the default value */ + /** Get the value of the provided parameter recorded in .php file + If it is not set in .php file, use the default value + @param string $param The option name to be returned */ public function get ($param) { if (!array_key_exists ($param, $this->default)) @@ -49,7 +53,9 @@ class config } /** Define a value for the parameter in the config file. Add all the default - values if they are not defined */ + values if they are not defined + @param string $param The option name + @param mixed $value The option value */ public function set ($param, $value) { if (!array_key_exists ($param, $this->default)) @@ -82,6 +88,10 @@ class config $this->confFile)); } + /** Display the $values in PHP format to be "require" easily + @param mixed $values Values to be recorded + @param string $phpcode Actual value of the php code + @param integer $indent Number of spaces in the indentation of config */ private function writePHP ($values, $phpcode, $indent) { foreach ($values as $key=>$val) diff --git a/dblayer.php b/dblayer.php index 73e3fc0..6995114 100644 --- a/dblayer.php +++ b/dblayer.php @@ -1,4 +1,8 @@ */ + // dblayer.php /* Documentation : @@ -27,15 +31,20 @@ Optionnaly, you can add the /** Permit abstraction on the differents SQL databases available */ class dblayer extends PDO { + /** The fields with the definition of type, and special parameters */ protected $fields = array (); + /** The primary field */ protected $primary = null; + /** An array to define the unique fields (or array of unique fields) */ protected $unique = null; + /** The db connection */ protected $db = null; + /** Debug of the SQL */ public $debug = FALSE; /** Return all the tables available in the database */ function listTables () { - $driver = $this->getAttribute(PDO::ATTR_DRIVER_NAME); + $driver = $this->getAttribute (PDO::ATTR_DRIVER_NAME); $rc = @include_once ("dbLayer".ucfirst ($driver).".php"); if ($rc === FALSE) throw new Exception (sprintf (_("dbLayer driver %s not available"), @@ -54,7 +63,11 @@ class dblayer extends PDO MYSQL : SHOW COLUMNS FROM yourtable;*/ /** Connection to the database engine - See http://fr2.php.net/manual/en/pdo.construct.php for the $dsn format */ + See http://fr2.php.net/manual/en/pdo.construct.php for the $dsn format + @param string $dsn PDO Data Source Name + @param string|null $username Username to connect + @param string|null $password Password to connect + @param string|null $driver_options Driver options to the database */ function __construct ($dsn, $username=null, $password=null, $driver_options=null) { @@ -62,7 +75,8 @@ class dblayer extends PDO $this->db->setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } - /** Create a new entry in the table. Datas must be an indexed array */ + /** Create a new entry in the table. Datas must be an indexed array + @param array $datas Datas to be recorded (column=>value)*/ function create ($datas) { if ($this->db === null) @@ -145,13 +159,14 @@ class dblayer extends PDO /** Read the table content based on a select filter, ordered by order operator and the associated select value - - $select = array (array ($key, $val, $operator), ...) - $key=>column, $val=>value to found, $operator=>'LIKE', =... - - $display = array ($col1, $col2...); - Columns displayed - - $order = array (array ($key, $orientation), ...) - $key=>column, $orientation=ASC/DESC - */ + @param array|null $select Rows to select with + $select = array (array ($key, $val, $operator), ...) + $key=>column, $val=>value to found, $operator=>'LIKE', =... + @param array|null $display Columns displayed + $display = array ($col1, $col2...); + @param array|null $order Sort the columns by orientation + $order = array (array ($key, $orientation), ...) + $key=>column, $orientation=ASC/DESC */ function read ($select=null, $display=null, $order=null) { if ($this->db === null) @@ -224,7 +239,10 @@ class dblayer extends PDO } /** Update the key tuple with the provided datas - Return the number of rows modified */ + Return the number of rows modified + @param string|integer $updatekey The key applied on primary key to be + updated + @param array $datas The values to be updated */ function update ($updatekey, $datas) { if ($this->db === null) @@ -326,7 +344,8 @@ class dblayer extends PDO } /** Delete a tuple identified by its primary key - Return the number of deleted rows (can be 0 !) */ + Return the number of deleted rows (can be 0 !) + @param strin|integer $deletekey The key of primary key to be deleted */ function delete ($deletekey) { if ($this->db === null) diff --git a/examples/blog/controllers/controller_blog.php b/examples/blog/controllers/controller_blog.php index 586dca7..c3f55b2 100644 --- a/examples/blog/controllers/controller_blog.php +++ b/examples/blog/controllers/controller_blog.php @@ -1,8 +1,14 @@ */ + error_reporting (E_ALL); +/** The main class : manage all the blogs articles */ class blog { - /** Return an article */ + /** Return an article + @param string|integer|null $articleid The article to display */ private function get ($articleid = FALSE) { require_once ("models/model_file.php"); @@ -10,7 +16,8 @@ class blog return $data->get ($articleid); } - /** Return an article in text */ + /** Return an article in text + @param string|integer|null $articleid The article to display */ public function getTxt ($articleid = FALSE) { try @@ -25,7 +32,8 @@ class blog catch (Exception $e) {}; } - /** Return an article in xml */ + /** Return an article in xml + @param string|integer|null $articleid The article to display */ public function getXml ($articleid = FALSE) { try @@ -40,7 +48,8 @@ class blog catch (Exception $e) {}; } - /** Return an article in csv */ + /** Return an article in CSV + @param string|integer|null $articleid The article to display */ public function getCsv ($articleid = FALSE) { try @@ -55,7 +64,8 @@ class blog catch (Exception $e) {}; } - /** Return an article in json */ + /** Return an article in JSON + @param string|integer|null $articleid The article to display */ public function getJson ($articleid = FALSE) { try @@ -70,7 +80,8 @@ class blog catch (Exception $e) {}; } - /** Return an article in HTML */ + /** Return an article in HTML + @param string|integer|null $articleid The article to display */ public function getHtml ($articleid = FALSE) { try diff --git a/examples/blog/index.php b/examples/blog/index.php index d08ca87..685bedd 100644 --- a/examples/blog/index.php +++ b/examples/blog/index.php @@ -1,4 +1,8 @@ */ + require_once ("domframework/route.php"); require_once ("domframework/renderer.php"); $route = new route (); diff --git a/examples/blog/models/model_file.php b/examples/blog/models/model_file.php index 4fcfe36..9a99b10 100644 --- a/examples/blog/models/model_file.php +++ b/examples/blog/models/model_file.php @@ -1,11 +1,16 @@ */ /** Model_file : store the blog datas in files */ class model_file { + /** The path where the blog articles files are stored */ public $dataPath = "datas/"; - /** Return a provided article */ + /** Return a provided article + @param string|integer|null $articleid Teh article to display */ function get ($articleid = FALSE) { $this->dataPath = realpath ($this->dataPath); diff --git a/examples/blog/views/view_blog.php b/examples/blog/views/view_blog.php index 34cc4e0..8ac773e 100644 --- a/examples/blog/views/view_blog.php +++ b/examples/blog/views/view_blog.php @@ -1,11 +1,20 @@ */ + +/** Display the articles of the blog */ class view_blog { + /** Return the datas + @param array $data The list of titles */ function get ($data) { return $data; } + /** Display the list of titles + @param array $data The list of titles */ function listing ($data) { $content = "
    \n"; diff --git a/form.php b/form.php index 4e431e3..84cf9d8 100644 --- a/form.php +++ b/form.php @@ -1,55 +1,70 @@ */ + error_reporting (E_ALL); +/** This class permit to create easily some forms to HTML (or text mode in + future). + Each field can be checked in AJAX or HTML. */ class form { - /** This class permit to create easily some forms to HTML (or text mode in - future). - Each field can be checked in AJAX or HTML. */ + /** All the fields */ private $fields = NULL; + /** The name of the form */ private $formName; + /** Allow to debug the PHP */ public $debug=0; - function __construct ($formName = "form") + /** Create a form + @param string|null $formName The form name + */ + public function __construct ($formName = "form") { $this->formName = $formName; } + /** Save the fields into the structure. + Available : + - name : name of the field in the HTML page + - label : label written to the describe the field + - [titles] : text written in radio/checkboxes + - [defaults] : default values. Must be array for checkbox/select, and + string for others + - [type] : text, password, hidden, checkbox, select, radio, submit + text by default + - [multiple] : Multiple selection are possible (if the type supports it) + - [group] : define a fieldset and define the title with groupe name + Warning : all the elements of the same group must be + consecutive ! + - [readonly] : put a read-only flag on the field (the user see it but + can't interract on it. The value will be sent to next + page + - [verify] : Tests to verify with error priority and associated + message (%s is replaced by field selected value). Order + test from main tests to minor tests. + \$tmpfield can be used as a copy of the current field, + to check the defaults per example + - [error] : array containing (error|warning) => message + + @param array $fields The fields to be displayed + */ public function fields ($fields) { - /** Save the fields into the structure. - Available : - - name : name of the field in the HTML page - - label : label written to the describe the field - - [titles] : text written in radio/checkboxes - - [defaults] : default values. Must be array for checkbox/select, and - string for others - - [type] : text, password, hidden, checkbox, select, radio, submit - text by default - - [multiple] : Multiple selection are possible (if the type supports it) - - [group] : define a fieldset and define the title with groupe name - Warning : all the elements of the same group must be - consecutive ! - - [readonly] : put a read-only flag on the field (the user see it but - can't interract on it. The value will be sent to next - page - - [verify] : Tests to verify with error priority and associated - message (%s is replaced by field selected value). Order - test from main tests to minor tests. - \$tmpfield can be used as a copy of the current field, - to check the defaults per example - - [error] : array containing (error|warning) => message - */ $this->fields = $fields; } + /** Return TRUE if the value associated to a field is correct. Return an + array with a severity and a message to explain why a field is not + correct. + Fields can be an array with just one element, then only this element is + checked + @param array $fieldsVerify The fields to verify + @param array|null $valuesVerify The values of the fields to verify + */ public function verify (&$fieldsVerify, $valuesVerify = NULL) { - /** Return TRUE if the value associated to a field is correct. Return an - array with a severity and a message to explain why a field is not - correct. - Fields can be an array with just one element, then only this element is - checked */ $ret = array (); if ($this->debug) echo "
    ";
    @@ -90,12 +105,15 @@ class form
         return $ret;
       }
     
    +  /** Return the fields in HTML code. If $values is provided, use it in place
    +      of default values. In case of select boxes, $values are the selected
    +      elements
    +      $method is the method written in method field of 
    + @param string|null $method The method to use to transmit the form (POST, + GET) + @param array|null $values The default values of the fields */ public function printHTML ($method = 'post', $values = NULL) { - /** Return the fields in HTML code. If $values is provided, use it in place - of default values. In case of select boxes, $values are the selected - elements - $method is the method written in method field of */ // TODO : textarea, file $res = ""; $res = "name = $name; diff --git a/http.php b/http.php index 26cf896..d7ffe07 100644 --- a/http.php +++ b/http.php @@ -1,4 +1,10 @@ */ + +/** HTTP Helper : understand the best choices provided by browser, the HTTP + codes */ class http { /** Choose the best choice from user choices. @@ -9,7 +15,9 @@ class http If available is empty, then return the best priority defined by user, and throw an exception if nothing is provided for by the user. If nothing match, return $default - */ + @param string $uservar The parameter provided by the user + @param array|null $available The list of available choices in the soft + @param string|null $default The choice if nothing match */ function bestChoice ($uservar, $available=array(), $default=FALSE) { $uservar = str_replace (" ", "", $uservar); @@ -53,7 +61,8 @@ class http return $default; } - /** Return the associated text for a HTTP code */ + /** Return the associated text for a HTTP code + @param integer $code The HTTP code to translate in text */ function codetext ($code) { switch ($code) diff --git a/logger.php b/logger.php index 800025b..1771887 100644 --- a/logger.php +++ b/logger.php @@ -1,4 +1,10 @@ */ + +/** The logger class permit to log the informations from the soft + It allow to debug too */ class logger { /* The logger class can be used with : @@ -10,16 +16,23 @@ class logger $d->logwrite ("Super log DEBUG", $d::DEBUG); $d->logwrite ("Super log NOTICE", $d::NOTICE); */ // TODO : Add SQL support - public $logtype = "display"; // display, file, syslog - // can be merged with a pipe : "display|syslog" + /** The method to log. + Can be display, file, syslog + Can be merged with a pipe : "display|syslog"*/ + public $logtype = "display"; + /** For logtype=file, the filename to use */ public $logfile = FALSE; + /** Timezone use to save the logs */ public $timezone = "UTC"; + /** Minimum log level in the logs */ public $loglevelmin = LOG_NOTICE; - // See http://fr2.php.net/manual/en/function.openlog.php for $syslogFacility + /** In Syslog mode, the facility to use + See http://fr2.php.net/manual/en/function.openlog.php for $syslogFacility */ public $syslogFacility = LOG_USER; + /** In Syslog, prefix the log by the text */ public $syslogPrefix = FALSE; - /* Priorities : + /** The priorities which can be used in the priorities LOG_EMERG system is unusable LOG_ALERT action must be taken immediately LOG_CRIT critical conditions @@ -37,7 +50,9 @@ class logger LOG_INFO => "INFO", LOG_DEBUG => "DEBUG"); - /** Store a new message log in the log manager defined by $logtype */ + /** Store a new message log in the log manager defined by $logtype + @param string $message Message to log + @param integer|null $priority Priority to use */ public function log ($message, $priority=LOG_NOTICE) { if ($this->loglevelmin < $priority) @@ -53,7 +68,9 @@ class logger $this->logsyslog ($message, $priority); } - /** Log $message on file */ + /** Log $message on file + @param string $message Message to log + @param integer|null $priority Priority to use */ private function logfile ($message, $priority) { if ($this->logfile === FALSE) @@ -86,8 +103,9 @@ class logger file_put_contents ($this->logfile, $message, FILE_APPEND); } - /** Log $message on screen with adding date. Add the HTML flags if not in CLI - */ + /** Log $message on screen with adding date. Add the HTML flags if not in CLI. + @param string $message Message to log + @param integer|null $priority Priority to use */ private function logdisplay ($message, $priority) { if (php_sapi_name () !== "cli") @@ -101,7 +119,9 @@ class logger echo "\n"; } - /** Log $message on syslog */ + /** Log $message on syslog + @param string $message Message to log + @param integer|null $priority Priority to use */ private function logsyslog ($message, $priority) { openlog ($this->syslogPrefix, NULL, $this->syslogFacility); diff --git a/output.php b/output.php index d7e2992..e5c0eb6 100644 --- a/output.php +++ b/output.php @@ -1,7 +1,13 @@ */ + /** Class used to display datas */ class output { + /** Class used to display datas + @param mixed $data The data to be displayed */ public function out ($data) { throw new Exception ("No type of output selected"); diff --git a/outputcsv.php b/outputcsv.php index 3b07b90..b632b1e 100644 --- a/outputcsv.php +++ b/outputcsv.php @@ -1,11 +1,23 @@ */ + require_once ("output.php"); +/** Display in CSV the datas provided */ class outputcsv extends output { - public function out ($data) + /** Don't allow to output in CSV if the functions are not available in PHP */ + function __construct () { if (!function_exists ("fputcsv")) throw new Exception ("CSV support not available in PHP !", 500); + } + + /** Display in CSV the datas provided + @param mixed $data The data to be displayed */ + public function out ($data) + { if (!is_array ($data)) $data = array ($data); @header("Cache-Control: no-store, no-cache, must-revalidate"); diff --git a/outputhtml.php b/outputhtml.php index 367f344..7ad3214 100644 --- a/outputhtml.php +++ b/outputhtml.php @@ -1,11 +1,22 @@ */ + require_once ("output.php"); +/** Display in HTML the datas provided, with the layout support */ class outputhtml extends output { /** Data is printed by viewClass->viewmethod, in the middle of $layout title is put in the title of the HTML page $replacement modify the result (it can do title too : - array ("{title}"=>"title to display") */ + array ("{title}"=>"title to display") + @param mixed $data Data to display on the page + @param string|null $title Title to put on head of page + @param string|null $viewClass Class in views to use to display + @param string|null $viewMethod Method in the class in views + @param string|null $layout Layout file in views + @param array|null $replacement Replace the {key}=>value */ public function out ($data, $title = FALSE, $viewClass = FALSE, $viewMethod = FALSE, $layout = FALSE, $replacement = array()) diff --git a/outputjson.php b/outputjson.php index 9c1feb6..754cd83 100644 --- a/outputjson.php +++ b/outputjson.php @@ -1,12 +1,24 @@ */ + require_once ("output.php"); +/** Display in JSOn the datas provided */ class outputjson extends output { - public function out ($data) + /** Don't allow to output in JSON if the functions are not available in PHP */ + function __construct () { if (!function_exists ("json_encode")) throw new Exception ("JSON support not available in PHP ! apt-get ". "install php5-json", 500); + } + + /** Display in JSOn the datas provided + @param mixed $data The data to be displayed */ + public function out ($data) + { @header("Cache-Control: no-store, no-cache, must-revalidate"); @header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); @header('Last-Modified: '.gmdate ('D, d M Y H:i:s').' GMT'); diff --git a/outputtxt.php b/outputtxt.php index 329249a..e0eb2be 100644 --- a/outputtxt.php +++ b/outputtxt.php @@ -1,7 +1,14 @@ */ + require_once ("output.php"); +/** Display in Text the datas provided */ class outputtxt extends output { + /** Display in Text the datas provided + @param mixed $data The data to be displayed */ public function out ($data) { @header("Cache-Control: no-store, no-cache, must-revalidate"); diff --git a/outputxml.php b/outputxml.php index 4c37b35..512b1b7 100644 --- a/outputxml.php +++ b/outputxml.php @@ -1,7 +1,14 @@ */ + require_once ("output.php"); +/** Display in XML the datas provided */ class outputxml extends output { + /** Display in XML the datas provided + @param mixed $data The data to be displayed */ public function out ($data) { @header("Cache-Control: no-store, no-cache, must-revalidate"); @@ -19,7 +26,9 @@ class outputxml extends output print $xml->asXML(); } - // function defination to convert array to xml + /** function defination to convert array to xml + @param mixed $data The data to be converted + @param string $xml The actual state of the XML file */ private function array_to_xml ($data, &$xml) { foreach($data as $key => $value) diff --git a/phpdoc.xml b/phpdoc.xml new file mode 100644 index 0000000..fe0f38f --- /dev/null +++ b/phpdoc.xml @@ -0,0 +1,7 @@ + + + DomFramework : The light framework + + /test/ + + diff --git a/renderer.php b/renderer.php index 9f092b7..faccc7f 100644 --- a/renderer.php +++ b/renderer.php @@ -1,9 +1,17 @@ */ + +/** Display the datas in HTML with a FLASH method to display the errors */ class renderer { + /** The result in construction */ public $result = NULL; + /** The output type */ public $output = NULL; - public $title = " "; // Title by default : space to be compatible with HTML5 + /** Title by default : space to be compatible with HTML5 */ + public $title = " "; /** Filename of class containing the presentation layer */ public $viewClass = FALSE; /** Method apply to class object to display the $result */ @@ -28,8 +36,9 @@ class renderer /** Add a flash message to the user, on the next HTML page. In CLI, display the message immediately. Message must be translated before sending to the function - Priority is 1:success, 2:info, 3:warning, 4:error - or textual : SUCCESS, INFO, WARNING, ERROR */ + @param integer|string $priority Priority 1:success, 2:info, 3:warning, + 4:error or textual : SUCCESS, INFO, WARNING, ERROR + @param string $message Message to display */ static public function flash ($priority, $message) { if (php_sapi_name () === "cli") diff --git a/rest.php b/rest.php index daadc4b..f1a1aeb 100644 --- a/rest.php +++ b/rest.php @@ -1,12 +1,20 @@ */ + require_once ("domframework/http.php"); +/** Allow to manage the REST protocol by using the users output types */ class rest { + /** Allowed types by default */ public $allowedtypes = array ("json", "xml", "txt", "csv"); /** Display the message (which can be a string, an array, an integer...) into the type asked by the client if it is allowed. - By default, the JSON type is used */ + By default, the JSON type is used + @param string $message Message to be displayed by the output type + @param integer $code HTTP code to use */ function display ($message, $code=200) { $http = new http; diff --git a/route.php b/route.php index 6d80447..6e1b811 100644 --- a/route.php +++ b/route.php @@ -1,19 +1,28 @@ */ + error_reporting (E_ALL); +/** The routing module, base of the DomFramework */ class route { + /** The baseURL of the site */ private $baseURL = ""; + /** The baseURL of the module in the site */ private $baseURLmodule = ""; + /** The method used to ask the page */ public $method = ""; + /** The module name */ public $module = NULL; - public $debug=0; // 0:NoDebug, 1:routing, 2:more debug (developpement) + /** The debug mode : + 0:NoDebug, 1:routing, 2:more debug (developpement)*/ + public $debug=0; //public $defaultOutput = "html"; // Default renderer : html - function __construct () - { - } /** Return the baseURL of the site - Always finish with a slash */ + Always finish with a slash + @param string|null $module The module name (if thereis one) */ function baseURL ($module = FALSE) { if ($this->module === NULL) @@ -51,6 +60,8 @@ class route return $this->baseURLmodule; } + /** Define the base URL of the site + @param string $baseURL The base URL of the site */ function baseURLset ($baseURL) { $this->baseURL = $baseURL; @@ -73,7 +84,9 @@ class route /** Do all the routing with redirections $destURL can be absolute or relative If module is set, the site is modular and a directory is named with module - name */ + name + @param string $destURL Do a redirection of the HTTP page + @param string $module The module name */ function redirect ($destURL, $module) { if (php_sapi_name () === "cli") @@ -424,7 +437,9 @@ class route function is called. Ex. : $app->get('/hello/{name}', function ($name) { echo "Hello, $name"; - }); */ + }); + @param string $route Route to check with the URL + @param function $function Function to be executed if the route match */ public function get ($route, $function) { if ($this->debug) @@ -443,7 +458,9 @@ class route function is called. Ex. : $app->get('/hello/{name}', function ($name) { echo "Hello, $name"; - }); */ + }); + @param string $route Route to check with the URL + @param function $function Function to be executed if the route match */ public function post ($route, $function) { if ($this->debug) @@ -462,7 +479,9 @@ class route function is called. Ex. : $app->get('/hello/{name}', function ($name) { echo "Hello, $name"; - }); */ + }); + @param string $route Route to check with the URL + @param function $function Function to be executed if the route match */ public function put ($route, $function) { if ($this->debug) @@ -481,7 +500,9 @@ class route function is called. Ex. : $app->get('/hello/{name}', function ($name) { echo "Hello, $name"; - }); */ + }); + @param string $route Route to check with the URL + @param function $function Function to be executed if the route match */ public function delete ($route, $function) { if ($this->debug) @@ -497,7 +518,9 @@ class route } /** Do the mapping between the url and the route : call the function if - thereis a match */ + thereis a match + @param string $route Route to check with the URL + @param function $function Function to be executed if the route match */ public function map ($route, $function) { $url = substr ($this->requestURL (), strlen ($this->baseURLmodule ()));