当前位置: 首页>>代码示例>>PHP>>正文


PHP Ldap\Dn类代码示例

本文整理汇总了PHP中Zend\Ldap\Dn的典型用法代码示例。如果您正苦于以下问题:PHP Dn类的具体用法?PHP Dn怎么用?PHP Dn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Dn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSimpleRecursiveIteration

 public function testSimpleRecursiveIteration()
 {
     $node = $this->getLDAP()->getBaseNode();
     $ri = new \RecursiveIteratorIterator($node, \RecursiveIteratorIterator::SELF_FIRST);
     $i = 0;
     foreach ($ri as $rdn => $n) {
         $dn = $n->getDn()->toString(Ldap\Dn::ATTR_CASEFOLD_LOWER);
         $rdn = Ldap\Dn::implodeRdn($n->getRdnArray(), Ldap\Dn::ATTR_CASEFOLD_LOWER);
         if ($i == 0) {
             $this->assertEquals(Ldap\Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)->toString(Ldap\Dn::ATTR_CASEFOLD_LOWER), $dn);
         } elseif ($i == 1) {
             $this->assertEquals('ou=Node', $rdn);
             $this->assertEquals($this->createDn('ou=Node,'), $dn);
         } else {
             if ($i < 4) {
                 $j = $i - 1;
                 $base = $this->createDn('ou=Node,');
             } else {
                 $j = $i - 3;
                 $base = Ldap\Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)->toString(Ldap\Dn::ATTR_CASEFOLD_LOWER);
             }
             $this->assertEquals('ou=Test' . $j, $rdn);
             $this->assertEquals('ou=Test' . $j . ',' . $base, $dn);
         }
         $i++;
     }
     $this->assertEquals(9, $i);
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:28,代码来源:ChildrenIterationTest.php

示例2: getUserBaseDn

 public function getUserBaseDn($uid)
 {
     // Search the user in the directory
     $result = $this->search(array('filter' => '(&(|(objectClass=person)(objectClass=mailRecipient))(mail=' . Filter::escapeValue($uid) . '))', 'attributes' => array('employeeNumber'), 'sizelimit' => 2));
     if ($result->count() < 1) {
         throw new Exception('not found');
     } else {
         if ($result->count() > 1) {
             throw new Exception('somethind bad happened');
         }
     }
     $entry = $result->getFirst();
     $userDn = $entry['dn'];
     $branchDn = Dn::factory($userDn)->getParentDn(1);
     // Search the subtree the user is an administrator
     $subtree = null;
     for ($i = 1; $i <= 3; $i++) {
         $result = $this->search(array('filter' => '(&(objectClass=groupOfNames)(member=' . Filter::escapeValue($userDn) . '))', 'basedn' => $subtree = $branchDn->getParentDn($i), 'attributes' => array('employeeNumber'), 'sizelimit' => 2));
         if ($result->count() === 1) {
             break;
         } else {
             $subtree = null;
         }
     }
     if (is_null($subtree)) {
         throw new UserFriendlyException(403, 'Access denied', 'You are not allowed to access this resource.');
     }
     return $subtree->toString();
 }
开发者ID:rledisez,项目名称:SOGoAccountsManager,代码行数:29,代码来源:Ldap.php

示例3: createDn

 protected function createDn($dn)
 {
     if (substr($dn, -1) !== ',') {
         $dn .= ',';
     }
     $dn = $dn . TESTS_ZEND_LDAP_WRITEABLE_SUBTREE;
     return Ldap\Dn::fromString($dn)->toString(Ldap\Dn::ATTR_CASEFOLD_LOWER);
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:8,代码来源:AbstractOnlineTestCase.php

示例4: testUnescapeValues

 public function testUnescapeValues()
 {
     $dnval = '\\20\\20\\16\\20t\\,e\\+s \\"t\\,\\\\v\\<a\\>l\\;u\\#e\\=!\\20\\20\\20\\20';
     $expected = '  ' . chr(22) . ' t,e+s "t,\\v<a>l;u#e=!    ';
     $this->assertEquals($expected, Ldap\Dn::unescapeValue($dnval));
     $this->assertEquals($expected, Ldap\Dn::unescapeValue(array($dnval)));
     $this->assertEquals(array($expected, $expected, $expected), Ldap\Dn::unescapeValue(array($dnval, $dnval, $dnval)));
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:8,代码来源:EscapingTest.php

示例5: update

    /**
     * Sends all pending changes to the LDAP server
     *
     * @param  \Zend\Ldap\Ldap $ldap
     * @return \Zend\Ldap\Node Provides a fluid interface
     * @throws \Zend\Ldap\Exception
     */
    public function update(Ldap $ldap = null)
    {
        if ($ldap !== null) {
            $this->attachLdap($ldap);
        }
        $ldap = $this->getLdap();
        if (!($ldap instanceof Ldap)) {
            throw new Exception(null, 'No LDAP connection available');
        }

        if ($this->willBeDeleted()) {
            if ($ldap->exists($this->_dn)) {
                $ldap->delete($this->_dn);
            }
            return $this;
        }

        if ($this->isNew()) {
            $data = $this->getData();
            $ldap->add($this->_getDn(), $data);
            $this->_loadData($data, true);
            return $this;
        }

        $changedData = $this->getChangedData();
        if ($this->willBeMoved()) {
            $recursive = $this->hasChildren();
            $ldap->rename($this->_dn, $this->_newDn, $recursive, false);
            foreach ($this->_newDn->getRdn() as $key => $value) {
                if (array_key_exists($key, $changedData)) {
                    unset($changedData[$key]);
                }
            }
            $this->_dn = $this->_newDn;
            $this->_newDn = null;
        }
        if (count($changedData) > 0) {
            $ldap->update($this->_getDn(), $changedData);
        }
        $this->_originalData = $this->_currentData;
        return $this;
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:49,代码来源:Node.php

示例6: testIsChildOfParentDnLonger

 public function testIsChildOfParentDnLonger()
 {
     $dn1 = 'dc=example,dc=de';
     $dn2 = 'cb=name1,cn=name2,dc=example,dc=org';
     $this->assertFalse(Ldap\Dn::isChildOf($dn1, $dn2));
 }
开发者ID:rexmac,项目名称:zf2,代码行数:6,代码来源:MiscTest.php

示例7: getSchemaDn

 /**
  * Returns the schema DN
  *
  * @return \Zend\Ldap\Dn
  */
 public function getSchemaDn()
 {
     $schemaDn = $this->getSubschemaSubentry();
     return Ldap\Dn::fromString($schemaDn);
 }
开发者ID:GeeH,项目名称:zend-ldap,代码行数:10,代码来源:RootDse.php

示例8: testLoadFromLDAPWithDnObject

 public function testLoadFromLDAPWithDnObject()
 {
     $dn = Ldap\Dn::fromString($this->_createDn('ou=Test1,'));
     $node = Node::fromLDAP($dn, $this->_getLDAP());
     $this->assertInstanceOf('Zend\\Ldap\\Node', $node);
     $this->assertTrue($node->isAttached());
 }
开发者ID:navtis,项目名称:xerxes-pazpar2,代码行数:7,代码来源:OnlineTest.php

示例9: testDnObjectCloning

 public function testDnObjectCloning()
 {
     $node1 = $this->createTestNode();
     $dn1 = Ldap\Dn::fromString('cn=name2,dc=example,dc=org');
     $node1->setDn($dn1);
     $dn1->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn1->toString(), $node1->getDn()->toString());
     $dn2 = Ldap\Dn::fromString('cn=name2,dc=example,dc=org');
     $node2 = Ldap\Node::create($dn2);
     $dn2->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn2->toString(), $node2->getDn()->toString());
     $dn3 = Ldap\Dn::fromString('cn=name2,dc=example,dc=org');
     $node3 = Ldap\Node::fromArray(array('dn' => $dn3, 'ou' => 'Test'), false);
     $dn3->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn3->toString(), $node3->getDn()->toString());
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:16,代码来源:OfflineTest.php

示例10: testSaveWithDnObject

 public function testSaveWithDnObject()
 {
     $dn = Ldap\Dn::fromString($this->_createDn('ou=TestCreated,'));
     $data = array('ou' => 'TestCreated', 'objectclass' => 'organizationalUnit');
     try {
         $this->_getLDAP()->save($dn, $data);
         $this->assertTrue($this->_getLDAP()->exists($dn));
         $data['l'] = 'mylocation1';
         $this->_getLDAP()->save($dn, $data);
         $this->assertTrue($this->_getLDAP()->exists($dn));
         $entry = $this->_getLDAP()->getEntry($dn);
         $this->_getLDAP()->delete($dn);
         $this->assertEquals('mylocation1', $entry['l'][0]);
     } catch (Ldap\Exception $e) {
         if ($this->_getLDAP()->exists($dn)) {
             $this->_getLDAP()->delete($dn);
         }
         $this->fail($e->getMessage());
     }
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:20,代码来源:CrudTest.php

示例11: testArrayAccessImplementation

 public function testArrayAccessImplementation()
 {
     $dnString = 'cn=Baker\\, Alice,cn=Users,dc=example,dc=com';
     $dn = Ldap\Dn::fromString($dnString);
     $this->assertEquals(array('cn' => 'Baker, Alice'), $dn[0]);
     $this->assertEquals(array('cn' => 'Users'), $dn[1]);
     $this->assertEquals(array('dc' => 'example'), $dn[2]);
     $this->assertEquals(array('dc' => 'com'), $dn[3]);
     $this->assertTrue(isset($dn[0]));
     $this->assertTrue(isset($dn[1]));
     $this->assertTrue(isset($dn[2]));
     $this->assertTrue(isset($dn[3]));
     $this->assertFalse(isset($dn[-1]));
     $this->assertFalse(isset($dn[4]));
     $dn = Ldap\Dn::fromString($dnString);
     unset($dn[0]);
     $this->assertEquals('cn=Users,dc=example,dc=com', $dn->toString());
     $dn = Ldap\Dn::fromString($dnString);
     unset($dn[1]);
     $this->assertEquals('cn=Baker\\, Alice,dc=example,dc=com', $dn->toString());
     $dn = Ldap\Dn::fromString($dnString);
     unset($dn[2]);
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=com', $dn->toString());
     $dn = Ldap\Dn::fromString($dnString);
     unset($dn[3]);
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example', $dn->toString());
     $dn = Ldap\Dn::fromString($dnString);
     $dn[0] = array('uid' => 'abaker');
     $this->assertEquals('uid=abaker,cn=Users,dc=example,dc=com', $dn->toString());
     $dn = Ldap\Dn::fromString($dnString);
     $dn[1] = array('ou' => 'Lab');
     $this->assertEquals('cn=Baker\\, Alice,ou=Lab,dc=example,dc=com', $dn->toString());
     $dn = Ldap\Dn::fromString($dnString);
     $dn[2] = array('dc' => 'example', 'ou' => 'Test');
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example+ou=Test,dc=com', $dn->toString());
     $dn = Ldap\Dn::fromString($dnString);
     $dn[3] = array('dc' => 'de+fr');
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example,dc=de\\+fr', $dn->toString());
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:39,代码来源:ModificationTest.php

示例12: isChildOf

 /**
  * Checks if given $childDn is beneath $parentDn subtree.
  *
  * @param  string|Dn $childDn
  * @param  string|Dn $parentDn
  * @return bool
  */
 public static function isChildOf($childDn, $parentDn)
 {
     try {
         $keys = [];
         $vals = [];
         if ($childDn instanceof Dn) {
             $cdn = $childDn->toArray(DN::ATTR_CASEFOLD_LOWER);
         } else {
             $cdn = static::explodeDn($childDn, $keys, $vals, DN::ATTR_CASEFOLD_LOWER);
         }
         if ($parentDn instanceof Dn) {
             $pdn = $parentDn->toArray(DN::ATTR_CASEFOLD_LOWER);
         } else {
             $pdn = static::explodeDn($parentDn, $keys, $vals, DN::ATTR_CASEFOLD_LOWER);
         }
     } catch (Exception\LdapException $e) {
         return false;
     }
     $startIndex = count($cdn) - count($pdn);
     if ($startIndex < 0) {
         return false;
     }
     for ($i = 0, $count = count($pdn); $i < $count; $i++) {
         if ($cdn[$i + $startIndex] != $pdn[$i]) {
             return false;
         }
     }
     return true;
 }
开发者ID:GeeH,项目名称:zend-ldap,代码行数:36,代码来源:Dn.php

示例13: findUnit

 private function findUnit(Identity $identity)
 {
     if (null === $this->unit) {
         $filter = Filter::equals('mail', $identity->mail);
         $baseDn = Dn::factory($this->ldap->getBaseDn())->prepend(['ou' => 'people']);
         $result = $this->ldap->search($filter, $baseDn, Ldap::SEARCH_SCOPE_ONE, ['l']);
         if (1 !== $result->count()) {
             return;
         }
         $result = $result->current();
         $unitDn = $result['l'][0];
         $this->unit = $this->ldap->getNode($unitDn);
     }
     return $this->unit;
 }
开发者ID:eellak,项目名称:gredu_labs,代码行数:15,代码来源:CreateSchool.php

示例14: testExplodeDnsProvidedByRFC2253

 /**
  * @dataProvider rfc2253DnProvider
  */
 public function testExplodeDnsProvidedByRFC2253($input, $expected)
 {
     $dnArray = Ldap\Dn::explodeDn($input);
     $this->assertEquals($expected, $dnArray);
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:8,代码来源:ExplodingTest.php

示例15: setDn

 /**
  * Sets the new DN for this node
  *
  * This is an offline method.
  *
  * @param  Dn|string|array $newDn
  * @throws Exception\LdapException
  * @return Node Provides a fluid interface
  */
 public function setDn($newDn)
 {
     if ($newDn instanceof Dn) {
         $this->newDn = clone $newDn;
     } else {
         $this->newDn = Dn::factory($newDn);
     }
     $this->ensureRdnAttributeValues(true);
     return $this;
 }
开发者ID:GeeH,项目名称:zend-ldap,代码行数:19,代码来源:Node.php


注:本文中的Zend\Ldap\Dn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。