Add NAMESPACE support (not activated, but just needed to add the namespace on top of file)
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4630 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
7
auth.php
7
auth.php
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/** DomFramework
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/** DomFramework
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
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)
|
||||
|
||||
27
authldap.php
27
authldap.php
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/** DomFramework
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
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)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/** DomFramework
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
/** Takes the email and the password of the user */
|
||||
class authparams
|
||||
|
||||
2
http.php
2
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)
|
||||
|
||||
10
lockfile.php
10
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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -27,11 +27,10 @@ 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,
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user