|
Posted by intrupt000@gmail.com on 07/25/06 12:28
hi list,
i'm trying to lose some bad programming habits and write neat
and re-useable oo php5 code. At the moment i'm trying to write
a highly abstracted interface to ldap (just for fun) and I am not
sure if the way i'm proceeding is indeed the correct and sane way.
the way i see it, to accomplish the level of abstraction that i want,
i'll need objects like the following :
phpLdap(superclass), phpldapConnection, phpldapRecord, etc etc
<psuedo-ish code>
class phpLDAP { // a superclass ???
private $conn = NULL;
public $search;
function __construct ($someparms) {
// hand it of to a different class
$this->conn = new phpLDAPConnection($someparms);
}
function search($someparms) {
// hand this of to another class
$this->search = new phpLDAPSearchObject($someparms);
}
}
class phpLDAPConnection {
public $conn = NULL;
function __construct($someparms) {
// do ldap connection stuff
}
/** more stuff **/
function __destruct() { }
}
class phpLDAPSearchObject {
private $rawResult = NULL;
public $records = NULL;
function __construct($someparms) {
// search stuff
foreach($result as $searchResults) {
$this->records[z++] = new phpLDAPRecord($result);
}
}
}
</psuedo-ish code>
okay, above is a small piece of code example showing how i'm
connecting objects together.
the end result of all this should be being able to do something
like this :
<ldap-app.php>
$ldap = new phpLDAP($someparms);
if ($ldap->conn->Connected) { // property of phpLdapConnection
$ldap->search($someparms); // do a search
$search = &$ldap->search;
do {
// returns for ex: a phpLDAPRecord
$curRec = &$search->ActiveRecord;
// a method of a phpLDAPRecord
$curRec->count("DN");
// a property of a phpLDAPSearch
echo $search->count;
// a method of a phpLDAPSearch
echo $search->refresh();
// method of phpLDAPSearch
$search->next;
} while (!($search->BOF));
// etc etc
} // endif
</ldap-app.php>
I hope that what i'm trying to do is clear. I would like to now if
this is the correct way to do abstraction or if i'm missing the
plot completely.
thanks,
cillier
Navigation:
[Reply to this message]
|