Strip the absolute path of template's paths for all given sections.

@param string $sections Sections to iterate over.

@return array
552578
protected static function deepen($sections): array
    {
        foreach ($sections as $section => $paths) {
            $sections[$section] = static::convertToTree($paths);
        }

        return $sections;
    }
610006
protected static function convertToTree(array $paths): array
    {
        foreach ($paths as $index => $path) {
            static::convertPathToTree($paths, $index, $path);
        }

        return $paths;
    }
17160
protected function getSections(): array
    {
        $sections = explode($this->getDivider(), $this->getNotation());
        foreach ($sections as $index => $section) {
            $sections[$index] = explode($this->getSeparator(), $section);
        }

        return $sections;
    }
923580
public function findSection($section)
    {
        if (!isset($this->sectionMap[$section])) {
            throw new UnknownSection($section);
        }

        return $this->sectionMap[$section];
    }
602458
public function _normalizePaths($paths = [])
    {
        $routePaths = [];

        if ($paths === null) {
            return ['controller' => 'index', 'action' => 'index'];
        } elseif (is_string($paths)) {
            if (($pos = strpos($paths, '::')) !== false) {
                $routePaths['controller'] = substr($paths, 0, $pos);
                $routePaths['action'] = substr($paths, $pos + 2);
            } else {
                $routePaths['controller'] = $paths;
                $routePaths['action'] = 'index';
            }
        } elseif (is_array($paths)) {
            if (isset($paths['area'])) {
                $routePaths['area'] = $paths['area'];
            }

            if (isset($paths['controller'])) {
                $routePaths['controller'] = $paths['controller'];
            } elseif (isset($paths[0])) {
                $routePaths['controller'] = $paths[0];
            } else {
                $routePaths['controller'] = 'index';
            }

            if (isset($paths['action'])) {
                $routePaths['action'] = $paths['action'];
            } elseif (isset($paths[1])) {
                $routePaths['action'] = $paths[1];
            } else {
                $routePaths['action'] = 'index';
            }

            $params = [];
            /** @noinspection ForeachSourceInspection */
            foreach ($paths as $k => $v) {
                if (is_string($k) && !in_array($k, ['area', 'controller', 'action'], true)) {
                    $params[$k] = $v;
                }
            }

            if ($params) {
                $routePaths['params'] = $params;
            }
        }

        if (isset($routePaths['controller']) && strpos($routePaths['controller'], '\\') !== false) {
            $controller = strtr($routePaths['controller'], '\\', '/');

            if (substr_count($controller, '/') === 2) {
                $routePaths['controller'] = basename($controller, 'Controller');
            } elseif (preg_match('#(?:/Controllers/([^/]+)/(\w+)Controller)|(?:/Areas/([^/]+)/Controllers/(\w+)Controller)$#', $controller, $match)) {
                if (isset($match[3])) {
                    $routePaths['area'] = $match[3];
                    $routePaths['controller'] = $match[4];
                } else {
                    $routePaths['area'] = $match[1];
                    $routePaths['controller'] = $match[2];
                }
            } else {
                $routePaths['controller'] = basename($controller, 'Controller');
            }
        }

        return $routePaths;
    }
353098
public function make_section_constants($section) {
		if(!is_null($section) && strlen($section) && in_array($section, $this->get_valid_sections())) {
			foreach($this->fullConfig[$section] as $k=>$parsedValue) {
				//TODO: implement option to set a section/value as a CONSTANT
				$constantName = $k;
				if(!defined($constantName)) {
					define($constantName, $parsedValue);
				}
				
				$constantPlusSection = preg_replace('~\-~', '_', $section) .'-'. $constantName;
				if(!defined($constantPlusSection)) {
					define($constantPlusSection, $parsedValue);
				}
			}
		}
		else {
			throw new InvalidArgumentException("non-existent section, '". $section ."'");
		}
	}
558428
protected function _templatePath($path, array $vars = array())
    {
        if (strpos($path, '{') !== false) {
            preg_match_all('#\{\$([_a-z0-9]*)\}#i', $path, $matches);
            if (!empty($matches[1])) {
                foreach ($matches[1] as $var) {
                    $path = str_replace('{$' . $var . '}', isset($vars[$var]) ? $vars[$var] : null, $path);
                }
            }
        }
        return $path;
    }
866379
protected function findTemplateInPaths($template)
    {
        if (file_exists($template)) {
            return $template;
        }

        foreach ($this->paths as $path) {
            if (file_exists($realpath = $path . DIRECTORY_SEPARATOR . ltrim($template, DIRECTORY_SEPARATOR))) {
                return $realpath;
            }
        }

        return false;
    }
1317189
public function commonDir($paths)
	{
		// $this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__);
		$re_split = '#[\\\/]#';
		$count = 0;
		foreach ($paths as $k => $path) {
			if (empty($path)) {
				unset($paths[$k]);
				continue;
			}
			$ds = strpos($path, '/') !== false
				? '/'
				: $this->cfg['ds'];
			$levels = preg_split($re_split, $path);
			if (count($levels) > $count) {
				$count = count($levels);
			}
		}
		foreach ($paths as $path) {
			$parts = preg_split($re_split, $path);
			while ($count >= 0) {
				if (array_slice($levels, 0, $count) == array_slice($parts, 0, $count)) {
					$levels = array_slice($levels, 0, $count);
					continue 2;
				}
				$count--;
			}
		}
		$return = !empty($levels)
			? implode($ds, $levels)
			: '';
		// $this->debug->groupEnd();
		return $return;
	}
76375
protected function ModuleTemplates($module)
    {
        $folder = PathUtil::ModuleCustomTemplatesFolder($module);
        if (!Folder::Exists($folder))
        {
            return array();
        }
        $templates = Folder::GetFiles($folder);
        $result = array();
        foreach ($templates as $template)
        {
            if (Path::Extension($template) == 'phtml')
            {
                $result[] = Path::RemoveExtension($template);
            }
        }
        return $result;
    }
186074
public function prep_paths(array $paths)
	{
		foreach ($paths as &$path)
		{
			$path = $this->prep_path($path);
		}
		return $paths;
	}
273489
private function doGetSection($section)
    {
        return isset($this->config[$section]) ? $this->config[$section] : null;
    }
92731
public static function all(): array
    {
        $sections = [];

        foreach (App::path('Template') as $path) {
            if (is_dir($path)) {
                $sections['APP'] = $sections['APP'] ?? [];
                $sections['APP'] = array_merge($sections['APP'], static::iteratePath($path));
            }
        }

        foreach (static::pluginsWithTemplates() as $plugin) {
            foreach (App::path('Template', $plugin) as $path) {
                if (is_dir($path)) {
                    $sections[$plugin] = $sections[$plugin] ?? [];
                    $sections[$plugin] = array_merge($sections[$plugin], static::iteratePath($path));
                }
            }
        }

        return static::clearEmptySections($sections);
    }
826347
public static function path(...$paths)
    {
        $protocol = '';
        $path = trim(implode(DIRECTORY_SEPARATOR, $paths));
        if (preg_match('@^([a-z0-9]+://|/)(.*)@i', $path, $m)) {
            $protocol = $m[1];
            $path = $m[2];
        }
        $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
        $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
        $absolutes = [];
        foreach ($parts as $part) {
            if ('.' == $part) {
                continue;
            }
            if ('..' == $part) {
                array_pop($absolutes);
            } else {
                $absolutes[] = $part;
            }
        }
        $path = implode(DIRECTORY_SEPARATOR, $absolutes);
        if (DIRECTORY_SEPARATOR == '\\' && isset($protocol[4])) {
            $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
        }
        return $protocol . $path;
    }
1335680
protected static function formalUsage($section) {
        list (, $section) = explode(':', $section, 2);  # drop "usage:"
        $pu = preg_split('/\s+/', trim($section));

        $ret = [];
        foreach (array_slice($pu, 1) as $s) {
            if ($s == $pu[0]) $ret[] = ') | (';
            else              $ret[] = $s;
        }
        return '( '.join(' ', $ret).' )';
    }
1267706
public function acfLoadClean($paths)
    {
        $paths = array_unique($paths);

        foreach ($paths as $path) {
            foreach (@glob($path . '/*.json') as $file) {
                $json = json_decode(file_get_contents($file));

                if (!is_array($json)) {
                    continue;
                }

                $content = file($file);

                if (trim($content[0]) == '[') {
                    array_shift($content);
                    array_pop($content);
                }

                file_put_contents($file, $content);
            }
        }

        return $paths;
    }
843764
private function getExcludePaths(): array
    {
        $excludePaths = [];

        foreach ($this->excludePaths as $path) {
            $path = str_replace('*', '.*', $path);
            $excludePaths[] = '#' . str_replace($this->rootDirectory . '/', '', $path) . '#';
        }

        return $excludePaths;
    }