Ejemplo n.º 1
0
Archivo: Move.php Proyecto: sonars/tree
 /**
  * Check wether the current move is possible and if not, rais an exception.
  *
  * @return void
  */
 protected function guardAgainstImpossibleMove()
 {
     if (!$this->node->exists) {
         throw new MoveNotPossibleException('A new node cannot be moved.');
     }
     if (array_search($this->position, array('child', 'left', 'right', 'root')) === FALSE) {
         throw new MoveNotPossibleException("Position should be one of ['child', 'left', 'right'] but is {$this->position}.");
     }
     if (!$this->promotingToRoot()) {
         if (is_null($this->target)) {
             if ($this->position === 'left' || $this->position === 'right') {
                 throw new MoveNotPossibleException("Could not resolve target node. This node cannot move any further to the {$this->position}.");
             } else {
                 throw new MoveNotPossibleException('Could not resolve target node.');
             }
         }
         if ($this->node->equals($this->target)) {
             throw new MoveNotPossibleException('A node cannot be moved to itself.');
         }
         if ($this->target->insideSubtree($this->node)) {
             throw new MoveNotPossibleException('A node cannot be moved to a descendant of itself (inside moved tree).');
         }
         if (!$this->node->inSameScope($this->target)) {
             throw new MoveNotPossibleException('A node cannot be moved to a different scope.');
         }
     }
 }