Example #1
0
 /**
  * Move entity hierarchy to new parent or root
  *
  * @param ConfigEntity $config config object
  * @param string|null  $to     parent name
  * @return ConfigEntity
  * @throws InvalidArgumentException
  * @throws NoParentException
  */
 public function move(ConfigEntity $config, $to = null)
 {
     if ($to !== null && $this->repo->find($config->siteKey, $to) === null) {
         throw new InvalidArgumentException(['arg' => $to]);
     }
     $parent = $config->getParent();
     if ($parent === null) {
         if ($config->getDepth() !== 1) {
             throw new NoParentException();
         }
         $this->repo->affiliate($config, $to);
     } else {
         $this->repo->foster($config, $to);
     }
     $arrName = explode('.', $config->name);
     $key = array_pop($arrName);
     if ($to !== null) {
         $key = $to . '.' . $key;
     }
     return $this->get($key, false, $config->siteKey);
 }
 /**
  * affiliated to another config
  *
  * @param ConfigEntity $config config object
  * @param string       $to     parent name
  * @return void
  */
 public function affiliate(ConfigEntity $config, $to)
 {
     $this->repo->affiliate($config, $to);
 }