I have two classes, an abstraction class and an actual functional class. I need to somehow store the functional class in the abstraction class and make it available to the abstraction class but I am having difficulties..
Heres some code similar to what I am trying to achieve
The abstraction class is the one interfaced with by the code, however this can load several "plugs" that actually handle contacting the authority servers and managing the authority logic, however I am having trouble loading and storing the "plug" objects (as seen in lines 11 and 25 of the abstraction class.
Abstraction Class (auth.class.php):
<?php
class AuthManager {
private $userDatabase;
public function __construct() {
/**
* AuthManager(0): Constructor for the class. Will initiate an
* auth session. Also autoconnects to the user
* service. Defaulting to LDAP
*/
$this ->userDatabase = new LDAPConnector();
}
public function login($user, $pass) {
/**
* login(2): Abstraction function for the user database.
* will check user and password against the
* user database and return the status
*
* @param string $user: Username for the user
* @param string $pass: Password for the user
* @return bool $status: 1 on sucess, 0 on failure
*/
if($user && $pass) {
if($this->userDatabase->login($user, $pass)) {
return 1;
}
} else
return 0;
}
}
}
?>
Functional Class (ldap.plug.php):
<?php
class LDAPConnector extends AuthManager {
private $server = "192.168.0.3";
private $connected = 0;
private $connection = 0;
private $domain = "morris";
public function __construct($host = "192.168.0.3") {
/**
* LDAPConnector(1): Constructor for the class. Will connect to the server
* automatically unless told not to
* @param string $host: IPAddr/Hostname of AD server
* Defaults to private var $server
*/
if($host) {
// Safety net to check we actually have a server to
// connect to
if(function_exists("ldap_connect")) {
if($this->connection = ldap_connect($host)) {
$this->connected = 1;
return 1;
}
}
} else {
return 0;
}
}
public function login($user,$pass, $domain = "") {
/**
* login(2): Attempts to verify user/pass combo with
* the LDAP server
*
* @param string $user: Username to verify
* @param string $pass: Password to verirf
* @return bool : 1 on sucess, 0 on failure
*/
if($user && $pass) {
// Verify we are actually connected to an LDAP server..
if(!$this->connected) {
// We cant possibly run queries on a server that doesnt
// exist.. Exit with a failure.
return 0;
}
if(!$domain) {
// A domain needs to be specified for LDAP users..
// If they havent given us append the default
$user = $this->domain."\\".$user;
} else {
// Prepend the supplied domain..
$user = $domain."\\".$user;
}
// Attempt to bind to the LDAP server. If returns true, the
// uname/pwd combination was a good one.
if(ldap_bind($this->connection, $user, $pass))
return 1;
else
return 0;
} else
return 0;
}
}
?>
These would then be called like so:
<?php
$Auth = new AuthManager();
if($Auth->login("test", "123")) {
echo 'Logged in';
}
?>
However when I try this PHP Spits out
Catchable fatal error: Object of class LDAPConnector could not be converted to string in /var/www/LDAP Experiment/libs/auth.class.php on line 26
Is there a way to do what I am trying or will I have to go back to the drawing board?
Cheers
$connectbeing accessed in your code above.