Ejemplo n.º 1
0
 /**
  * Rebase diff based on source node as an origin
  *
  * @param Node $node Node to use as a source for origin
  *
  * @return void
  *
  * @throws RebaseException If source of origin node has uncommitted changes
  */
 public function rebaseDiff(Node $node)
 {
     $changes = array_merge($node->getDiffAdditions(), $node->getDiffDeletions(), $node->getDiffReplacements());
     if (count($changes) > 0) {
         throw new RebaseException(sprintf('%s has some uncommitted changes - Cannot rebase %s on %s', $node->getDn(), $this->getDn(), $node->getDn()));
     }
     $additions = $this->getDiffAdditions();
     $deletions = $this->getDiffDeletions();
     $replacements = $this->getDiffReplacements();
     $this->snapshot();
     $this->attributes = $node->getAttributes();
     foreach ($additions as $attribute => $values) {
         $this->get($attribute, true)->add($values);
     }
     foreach ($deletions as $attribute => $values) {
         if (count($values) == 0) {
             $this->removeAttribute($attribute);
             continue;
         }
         if ($this->has($attribute)) {
             $this->get($attribute)->remove($values);
         }
     }
     foreach ($replacements as $attribute => $values) {
         $this->get($attribute, true)->set($values);
     }
 }
Ejemplo n.º 2
0
 /**
  * Tests setting Dn for a node
  *
  * @return void
  */
 public function testSetDn()
 {
     $node = new Node();
     $this->assertNull($node->getDn());
     $node->setDn('test');
     $this->assertEquals('test', $node->getDn());
     $node = new Node();
     $entry = new Entry('test_dn', array());
     $node->hydrateFromEntry($entry);
     $this->assertEquals('test_dn', $node->getDn());
     try {
         $node->setDn('other_dn');
         $this->fail('Cannot manually set dn when node is bound to an existing entry');
     } catch (\InvalidArgumentException $e) {
         $this->assertRegExp('/Dn cannot be updated manually/', $e->getMessage());
     }
     $this->assertEquals('test_dn', $node->getDn());
     $node->setDn('other_dn', true);
     $this->assertEquals('other_dn', $node->getDn());
 }
Ejemplo n.º 3
0
 /**
  * Retrieves immediate children for the given node
  *
  * @param Node $node Node to retrieve children for
  *
  * @return array(Node) a set of Nodes
  */
 public function getChildrenNodes(Node $node)
 {
     $result = $this->search($node->getDn(), null, false);
     $nodes = array();
     foreach ($result as $node) {
         $nodes[] = $node;
     }
     return $nodes;
 }