Example #1
0
File: LDAP.php Project: stunti/zf2
 /**
  * Copies a LDAP entry from one DN to another DN.
  *
  * @param  string|\Zend\LDAP\DN $from
  * @param  string|\Zend\LDAP\DN $to
  * @param  boolean             $recursively
  * @return \Zend\LDAP\LDAP Provides a fluid interface
  * @throws \Zend\LDAP\Exception
  */
 public function copy($from, $to, $recursively = false)
 {
     $entry = $this->getEntry($from, array(), true);
     if ($to instanceof DN) {
         $toDnParts = $to->toArray();
     } else {
         $toDnParts = DN::explodeDn($to);
     }
     $this->add($to, $entry);
     if ($recursively === true && $this->countChildren($from) > 0) {
         $children = $this->_getChildrenDns($from);
         foreach ($children as $c) {
             $cDnParts = DN::explodeDn($c);
             $newChildParts = array_merge(array(array_shift($cDnParts)), $toDnParts);
             $newChild = DN::implodeDn($newChildParts);
             $this->copy($c, $newChild, true);
         }
     }
     return $this;
 }
Example #2
0
File: DN.php Project: stunti/zf2
 /**
  * Checks if given $childDn is beneath $parentDn subtree.
  *
  * @param  string|\Zend\LDAP\DN $childDn
  * @param  string|\Zend\LDAP\DN $parentDn
  * @return boolean
  */
 public static function isChildOf($childDn, $parentDn)
 {
     try {
         $keys = array();
         $vals = array();
         if ($childDn instanceof DN) {
             $cdn = $childDn->toArray(DN::ATTR_CASEFOLD_LOWER);
         } else {
             $cdn = self::explodeDn($childDn, $keys, $vals, DN::ATTR_CASEFOLD_LOWER);
         }
         if ($parentDn instanceof DN) {
             $pdn = $parentDn->toArray(DN::ATTR_CASEFOLD_LOWER);
         } else {
             $pdn = self::explodeDn($parentDn, $keys, $vals, DN::ATTR_CASEFOLD_LOWER);
         }
     } catch (Exception $e) {
         return false;
     }
     $startIndex = count($cdn) - count($pdn);
     if ($startIndex < 0) {
         return false;
     }
     for ($i = 0; $i < count($pdn); $i++) {
         if ($cdn[$i + $startIndex] != $pdn[$i]) {
             return false;
         }
     }
     return true;
 }