Devide url on segments

@return array
9844
protected function devideUrl()
    {
        $parts = explode('/', $this->getPath());
        $cnt   = count($parts);
        for ($i = 0; $i < $cnt; $i++) {
            $parts[$i] = trim($parts[$i]);
        }
        return $parts;
    }
1291017
public function currentRequestAllUrls()
    {
        $urls = $this->allUrls;

        if ($urls === null) {
            if ($this->getPath() === null) {
                $this->detectUrlDetails();
            }

            $urls = [];
            $current = $this->getHost() . $this->config->getPathPrefix() . $this->getPath();
            if (!is_null($this->getQuery())) {
                $current .= '?'. $this->getQuery();
            }
            $urls[$this->translate->getDefault()] = $current;
            foreach ($this->translate->getLanguages() as $language) {
                $current = $this->getHost() . $this->config->getPathPrefix() . '/' . $language . $this->getPath();
                if (!is_null($this->getQuery())) {
                    $current .= '?'. $this->getQuery();
                }
                $urls[$language] = $current;
            }

            $this->allUrls = $urls;
        }

        return $urls;
    }
1120642
public function url()
    {
        $scheme = $this->scheme();
        $scheme = $scheme ? $scheme . '://' : '//';
        $query = $this->query() ? '?' . http_build_query($this->query()) : '';
        $fragment = $this->fragment() ? '#' . $this->fragment() : '';
        return $scheme . $this->host() . $this->path() . $query . $fragment;
    }
510944
public function getSegmentHashesByIdSite()
    {
        //Get a list of hashes of all segments that exist now
        $sql = "SELECT DISTINCT definition, enable_only_idsite FROM " . Common::prefixTable('segment')
            . " WHERE deleted = 0";
        $rows = Db::fetchAll($sql);
        $segmentHashes = array();
        foreach ($rows as $row) {
            $idSite = (int)$row['enable_only_idsite'];
            if (! isset($segmentHashes[$idSite])) {
                $segmentHashes[$idSite] = array();
            }
            $segmentHashes[$idSite][] = Segment::getSegmentHash($row['definition']);
        }

        return $segmentHashes;
    }
2868
public function getRedirectUrlBase()
    {
        // URLConfirmationTokens may alter the URL to suppress the URL they're protecting,
        // so we need to ensure they're inspected last and therefore take priority
        $tokens = iterator_to_array($this->filteredTokens(), false);
        usort($tokens, function ($a, $b) {
            return ($a instanceof URLConfirmationToken) ? 1 : 0;
        });

        $urlBase = Director::baseURL();
        foreach ($tokens as $token) {
            $urlBase = $token->getRedirectUrlBase();
        }

        return $urlBase;
    }
326814
public function getPath(): string
    {
        if (!isset($this->segments['path'])) {
            throw new UrlException('Unable to get path for ' . $this->url);
        }

        return $this->segments['path'];
    }
1095682
public function parse(&$segments)
    {
        $path = implode('/', $segments);
        $vars = array();

        $matches = array();
        if (preg_match('/(\d+)-([^\/]+)/', $path, $matches)) {
            $vars['alias'] = $matches[2];
            $path = str_replace($matches[0], $matches[1], $path);
            $segments = array_filter(explode('/', $path));
        }

        $path = implode('/', $segments);

        $matches = array();

        if (preg_match('/@(\w+)/', $path, $matches)) {
            $vars['oid'] = $matches[1];
            if (isset($matches[2])) {
                $vars['view'] = $matches[2];
            }
            $path = ltrim(str_replace($matches[0], '', $path), '/');
            $segments = array_filter(explode('/', $path));
        }

        $vars = array_merge($vars, parent::parse($segments));

        if (isset($vars['id']) && current($segments)) {
            $vars['alias'] = array_shift($segments);
        }

        return $vars;
    }
873954
private function parse()
    {
        $this->parameters   = [];
        $this->pathSegments = [];
        $parsedUrl          = parse_url($this->returnValue);
        foreach ($parsedUrl as $key => $value) {
            if ($key == 'query') {
                parse_str($value, $this->parameters);
            } elseif ($key == 'path') {
                $this->pathSegments = ($value) ? explode('/', ltrim($value, '/')) : [];
            } else {
                $this->{$key} = $value;
            }
        }
        return $this;
    }
1285694
protected function getRequestedUrls()
    {
        $oInput = Factory::service('Input');
        $sUrls  = $oInput->get('urls') ?: $oInput->header('X-Cdn-Urls');
        $aUrls  = !is_array($sUrls) ? explode(',', $sUrls) : $sUrls;
        $aUrls  = array_map('strtolower', $aUrls);

        //  Filter out any which don't follow the format {digit}x{digit}-{scale|crop} || raw
        foreach ($aUrls as &$sDimension) {

            if (!is_string($sDimension)) {
                $sDimension = null;
                continue;
            }

            preg_match_all('/^(\d+?)x(\d+?)-(scale|crop)$/i', $sDimension, $aMatches);

            if (empty($aMatches[0])) {
                $sDimension = null;
            } else {
                $sDimension = [
                    'width'  => !empty($aMatches[1][0]) ? $aMatches[1][0] : null,
                    'height' => !empty($aMatches[2][0]) ? $aMatches[2][0] : null,
                    'type'   => !empty($aMatches[3][0]) ? $aMatches[3][0] : 'crop',
                ];
            }
        }

        return array_filter($aUrls);
    }
240151
public function getAllLocalizedRoutes($segments = null, $leadSlash = true, $fullPath = false) {
        /*
         * routes with dynamic parameter(s)
         */
        if ($allRoutes = $this->getAllLocalazedDynamicRoutes($segments, $leadSlash, $fullPath)) {
            return $allRoutes;
        }
        
        /*
         * static routes
         */
        $allRoutes = [];
        // if segmets are not set - get from current request
        if (is_null($segments)) {
            $segments = \Request::segments();
        }
        elseif (is_string($segments)) {
            $segments = explode('/', $segments);
        }
        
        // if locale segment set - remove it from [0]
        if ($this->isSetLocaleSegmentInRoute($segments)) {
            array_shift($segments);
        }

        // loop each posiable locales and build localized rote
        foreach($this->getAllRoutelocales() as $locale) {
            $path = '';
            if (($this->getDefaultRoutelocale() !== $locale) || $this->isUsePrefixForDefaultLocale()) {
                // add locale to [0] segment
                $path = ($leadSlash ? '/' : '') . implode('/', array_merge([$locale], $segments));
            }
            else {
                // if it is default locale - DO NOT add it to [0] segment
                $path = ($leadSlash ? '/' : '') . implode('/', $segments);
            }
            $allRoutes[$locale] = $fullPath ? \URL::to($path) : $path;
        }
        return $allRoutes;
    }
1199880
public function generateURLSegment()
    {
        $filter = URLSegmentFilter::create();
        $name = $this->owner->FirstName . ' ' . $this->owner->Surname;
        $urlSegment = $filter->filter($name);

        if (!$urlSegment || $urlSegment == '-' || $urlSegment == '-1') {
            $urlSegment = 'profile-' . $this->owner->ID;
        }

        return $urlSegment;
    }
143637
public function getQuery(): string
    {
        if (!isset($this->segments['query'])) {
            throw new UrlException('Unable to get query for ' . $this->url);
        }

        return $this->segments['query'];
    }
1120263
public function getUrlRule()
    {
        $request = $this->getRequestRoute();
        
        return [
            'module' => $this->module->id,
            'route' => $this->module->id . '/' . $request['route'],
            'params' => $request['originalArgs'],
        ];
    }
267443
public static function buildUrl(array $parts)
    {
        $url = $scheme = '';

        if (isset($parts['scheme'])) {
            $scheme = $parts['scheme'];
            $url .= $scheme . ':';
        }

        if (isset($parts['host'])) {
            $url .= '//';
            if (isset($parts['user'])) {
                $url .= $parts['user'];
                if (isset($parts['pass'])) {
                    $url .= ':' . $parts['pass'];
                }
                $url .=  '@';
            }

            $url .= $parts['host'];

            // Only include the port if it is not the default port of the scheme
            if (isset($parts['port'])
                && !(($scheme == 'http' && $parts['port'] == 80) || ($scheme == 'https' && $parts['port'] == 443))
            ) {
                $url .= ':' . $parts['port'];
            }
        }

        // Add the path component if present
        if (isset($parts['path']) && 0 !== strlen($parts['path'])) {
            // Always ensure that the path begins with '/' if set and something is before the path
            if ($url && $parts['path'][0] != '/' && substr($url, -1)  != '/') {
                $url .= '/';
            }
            $url .= $parts['path'];
        }

        // Add the query string if present
        if (isset($parts['query'])) {
            $url .= '?' . $parts['query'];
        }

        // Ensure that # is only added to the url if fragment contains anything.
        if (isset($parts['fragment'])) {
            $url .= '#' . $parts['fragment'];
        }

        return $url;
    }
585843
public function getAllSegmentsAndIgnoreVisibility()
    {
        $sql = "SELECT * FROM " . $this->getTable() . " WHERE deleted = 0";

        $segments = $this->getDb()->fetchAll($sql);

        return $segments;
    }
935671
private function getSegmentsHtml(&$segments) {
    $html = '<h3>Segments Collection</h3>' .
            $this->getCollectionInfoHtml($segments);

    $items = $segments->getItems();

    if (count($items) == 0) {
      $html .= '<p>No Segments Found</p>';
    } else {
      foreach ($items as &$segment) {
        $html .= <<<HTML
<hr>
<pre>
Segment ID = {$segment->getId()}
Kind       = {$segment->getKind()}
Self Link  = {$segment->getSelfLink()}
Name       = {$segment->getName()}
Definition = {$segment->getDefinition()}
Created    = {$segment->getCreated()}
Updated    = {$segment->getUpdated()}
</pre>
HTML;
      }
    }
    return $html;
  }
866830
protected function getCommonReplacements()
    {
        return [
            '{{sectionBaseName}}' => end($this->sectionSegments),
            '{{studlySectionBaseName}}' => end($this->sectionSegmentsStudly),
            '{{routeBaseAlias}}' => $this->section,
            '{{langBaseKey}}'    => ($this->langDir ? $this->langDir.'/' : '').implode('/', $this->sectionSegments),
            '{{viewBaseName}}'   => ($this->viewsDir ? $this->viewsDir.'.' : '').$this->section,
            '{{modelClass}}'     => $this->modelClass,
        ];
    }