create env access classes
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Wed, 15 Dec 2004 13:37:19 +0000 (13:37 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:26:41 +0000 (23:26 +0200)
commitcfe9921aa1568cb3ba82364b9014cedbf37c13f6
tree50f9475b7c5fdbcad5fb7f3cfcd479c82fda179d
parentea73cc02702d6b5a4f687283f2c76be2d44ebe1b
create env access classes

there is now Env::, Session::, Get::, Post::, Cookie:: classes.
the duplication of code is awful, but is a result of the deficient PHP4 OO design.
it would be a lot better in php5 where 'self' is defined as the current class.

moreover, I used thoses classes in 3 pages for a proof of concept.  code become much much clearer !
So i'll go through the entire site and remove direct accesses to POST/GET/REQUESTS/SESSION/COOKIE

note that PHP is not able to parse Session::get('log')->log(foo)

so for thoses exceptions, you have to do instead :

if (Session::has('log')) {
    $_SESSION->log(foo);
}

which IMHO remains more readable than

if (isset($_SESSION['log'])) {
    $_SESSION->log(foo);
}

purists would even use :
if ($logger = Session::getMixed('log')) {
    $logger->log(foo);
}

or some other form that does not use $_SESSION explicitely

PS: maybe I should create a :
    WIBBLE::callIfExists('log', Array('func', 'arg1', 'arg2', ...))
    but I find that horrible to read.  that's why I did'nt implemented it

git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-94
14 files changed:
htdocs/TESTS/xorg_env.php [new file with mode: 0644]
htdocs/acces_smtp.php
htdocs/alias.php
htdocs/deconnexion.php
htdocs/emails/send.php
htdocs/exit.php
htdocs/getphoto.php
htdocs/index.php
htdocs/newsletter/show.php
include/xorg.inc.php
include/xorg/env.inc.php [new file with mode: 0644]
plugins/modifier.stripslashes.php [new file with mode: 0644]
templates/emails/send.tpl
templates/include/form.valid.aliases.tpl