web/lib/Zend/Ldap/Node/RootDse.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Ldap
       
    17  * @subpackage RootDSE
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: RootDse.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Ldap_Node_Abstract
       
    25  */
       
    26 require_once 'Zend/Ldap/Node/Abstract.php';
       
    27 
       
    28 /**
       
    29  * Zend_Ldap_Node_RootDse provides a simple data-container for the RootDSE node.
       
    30  *
       
    31  * @category   Zend
       
    32  * @package    Zend_Ldap
       
    33  * @subpackage RootDSE
       
    34  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    36  */
       
    37 class Zend_Ldap_Node_RootDse extends Zend_Ldap_Node_Abstract
       
    38 {
       
    39     const SERVER_TYPE_GENERIC         = 1;
       
    40     const SERVER_TYPE_OPENLDAP        = 2;
       
    41     const SERVER_TYPE_ACTIVEDIRECTORY = 3;
       
    42     const SERVER_TYPE_EDIRECTORY      = 4;
       
    43 
       
    44     /**
       
    45      * Factory method to create the RootDSE.
       
    46      *
       
    47      * @param  Zend_Ldap $ldap
       
    48      * @return Zend_Ldap_Node_RootDse
       
    49      * @throws Zend_Ldap_Exception
       
    50      */
       
    51     public static function create(Zend_Ldap $ldap)
       
    52     {
       
    53         $dn = Zend_Ldap_Dn::fromString('');
       
    54         $data = $ldap->getEntry($dn, array('*', '+'), true);
       
    55         if (isset($data['domainfunctionality'])) {
       
    56             /**
       
    57              * @see Zend_Ldap_Node_RootDse_ActiveDirectory
       
    58              */
       
    59             require_once 'Zend/Ldap/Node/RootDse/ActiveDirectory.php';
       
    60             return new Zend_Ldap_Node_RootDse_ActiveDirectory($dn, $data);
       
    61         } else if (isset($data['dsaname'])) {
       
    62             /**
       
    63              * @see Zend_Ldap_Node_RootDse_ActiveDirectory
       
    64              */
       
    65             require_once 'Zend/Ldap/Node/RootDse/eDirectory.php';
       
    66             return new Zend_Ldap_Node_RootDse_eDirectory($dn, $data);
       
    67         } else if (isset($data['structuralobjectclass']) &&
       
    68                 $data['structuralobjectclass'][0] === 'OpenLDAProotDSE') {
       
    69             /**
       
    70              * @see Zend_Ldap_Node_RootDse_OpenLdap
       
    71              */
       
    72             require_once 'Zend/Ldap/Node/RootDse/OpenLdap.php';
       
    73             return new Zend_Ldap_Node_RootDse_OpenLdap($dn, $data);
       
    74         } else {
       
    75             return new self($dn, $data);
       
    76         }
       
    77     }
       
    78 
       
    79     /**
       
    80      * Constructor.
       
    81      *
       
    82      * Constructor is protected to enforce the use of factory methods.
       
    83      *
       
    84      * @param  Zend_Ldap_Dn $dn
       
    85      * @param  array        $data
       
    86      */
       
    87     protected function __construct(Zend_Ldap_Dn $dn, array $data)
       
    88     {
       
    89         parent::__construct($dn, $data, true);
       
    90     }
       
    91 
       
    92     /**
       
    93      * Gets the namingContexts.
       
    94      *
       
    95      * @return array
       
    96      */
       
    97     public function getNamingContexts()
       
    98     {
       
    99         return $this->getAttribute('namingContexts', null);
       
   100     }
       
   101 
       
   102     /**
       
   103      * Gets the subschemaSubentry.
       
   104      *
       
   105      * @return string|null
       
   106      */
       
   107     public function getSubschemaSubentry()
       
   108     {
       
   109         return $this->getAttribute('subschemaSubentry', 0);
       
   110     }
       
   111 
       
   112     /**
       
   113      * Determines if the version is supported
       
   114      *
       
   115      * @param  string|int|array $versions version(s) to check
       
   116      * @return boolean
       
   117      */
       
   118     public function supportsVersion($versions)
       
   119     {
       
   120         return $this->attributeHasValue('supportedLDAPVersion', $versions);
       
   121     }
       
   122 
       
   123     /**
       
   124      * Determines if the sasl mechanism is supported
       
   125      *
       
   126      * @param  string|array $mechlist SASL mechanisms to check
       
   127      * @return boolean
       
   128      */
       
   129     public function supportsSaslMechanism($mechlist)
       
   130     {
       
   131         return $this->attributeHasValue('supportedSASLMechanisms', $mechlist);
       
   132     }
       
   133 
       
   134     /**
       
   135      * Gets the server type
       
   136      *
       
   137      * @return int
       
   138      */
       
   139     public function getServerType()
       
   140     {
       
   141         return self::SERVER_TYPE_GENERIC;
       
   142     }
       
   143 
       
   144     /**
       
   145      * Returns the schema DN
       
   146      *
       
   147      * @return Zend_Ldap_Dn
       
   148      */
       
   149     public function getSchemaDn()
       
   150     {
       
   151         $schemaDn = $this->getSubschemaSubentry();
       
   152         /**
       
   153          * @see Zend_Ldap_Dn
       
   154          */
       
   155         require_once 'Zend/Ldap/Dn.php';
       
   156         return Zend_Ldap_Dn::fromString($schemaDn);
       
   157     }
       
   158 }