Xpressengine\Config\ConfigEntity::getDepth PHP Method

getDepth() public method

depth level
public getDepth ( ) : integer
return integer
    public function getDepth()
    {
        return count(explode('.', $this->name));
    }

Usage Example

Beispiel #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);
 }