Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring class object within class variable
    primarykey
    data
    text
    <p>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..</p> <p>Heres some code similar to what I am trying to achieve</p> <p>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.</p> <p>Abstraction Class (auth.class.php):</p> <pre><code>&lt;?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 -&gt;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 &amp;&amp; $pass) { if($this-&gt;userDatabase-&gt;login($user, $pass)) { return 1; } } else return 0; } } } ?&gt; </code></pre> <p>Functional Class (ldap.plug.php):</p> <pre><code>&lt;?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-&gt;connection = ldap_connect($host)) { $this-&gt;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 &amp;&amp; $pass) { // Verify we are actually connected to an LDAP server.. if(!$this-&gt;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-&gt;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-&gt;connection, $user, $pass)) return 1; else return 0; } else return 0; } } ?&gt; </code></pre> <p>These would then be called like so:</p> <pre><code>&lt;?php $Auth = new AuthManager(); if($Auth-&gt;login("test", "123")) { echo 'Logged in'; } ?&gt; </code></pre> <p>However when I try this PHP Spits out</p> <pre><code>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 </code></pre> <p>Is there a way to do what I am trying or will I have to go back to the drawing board?</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload