Skip to content

Commit 8bb9eb6

Browse files
committed
Added ability to determine if the connection is present on the instance
1 parent e103300 commit 8bb9eb6

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/Connection.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ public function __construct($configuration = [], LdapInterface $ldap = null)
4242
*/
4343
public function __destruct()
4444
{
45-
if (
46-
$this->ldap instanceof LdapInterface &&
47-
$this->ldap->isBound()
48-
) {
45+
if ($this->ldap->isBound()) {
4946
$this->ldap->close();
5047
}
5148
}
@@ -155,6 +152,14 @@ public function connect($username = null, $password = null)
155152
return $this;
156153
}
157154

155+
/**
156+
* {@inheritDoc}
157+
*/
158+
public function isConnected()
159+
{
160+
return $this->ldap->isBound();
161+
}
162+
158163
/**
159164
* Prepares the connection by setting configured parameters.
160165
*

src/ConnectionInterface.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ interface ConnectionInterface
1616
public function __construct($configuration, LdapInterface $ldap = null);
1717

1818
/**
19-
* Returns the current connection instance.
19+
* Get the LDAP connection instance.
2020
*
2121
* @return LdapInterface
2222
*/
2323
public function getLdapConnection();
2424

2525
/**
26-
* Returns the current configuration instance.
26+
* Get the LDAP configuration instance.
2727
*
2828
* @return DomainConfiguration
2929
*/
@@ -39,7 +39,7 @@ public function getConfiguration();
3939
public function setCache(CacheInterface $store);
4040

4141
/**
42-
* Sets the current connection.
42+
* Set the LDAP connection.
4343
*
4444
* @param LdapInterface $connection
4545
*
@@ -48,7 +48,7 @@ public function setCache(CacheInterface $store);
4848
public function setLdapConnection(LdapInterface $connection = null);
4949

5050
/**
51-
* Sets the current configuration.
51+
* Set the connection configuration.
5252
*
5353
* @param DomainConfiguration|array $configuration
5454
*
@@ -57,21 +57,21 @@ public function setLdapConnection(LdapInterface $connection = null);
5757
public function setConfiguration($configuration = []);
5858

5959
/**
60-
* Returns a new auth guard instance.
60+
* Get a new auth guard instance.
6161
*
6262
* @return \LdapRecord\Auth\Guard
6363
*/
6464
public function auth();
6565

6666
/**
67-
* Returns a new query builder for the current connection.
67+
* Get a new query builder for the connection.
6868
*
6969
* @return \LdapRecord\Query\Builder
7070
*/
7171
public function query();
7272

7373
/**
74-
* Connects and Binds to the Domain Controller.
74+
* Connect to the Domain Controller.
7575
*
7676
* If no username or password is specified, then the
7777
* configured administrator credentials are used.
@@ -85,4 +85,11 @@ public function query();
8585
* @return ConnectionInterface
8686
*/
8787
public function connect($username = null, $password = null);
88+
89+
/**
90+
* Determine if the LDAP connection is bound.
91+
*
92+
* @return bool
93+
*/
94+
public function isConnected();
8895
}

0 commit comments

Comments
 (0)