Exemplo n.º 1
0
 /**
  * Move entity hierarchy to new parent or root
  *
  * @param Registered  $registered registered object
  * @param string|null $to         to registered prefix
  *
  * @return void
  * @throws InvalidArgumentException
  */
 public function move(Registered $registered, $to = null)
 {
     $toParent = $to !== null ? $this->repo->findByTypeAndName($registered->siteKey, $registered->type, $to) : null;
     if ($to !== null && $toParent === null || $toParent !== null && $registered->type != $toParent->type) {
         throw new InvalidArgumentException();
     }
     $parent = $registered->getParent();
     if ($parent === null) {
         if ($registered->getDepth() !== 1) {
             throw new InvalidArgumentException();
         }
         $this->repo->affiliate($registered, $to);
     } else {
         $this->repo->foster($registered, $to);
     }
 }