Skip to content

Commit

Permalink
L5 style config + tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
XavRsl committed May 21, 2015
1 parent 8873ed1 commit 1c82a90
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 157 deletions.
66 changes: 21 additions & 45 deletions src/Xavrsl/Ldap/LdapManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,51 @@
class LdapManager {

/**
* The active connection instances.
* The config Array
*
* @var array
*/
protected $connections = array();
protected $config;

/**
* Get a Ldap connection instance.
* The active connection instances.
*
* @param string $name
* @return Xavrsl\Ldap\Directory
* @var Directory
*/
public function connection($name = null)
{
if ( ! isset($this->connections[$name]))
{
$this->connections[$name] = $this->createConnection($name);
}
protected $connection;

return $this->connections[$name];
}

/**
* Create the given connection by name.
*
* @param string $name
* @return Xavrsl\Ldap\Directory
*/
protected function createConnection($name)
{
$config = $this->getConfig($name);

$connection = new Directory($config, new Connection($config));

return $connection;
}
function __construct(Array $config)
{
$this->config = $config;
}

/**
* Get the configuration for a connection.
* Get a Ldap connection instance.
*
* @param string $name
* @return array
* @return Xavrsl\Ldap\Directory
*/
protected function getConfig($name)
public function connection()
{
$name = $name ?: $this->getDefaultConnection();

// To get the database connection configuration, we will just pull each of the
// connection configurations and get the configurations for the given name.
// If the configuration doesn't exist, we'll throw an exception and bail.
// $connections = $this->app['config']['database.ldap'];
$connections = \Config::get('ldap::'.$name);

if (is_null($connections))
if ( ! isset($this->connection))
{
throw new \InvalidArgumentException("Ldap [$name] not configured.");
$this->connection = $this->createConnection();
}

return $connections;
return $this->connection;
}

/**
* Get the default connection name.
* Create the given connection.
*
* @return string
* @return Xavrsl\Ldap\Directory
*/
protected function getDefaultConnection()
protected function createConnection()
{
return 'default';
$connection = new Directory($this->config, new Connection($this->config));

return $connection;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Xavrsl/Ldap/LdapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class LdapServiceProvider extends ServiceProvider {
*/
public function boot()
{
$this->package('xavrsl/ldap');
$this->publishes([
__DIR__.'/../../config/ldap.php' => config_path('ldap.php'),
]);
}

/**
Expand All @@ -28,10 +30,10 @@ public function boot()
*/
public function register()
{
//
$this->app['ldap'] = $this->app->share(function()
{
return new LdapManager();
$config = $this->app['config']->get('ldap');
return new LdapManager($config);
});
}

Expand All @@ -45,4 +47,4 @@ public function provides()
return array('ldap');
}

}
}
214 changes: 106 additions & 108 deletions src/config/ldap.php
Original file line number Diff line number Diff line change
@@ -1,111 +1,109 @@
<?php

return array(
'default' => array(

/*
|--------------------------------------------------------------------------
| LDAP Server
|--------------------------------------------------------------------------
|
| Address of the LDAP Server
|
| Example: 'cas.myuniv.edu'.
|
*/

'server' => 'ldap.domain.fr',

/*
|--------------------------------------------------------------------------
| LDAP Port (389 is default)
|--------------------------------------------------------------------------
*/

'port' => '389',

/*
|--------------------------------------------------------------------------
| LDAP Base DN
|--------------------------------------------------------------------------
*/

'basedn' => 'dc=domain,dc=fr',

/*
|--------------------------------------------------------------------------
| Managed Organisation Units (OU)
| Only people works for now
|--------------------------------------------------------------------------
*/

'organisationUnits' => ['people', 'groups'],

/*
|--------------------------------------------------------------------------
| LDAP ADMIN bind DN
|--------------------------------------------------------------------------
*/

'binddn' => 'cn=Manager,dc=domain,dc=fr',

/*
|--------------------------------------------------------------------------
| LDAP ADMIN bind password
|--------------------------------------------------------------------------
|
*/
'bindpwd' => 'password',

/*
|--------------------------------------------------------------------------
| Cache time-to-live value in minutes.
| How long should we cache result if found
|--------------------------------------------------------------------------
*/

'cachettl' => 20,

/*
|--------------------------------------------------------------------------
| Caching & Results array key.
| This is typically a unique attribute from the directory OU
|--------------------------------------------------------------------------
*/

'key' => 'dn',

/*
|--------------------------------------------------------------------------
| Default filter attribute
| Will be used when calling short method like :
| Ldap::people('xavrsl')->displayname;
|--------------------------------------------------------------------------
*/

'filter' => 'login',

/*
|--------------------------------------------------------------------------
| User dn used for user authentication.
| This is the distinguished name of a user that will authenticate to
| the directory using a BIND. Typically named 'dn'
|--------------------------------------------------------------------------
*/

'userdn' => 'dn',

'searchscope' => 'SUBTREE_SCOPE',

'attributes' => array(
'uid',
'displayName',
'sn',
'givenName',
'mail',
'edupersonAffiliation',
'supannAffectation',
'login',
),
),
);

/*
|--------------------------------------------------------------------------
| LDAP Server
|--------------------------------------------------------------------------
|
| Address of the LDAP Server
|
| Example: 'cas.myuniv.edu'.
|
*/

'server' => env('LDAP_HOST'),

/*
|--------------------------------------------------------------------------
| LDAP Port (389 is default)
|--------------------------------------------------------------------------
*/

'port' => env('LDAP_PORT', '389'),

/*
|--------------------------------------------------------------------------
| LDAP Base DN
|--------------------------------------------------------------------------
*/

'basedn' => env('LDAP_BASE_DN'),

/*
|--------------------------------------------------------------------------
| Managed Organisation Units (OU)
| Only people works for now
|--------------------------------------------------------------------------
*/

'organisationUnits' => ['people', 'groups'],

/*
|--------------------------------------------------------------------------
| LDAP ADMIN bind DN
|--------------------------------------------------------------------------
*/

'binddn' => env('LDAP_BIND_DN', 'cn=Manager,dc=domain,dc=fr'),

/*
|--------------------------------------------------------------------------
| LDAP ADMIN bind password
|--------------------------------------------------------------------------
|
*/
'bindpwd' => env('LDAP_BIND_PASSWORD'),

/*
|--------------------------------------------------------------------------
| Cache time-to-live value in minutes.
| How long should we cache result if found
|--------------------------------------------------------------------------
*/

'cachettl' => 20,

/*
|--------------------------------------------------------------------------
| Caching & Results array key.
| This is typically a unique attribute from the directory OU
|--------------------------------------------------------------------------
*/

'key' => 'dn',

/*
|--------------------------------------------------------------------------
| Default filter attribute
| Will be used when calling short method like :
| Ldap::people('xavrsl')->displayname;
|--------------------------------------------------------------------------
*/

'filter' => 'login',

/*
|--------------------------------------------------------------------------
| User dn used for user authentication.
| This is the distinguished name of a user that will authenticate to
| the directory using a BIND. Typically named 'dn'
|--------------------------------------------------------------------------
*/

'userdn' => 'dn',

'searchscope' => 'SUBTREE_SCOPE',

'attributes' => array(
'uid',
'displayName',
'sn',
'givenName',
'mail',
'edupersonAffiliation',
'supannAffectation',
'login',
)
);

0 comments on commit 1c82a90

Please sign in to comment.