This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnldap/classes/Kohana/LDAP.php

117 lines
2.9 KiB
PHP
Raw Normal View History

2013-07-12 00:35:54 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class takes care of communicating with LDAP
*
2014-02-11 00:26:11 +00:00
* @package Kohana/Database
2013-07-12 00:35:54 +00:00
* @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;
2014-02-11 05:53:37 +00:00
/**
* @var Our LDAP OBJECT that holds the schema
*/
protected $_schema = NULL;
2013-07-12 00:35:54 +00:00
/**
* @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()');
}
2014-02-11 05:53:37 +00:00
public function setSchema(Model_LDAP_Schema $orm) {
$this->_schema = $orm;
}
public function schema() {
2014-02-13 05:07:03 +00:00
if (is_null($this->_schema))
$this->getSchema();
2014-02-11 05:53:37 +00:00
return $this->_schema;
}
2013-07-12 00:35:54 +00:00
}
?>