http : presentation of code

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5801 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-12-06 14:18:31 +00:00
parent 2c767e7f06
commit 92ba3bb1c3

View File

@@ -1,24 +1,28 @@
<?php <?php
/** DomFramework /** DomFramework
@package domframework * @package domframework
@author Dominique Fournier <dominique@fournier38.fr> */ * @author Dominique Fournier <dominique@fournier38.fr>
*/
/** HTTP Helper : understand the best choices provided by browser, the HTTP /** HTTP Helper : understand the best choices provided by browser, the HTTP
codes */ * codes
*/
class http class http
{ {
/** Choose the best choice from user choices. /** Choose the best choice from user choices.
Can be used for languages (HTTP_ACCEPT_LANGUAGE), type of pages * Can be used for languages (HTTP_ACCEPT_LANGUAGE), type of pages
(HTTP_ACCEPT)... * (HTTP_ACCEPT)...
Ex. fr, en-gb;q=0.8, en;q=0.7 * Ex. fr, en-gb;q=0.8, en;q=0.7
Ex. text/html,application/xhtml+xml,application/xml;q=0.9,* /*;q=0.8 * Ex. text/html,application/xhtml+xml,application/xml;q=0.9,* /*;q=0.8
If available is empty, then return the best priority defined by user, * If available is empty, then return the best priority defined by user,
and throw an exception if nothing is provided for by the user. * and throw an exception if nothing is provided for by the user.
If nothing match, return $default * If nothing match, return $default
@param string $uservar The parameter provided by the user * @param string $uservar The parameter provided by the user
@param array|null $available The list of available choices in the soft * @param array|null $available The list of available choices in the soft
@param string|null $default The choice if nothing match */ * @param string|null $default The choice if nothing match
*/
function bestChoice ($uservar, $available=array(), $default=FALSE) function bestChoice ($uservar, $available=array(), $default=FALSE)
// {{{
{ {
$uservar = str_replace (" ", "", $uservar); $uservar = str_replace (" ", "", $uservar);
$userchoices = explode (",", $uservar); $userchoices = explode (",", $uservar);
@@ -60,10 +64,13 @@ class http
// No best solution found. Use the default available solution // No best solution found. Use the default available solution
return $default; 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 */ * @param integer $code The HTTP code to translate in text
*/
function codetext ($code) function codetext ($code)
// {{{
{ {
switch ($code) switch ($code)
{ {
@@ -108,7 +115,7 @@ class http
default: default:
exit('Unknown http status code "'.htmlentities ($code).'"'); exit('Unknown http status code "'.htmlentities ($code).'"');
} }
return $text; return $text;
} }
// }}}
} }