117 lines
2.9 KiB
PHP
117 lines
2.9 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class takes care of communicating with LDAP
|
|
*
|
|
* @package Kohana/Database
|
|
* @author Deon George
|
|
* @copyright (c) 2013 phpLDAPadmin Development Team
|
|
* @license http://dev.phpldapadmin.org/license.html
|
|
*/
|
|
abstract class Kohana_LDAP extends Database {
|
|
/** LDAP **/
|
|
|
|
/**
|
|
* @var boolean Whether we are fully connected (connection and bound)
|
|
*/
|
|
protected $_connected = FALSE;
|
|
|
|
/**
|
|
* @var Our LDAP OBJECT that holds the schema
|
|
*/
|
|
protected $_schema = NULL;
|
|
|
|
/**
|
|
* @var string Our default usage when connection
|
|
*/
|
|
public static $usage = 'default';
|
|
|
|
/**
|
|
* Identifiy if caching is enabled for this LDAP connection
|
|
*
|
|
* @return boolean TRUE|FALSE
|
|
*/
|
|
public function caching() {
|
|
return $this->_config['caching'];
|
|
}
|
|
|
|
/**
|
|
* Have we got a bound connection to the LDAP server
|
|
*
|
|
* @return boolean TRUE|FALSE
|
|
*/
|
|
public function connected() {
|
|
return ($this->_connection AND $this->_connected);
|
|
}
|
|
|
|
/**
|
|
* Return the connection resource
|
|
*
|
|
* @return resource LDAP Resource Identifier
|
|
*/
|
|
public function connection() {
|
|
return $this->_connection;
|
|
}
|
|
|
|
/**
|
|
* A wrapper for parent::instance(), so that we can create multiple connections
|
|
* to the same LDAP server with different credentials/purposes.
|
|
*
|
|
* Get a singleton Database instance. If configuration is not specified,
|
|
* it will be loaded from the database configuration file using the same
|
|
* group as the name.
|
|
*
|
|
* // Load the default database
|
|
* $db = LDAP::factory();
|
|
*
|
|
* // Create a custom configured instance
|
|
* $db = LDAP:factory('auth','custom', $config);
|
|
*
|
|
* @param string A free form usage name, for this connection
|
|
* @param string A database configuration name, as per parent::instance()
|
|
* @param array An alternative database configuration to use for $name.
|
|
* @see Database::instance();
|
|
* @return LDAP::instance();
|
|
*
|
|
* @note We cant call this instance() like our parent, because of the additional parameter
|
|
* we need.
|
|
*/
|
|
public static function factory($usage=NULL,$name=NULL,array $config=NULL) {
|
|
// Use the default instance name
|
|
if ($usage === NULL)
|
|
$usage = LDAP::$usage;
|
|
|
|
if (! isset(Database::$instances[$usage])) {
|
|
// Use the default instance name
|
|
if ($name === NULL)
|
|
$name = Database::$default;
|
|
|
|
// Load the configuration for this database
|
|
if ($config === NULL)
|
|
$config = Kohana::$config->load('database')->$name;
|
|
}
|
|
|
|
return parent::instance($usage,$config);
|
|
}
|
|
|
|
/**
|
|
* @defunct This static function is defunct, you need to use factory() instead.
|
|
* @see LDAP::factory();
|
|
*/
|
|
public static function instance($name=NULL,array $config=NULL) {
|
|
throw Kohana_Exception('Sorry, you cant use instance(), you need to use factory()');
|
|
}
|
|
|
|
public function setSchema(Model_LDAP_Schema $orm) {
|
|
$this->_schema = $orm;
|
|
}
|
|
|
|
public function schema() {
|
|
if (is_null($this->_schema))
|
|
$this->getSchema();
|
|
|
|
return $this->_schema;
|
|
}
|
|
}
|
|
?>
|