抽象クラスと実際の機能クラスの2つのクラスがあります。私は何とか抽象クラスで機能クラスを格納し、抽象クラスが利用できるようにする必要がありますが、私はHERESに困難..クラスオブジェクト内にクラスオブジェクトを格納する
を持っています、私は
抽象クラスを達成しようとしています何に似ていくつかのコードがあります実際には権限サーバとの通信や権限ロジックの管理を行ういくつかの「プラグ」をロードすることができますが、11行目と25行目に示されているように、「プラグ」オブジェクトのロードと格納に問題があります。
抽象クラス(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;
}
}
}
?>
機能分類(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;
}
}
?>
はこれらのそのようにのように呼ばれます:私がしようとすると、
<?php
$Auth = new AuthManager();
if($Auth->login("test", "123")) {
echo 'Logged in';
}
?>
しかし、このPHPが
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
を吐き出します
私は何をしようとしているのでしょうか、あるいは私はドローイングボードに戻る必要がありますか?
乾杯auth.class.phpで
25行とは何ですか?上のコードでは '$ connect'という変数にアクセスすることはできません。 –
これは私を混乱させるものです。エラーは、行によって吐き出されています $ this-> connection-> connect()私の知る限りでは、変数ではなく関数呼び出しです –