]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/Access/Ldap.php
Applied StyleCI changes, added php/larastan to attribution
[bookstack] / app / Auth / Access / Ldap.php
index 843a2f204920e9bd5154efe477c5212f73efa057..b5c70e498c0b4581dae5b6772ecee6f4c20696ca 100644 (file)
@@ -1,18 +1,20 @@
-<?php namespace BookStack\Auth\Access;
+<?php
+
+namespace BookStack\Auth\Access;
 
 /**
  * Class Ldap
  * An object-orientated thin abstraction wrapper for common PHP LDAP functions.
  * Allows the standard LDAP functions to be mocked for testing.
- * @package BookStack\Services
  */
 class Ldap
 {
-
     /**
      * Connect to a LDAP server.
+     *
      * @param string $hostName
      * @param int    $port
+     *
      * @return resource
      */
     public function connect($hostName, $port)
@@ -22,9 +24,11 @@ class Ldap
 
     /**
      * Set the value of a LDAP option for the given connection.
+     *
      * @param resource $ldapConnection
-     * @param int $option
-     * @param mixed $value
+     * @param int      $option
+     * @param mixed    $value
+     *
      * @return bool
      */
     public function setOption($ldapConnection, $option, $value)
@@ -32,10 +36,20 @@ class Ldap
         return ldap_set_option($ldapConnection, $option, $value);
     }
 
+    /**
+     * Start TLS on the given LDAP connection.
+     */
+    public function startTls($ldapConnection): bool
+    {
+        return ldap_start_tls($ldapConnection);
+    }
+
     /**
      * Set the version number for the given ldap connection.
+     *
      * @param $ldapConnection
      * @param $version
+     *
      * @return bool
      */
     public function setVersion($ldapConnection, $version)
@@ -45,10 +59,12 @@ class Ldap
 
     /**
      * Search LDAP tree using the provided filter.
+     *
      * @param resource   $ldapConnection
      * @param string     $baseDn
      * @param string     $filter
      * @param array|null $attributes
+     *
      * @return resource
      */
     public function search($ldapConnection, $baseDn, $filter, array $attributes = null)
@@ -58,8 +74,10 @@ class Ldap
 
     /**
      * Get entries from an ldap search result.
+     *
      * @param resource $ldapConnection
      * @param resource $ldapSearchResult
+     *
      * @return array
      */
     public function getEntries($ldapConnection, $ldapSearchResult)
@@ -69,23 +87,28 @@ class Ldap
 
     /**
      * Search and get entries immediately.
+     *
      * @param resource   $ldapConnection
      * @param string     $baseDn
      * @param string     $filter
      * @param array|null $attributes
+     *
      * @return resource
      */
     public function searchAndGetEntries($ldapConnection, $baseDn, $filter, array $attributes = null)
     {
         $search = $this->search($ldapConnection, $baseDn, $filter, $attributes);
+
         return $this->getEntries($ldapConnection, $search);
     }
 
     /**
      * Bind to LDAP directory.
+     *
      * @param resource $ldapConnection
      * @param string   $bindRdn
      * @param string   $bindPassword
+     *
      * @return bool
      */
     public function bind($ldapConnection, $bindRdn = null, $bindPassword = null)
@@ -95,8 +118,10 @@ class Ldap
 
     /**
      * Explode a LDAP dn string into an array of components.
+     *
      * @param string $dn
-     * @param int $withAttrib
+     * @param int    $withAttrib
+     *
      * @return array
      */
     public function explodeDn(string $dn, int $withAttrib)
@@ -106,12 +131,14 @@ class Ldap
 
     /**
      * Escape a string for use in an LDAP filter.
+     *
      * @param string $value
      * @param string $ignore
-     * @param int $flags
+     * @param int    $flags
+     *
      * @return string
      */
-    public function escape(string $value, string $ignore = "", int $flags = 0)
+    public function escape(string $value, string $ignore = '', int $flags = 0)
     {
         return ldap_escape($value, $ignore, $flags);
     }