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:
37
http.php
37
http.php
@@ -1,24 +1,28 @@
|
||||
<?php
|
||||
/** DomFramework
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
/** HTTP Helper : understand the best choices provided by browser, the HTTP
|
||||
codes */
|
||||
* codes
|
||||
*/
|
||||
class http
|
||||
{
|
||||
/** Choose the best choice from user choices.
|
||||
Can be used for languages (HTTP_ACCEPT_LANGUAGE), type of pages
|
||||
(HTTP_ACCEPT)...
|
||||
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
|
||||
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 */
|
||||
* Can be used for languages (HTTP_ACCEPT_LANGUAGE), type of pages
|
||||
* (HTTP_ACCEPT)...
|
||||
* 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
|
||||
* 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);
|
||||
$userchoices = explode (",", $uservar);
|
||||
@@ -60,10 +64,13 @@ class http
|
||||
// No best solution found. Use the default available solution
|
||||
return $default;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** 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)
|
||||
// {{{
|
||||
{
|
||||
switch ($code)
|
||||
{
|
||||
@@ -108,7 +115,7 @@ class http
|
||||
default:
|
||||
exit('Unknown http status code "'.htmlentities ($code).'"');
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user