Auth, patch to use existing DB object

From: Date: Sat, 23 Aug 2003 20:27:31 +0000
Subject: Auth, patch to use existing DB object
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-20443@lists.php.net to get a copy of this message
Hello, about the Auth package, stable version 1.2.2 (dont know how to access cvs so maybe its allready done by somebody else) i saw that it was possible to pass an existing container, but not possible to pass an existing DB object... this little patch allows you to pass an existing DB object, so that the (freshly made) container uses it (in stead of having to give a dsn and create a new DB object) It does this through the 'options' paramter (mixed) of Auth::Auth (whithout changing its code) An example on how to use this would be: require_once('DB.php'); $dsn = "mysql://foo:bar@example.org/auth" $db = DB::connect($dsn); unset($dsn); //other stuff require_once("Auth/Auth.php"); $auOpt = array(
           "DB" => &$db,
           "table" => "users",
           "usernamecol" => "nick",
           "passwordcol" => "pass",
           );
$au = new Auth("DB", $auOpt, "", true); the options keyword here is 'DB' but that can be easely changed this is the patch, Container/DB.php --- DB_orig.php 2003-08-23 21:54:23.000000000 +0200
+++ DB.php      2003-08-23 21:56:47.000000000 +0200
@@ -191,7 +191,9 @@
    function _parseOptions($array)
    {
        foreach ($array as $key => $value) {
-            if (isset($this->options[$key])) {
+            if (($key == "DB") && (is_object($value)) && (DB::isConnection($value)) {
+                $this->db = $value;
+            } elseif (isset($this->options[$key])) {
                $this->options[$key] = $value;
            }
        }


« previous php.pear.dev (#20443) next »