diff --git a/auth.php b/auth.php index 5e1bca5..b8ecaaf 100644 --- a/auth.php +++ b/auth.php @@ -1,7 +1,8 @@ */ + * @package domframework + * @author Dominique Fournier + */ /** User authentication (abstract class) */ class auth @@ -143,7 +144,7 @@ class auth */ public function connect () { - throw new Exception (dgettext("domframework", + throw new \Exception (dgettext("domframework", "No connect to authentication available"), 405); } diff --git a/authentication.php b/authentication.php index 97a4d41..d2fb2bb 100644 --- a/authentication.php +++ b/authentication.php @@ -1,7 +1,8 @@ */ + * @package domframework + * @author Dominique Fournier + */ require_once ("domframework/auth.php"); require_once ("domframework/authparams.php"); @@ -116,8 +117,8 @@ class authentication // If the user is already connected, redirect to the main page of the site if (session_id () === "") session_start (); - $auth = new \auth (); - $pre = new \authparams (array ("session")); + $auth = new auth (); + $pre = new authparams (array ("session")); if (isset ($_SESSION["domframework"]["authentication"]["message"])) $message = $_SESSION["domframework"]["authentication"]["message"]; else @@ -168,7 +169,7 @@ class authentication $this->route->redirect ("/authentication/$url", ""); } } - $authparams = new \authparams (array ("post")); + $authparams = new authparams (array ("post")); $res = $this->verifAuth ($authparams->email, $authparams->password); if (! is_array ($res)) { @@ -217,7 +218,7 @@ class authentication if ($this->debug) echo "=== entering verifAuthREST (restMethods=". print_r ($this->restMethods, true).")\n"; - $authparams = new \authparams ($this->restMethods); + $authparams = new authparams ($this->restMethods); $res = array ("email"=>"anonymous", "password"=>"anonymous"); if ($authparams->email !== "anonymous" && $authparams->password !== "anonymous") @@ -245,7 +246,7 @@ class authentication if ($this->debug) echo "=== entering verifAuthHTML (htmlMethods=". print_r ($this->htmlMethods, true).")\n"; - $authparams = new \authparams ($this->htmlMethods); + $authparams = new authparams ($this->htmlMethods); // Don't ask to the provider if anonymous is known if ($authparams->email === "anonymous" || $authparams->email === null) { @@ -328,7 +329,8 @@ class authentication if (! is_array ($serversParam)) throw new \Exception ("Auth Server $key configuration error : ". "not an array", 500); - $authmethod = new $classname (); + $class = __NAMESPACE__."\\$classname"; + $authmethod = new $class (); foreach ($serversParam as $param=>$value) { if ($this->debug) diff --git a/authldap.php b/authldap.php index 14bea25..507b80d 100644 --- a/authldap.php +++ b/authldap.php @@ -1,7 +1,8 @@ */ + * @package domframework + * @author Dominique Fournier + */ require_once ("domframework/auth.php"); @@ -36,7 +37,7 @@ class authldap extends auth function __construct () { if (!function_exists ("ldap_connect")) - throw new Exception ("LDAP support unavailable in PHP", 500); + throw new \Exception ("LDAP support unavailable in PHP", 500); } /** Establish a connection to a LDAP server @@ -46,13 +47,13 @@ class authldap extends auth { $this->ldapconn = ldap_connect ($this->ldapserver, $this->ldapport); if (!$this->ldapconn) - throw new Exception ("Can't contact LDAP server", 500); + throw new \Exception ("Can't contact LDAP server", 500); ldap_set_option ($this->ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($this->ldapconn, LDAP_OPT_TIMELIMIT, $this->ldaptimeout); $ldapbind = @ldap_bind ($this->ldapconn, $this->ldapauth, $this->ldappwd); if (ldap_errno ($this->ldapconn) !== 0) - throw new Exception ("Authentication error in pre-auth LDAP", 500); + throw new \Exception ("Authentication error in pre-auth LDAP", 500); } /** Try to authenticate the email/password of the user @@ -64,15 +65,15 @@ class authldap extends auth $search = ldap_search ($this->ldapconn, $this->ldapbase, $filter, array ($this->ldapfield)); if ($search === FALSE) - throw new Exception ("Unable to search in LDAP", 500); + throw new \Exception ("Unable to search in LDAP", 500); $info = ldap_get_entries ($this->ldapconn, $search); if (!isset ($info["count"]) || $info["count"] !== 1 || !isset ($info[0]) || !isset ($info[0]["dn"])) - throw new Exception ("Unable to find the user : '$email'", 401); + throw new \Exception ("Unable to find the user : '$email'", 401); $dn = $info[0]["dn"]; $ldapbind2 = @ldap_bind ($this->ldapconn, $dn, $password); if ($ldapbind2 !== TRUE) - throw new Exception ("Bad password for '$email'", 401); + throw new \Exception ("Bad password for '$email'", 401); $this->ldapdnuser = $dn; } @@ -80,11 +81,11 @@ class authldap extends auth public function getdetails () { if ($this->ldapdnuser === NULL) - throw new Exception ("No user authenticated !", 401); + throw new \Exception ("No user authenticated !", 401); $search = ldap_search ($this->ldapconn, $this->ldapdnuser, $this->ldapfiltersearch); if ($search === FALSE) - throw new Exception ("Can not found the details for user", 401); + throw new \Exception ("Can not found the details for user", 401); $data = ldap_get_entries ($this->ldapconn, $search); $res = array (); if (isset ($data[0])) @@ -103,7 +104,7 @@ class authldap extends auth @param string $newpassword The new password to be recorded */ public function changepassword ($oldpassword, $newpassword) { - throw new Exception (dgettext("domframework", + throw new \Exception (dgettext("domframework", "The password can't be change for LDAP users"), 405); } @@ -124,12 +125,12 @@ class authldap extends auth public function listusers () { if ($this->ldapconn === NULL) - throw new Exception ("No established LDAP connection", 500); + throw new \Exception ("No established LDAP connection", 500); $search = ldap_search ($this->ldapconn,$this->ldapbase, $this->ldapfiltersearch, array ("mail","sn","givenname")); if ($search === FALSE) - throw new Exception ("Unable to search the users in LDAP", 500); + throw new \Exception ("Unable to search the users in LDAP", 500); $info = ldap_get_entries ($this->ldapconn, $search); $data = array (); foreach ($info as $key=>$vals) diff --git a/authparams.php b/authparams.php index 108cb2f..e6695d3 100644 --- a/authparams.php +++ b/authparams.php @@ -1,7 +1,8 @@ */ + * @package domframework + * @author Dominique Fournier + */ /** Takes the email and the password of the user */ class authparams diff --git a/http.php b/http.php index 7293aad..2c1096f 100644 --- a/http.php +++ b/http.php @@ -25,7 +25,7 @@ class http if (!isset ($userchoices[0])) { if ($default === FALSE) - throw new Exception ("No user choice provided to bestChoice", 500); + throw new \Exception ("No user choice provided to bestChoice", 500); return $default; } // Remove weights (provided by the order of the user) diff --git a/lockfile.php b/lockfile.php index f58e83d..fce51ce 100644 --- a/lockfile.php +++ b/lockfile.php @@ -18,7 +18,7 @@ class lockfile if (!is_dir (dirname ($this->storagelock))) @mkdir (dirname ($this->storagelock)); if (!is_dir (dirname ($this->storagelock))) - throw new Exception ("Can't create '".dirname ($this->storagelock). + throw new \Exception ("Can't create '".dirname ($this->storagelock). "' directory for lockfile", 500); $lockid = uniqid() . '_' . md5 (mt_rand()); @@ -39,7 +39,7 @@ class lockfile usleep (100000); clearstatcache (TRUE, $this->storagelock); if (microtime (TRUE) > $startTime + 10) - throw new Exception ("Can't have the authorization lock RW in 10s", + throw new \Exception ("Can't have the authorization lock RW in 10s", 500); } @@ -56,7 +56,7 @@ class lockfile { usleep (100000); if (microtime (TRUE) > $startTime + 10) - throw new Exception ("Can't have the authorization lock RO in 10s", + throw new \Exception ("Can't have the authorization lock RO in 10s", 500); } @@ -71,7 +71,7 @@ class lockfile if (!is_dir (dirname ($this->storagelock))) @mkdir (dirname ($this->storagelock)); if (!is_dir (dirname ($this->storagelock))) - throw new Exception ("Can't create '".dirname ($this->storagelock)."'", + throw new \Exception ("Can't create '".dirname ($this->storagelock)."'", 500); $lockid = uniqid() . '_' . md5 (mt_rand()); // Stale lock : 60s old min @@ -89,7 +89,7 @@ class lockfile usleep (100000); clearstatcache (TRUE, $this->storagelock); if (microtime (TRUE) > $startTime + 10) - throw new Exception ("Can't have the authorization lock in 10s", 500); + throw new \Exception ("Can't have the authorization lock in 10s", 500); } touch ($this->storagelock."-".$lockid); diff --git a/output.php b/output.php index ee7f25e..0d725ec 100644 --- a/output.php +++ b/output.php @@ -10,6 +10,6 @@ class output @param mixed $data The data to be displayed */ public function out ($data) { - throw new Exception ("No type of output selected"); + throw new \Exception ("No type of output selected"); } } diff --git a/outputhtml.php b/outputhtml.php index 2602322..9e08249 100644 --- a/outputhtml.php +++ b/outputhtml.php @@ -53,7 +53,7 @@ class outputhtml extends output if (isset ($resView["title"])) $title = $resView["title"]; if (! isset ($resView["content"])) - throw new Exception (sprintf ( + throw new \Exception (sprintf ( dgettext("domframework", "No data provided from view %s::%s"), $viewClass,$viewMethod), diff --git a/outputjson.php b/outputjson.php index 458bb6c..8f5141d 100644 --- a/outputjson.php +++ b/outputjson.php @@ -13,7 +13,7 @@ class outputjson extends output function __construct () { if (!function_exists ("json_encode")) - throw new Exception ("JSON support not available in PHP ! apt-get ". + throw new \Exception ("JSON support not available in PHP ! apt-get ". "install php5-json", 500); } diff --git a/outputrest.php b/outputrest.php index a980fd4..db7c60f 100644 --- a/outputrest.php +++ b/outputrest.php @@ -32,7 +32,7 @@ class outputrest extends output { if (! isset ($variable["exceptionCode"])) $variable["exceptionCode"] = 200; - $rest = new \rest (); + $rest = new rest (); $rest->display ($data, $variable["exceptionCode"]); } } diff --git a/ratelimitfile.php b/ratelimitfile.php index 6469c29..f8469bc 100644 --- a/ratelimitfile.php +++ b/ratelimitfile.php @@ -108,22 +108,22 @@ class ratelimitfile extends ratelimit if (file_exists ($this->storageDir)) { if (! is_dir ($this->storageDir)) - throw new Exception (sprintf (dgettext ("domframework", + throw new \Exception (sprintf (dgettext ("domframework", "storageDir '%s' is not a directory"), $this->storageDir), 500); if (! is_readable ($this->storageDir)) - throw new Exception (sprintf (dgettext ("domframework", + throw new \Exception (sprintf (dgettext ("domframework", "storageDir '%s' is not readable"), $this->storageDir), 500); if (! is_writeable ($this->storageDir)) - throw new Exception (sprintf (dgettext ("domframework", + throw new \Exception (sprintf (dgettext ("domframework", "storageDir '%s' is not writeable"), $this->storageDir), 500); } else { if (@mkdir ($this->storageDir, 0777, true) === false) - throw new Exception (sprintf (dgettext ("domframework", + throw new \Exception (sprintf (dgettext ("domframework", "Can't create '%s' storageDir"), $this->storageDir), 500); } diff --git a/renderer.php b/renderer.php index 0468866..95f7b85 100644 --- a/renderer.php +++ b/renderer.php @@ -27,14 +27,13 @@ class renderer $this->output */ public function run () { - if (!@require_once ("domframework/output$this->output.php")) - throw new \Exception ("Renderer '$this->output' not found", 500); - $class = "output$this->output"; - $reflection = new \ReflectionMethod ($class, "out"); - $res = $reflection->invokeArgs (new $class, - array ($this->result, $this->title, - $this->viewClass, $this->viewMethod, $this->layout, - $this->replacement, $this->variable)); + require_once ("domframework/outputhtml.php"); + $class = __NAMESPACE__."\\output$this->output"; + $obj = new $class (); + $res = call_user_func_array (array ($obj, "out"), + array ($this->result, $this->title, + $this->viewClass, $this->viewMethod, $this->layout, + $this->replacement, $this->variable)); echo $res; } diff --git a/rest.php b/rest.php index 8b1aeb8..cb172f3 100644 --- a/rest.php +++ b/rest.php @@ -28,7 +28,7 @@ class rest } require_once ("domframework/output$type.php"); - $constr = "output$type"; + $constr = __NAMESPACE__."\\output$type"; $method = "out"; $obj = new $constr (); $obj->$method ($message);