Horde_Ldap::copy PHP Метод

copy() публичный Метод

The entry will be immediately copied. Only attributes you have selected will be copied.
public copy ( Horde_Ldap_Entry $entry, string $newdn ) : Horde_Ldap_Entry
$entry Horde_Ldap_Entry An LDAP entry.
$newdn string New FQF-DN of the entry.
Результат Horde_Ldap_Entry The copied entry.
    public function copy($entry, $newdn)
    {
        if (!$entry instanceof Horde_Ldap_Entry) {
            throw new Horde_Ldap_Exception('Parameter $entry is expected to be a Horde_Ldap_Entry object');
        }
        $newentry = Horde_Ldap_Entry::createFresh($newdn, $entry->getValues());
        $this->add($newentry);
        return $newentry;
    }

Usage Example

Пример #1
0
 /**
  * Test copy().
  */
 public function testCopy()
 {
     $ldap = new Horde_Ldap(self::$ldapcfg['server']);
     // Some testdata.
     $base = self::$ldapcfg['server']['basedn'];
     $ou1 = Horde_Ldap_Entry::createFresh('ou=Horde_Ldap_Test_pool,' . $base, array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'Horde_Ldap_Test_copy'));
     $ou2 = Horde_Ldap_Entry::createFresh('ou=Horde_Ldap_Test_tgt,' . $base, array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'Horde_Ldap_Test_copy'));
     $ldap->add($ou1);
     $this->assertTrue($ldap->exists($ou1->dn()));
     $ldap->add($ou2);
     $this->assertTrue($ldap->exists($ou2->dn()));
     $entry = Horde_Ldap_Entry::createFresh('l=cptest,' . $ou1->dn(), array('objectClass' => array('top', 'locality'), 'l' => 'cptest'));
     $ldap->add($entry);
     $ldap->exists($entry->dn());
     // Copy over the entry to another tree with rename.
     $entrycp = $ldap->copy($entry, 'l=test_copied,' . $ou2->dn());
     $this->assertInstanceOf('Horde_Ldap_Entry', $entrycp);
     $this->assertNotEquals($entry->dn(), $entrycp->dn());
     $this->assertTrue($ldap->exists($entrycp->dn()));
     // Copy same again (fails, entry exists).
     try {
         $entrycp_f = $ldap->copy($entry, 'l=test_copied,' . $ou2->dn());
         $this->fail('Horde_Ldap_Exception expected.');
     } catch (Horde_Ldap_Exception $e) {
     }
     // Use only DNs to copy (fails).
     try {
         $entrycp = $ldap->copy($entry->dn(), 'l=test_copied2,' . $ou2->dn());
         $this->fail('Horde_Ldap_Exception expected.');
     } catch (Horde_Ldap_Exception $e) {
     }
 }