Parses a segment

@param string $segment
a segment from the "mappings" section
@return \axy\sourcemap\PosMap
@throws \axy\sourcemap\errors\InvalidMappings
169794
public function parse($segment)
    {
        $generated = new PosGenerated();
        $source = new PosSource();
        $pos = new PosMap($generated, $source);
        try {
            $offsets = $this->encoder->decode($segment);
        } catch (VLQError $e) {
            throw new InvalidMappings('Invalid segment "'.$segment.'"', $e);
        }
        $count = count($offsets);
        if (!in_array($count, [1, 4, 5])) {
            throw new InvalidMappings('Invalid segment "'.$segment.'"');
        }
        $generated->line = $this->gLine;
        $this->gColumn += $offsets[0];
        $generated->column = $this->gColumn;
        if ($count >= 4) {
            $this->sFile += $offsets[1];
            $this->sLine += $offsets[2];
            $this->sColumn += $offsets[3];
            $source->fileIndex = $this->sFile;
            $source->line = $this->sLine;
            $source->column = $this->sColumn;
            if ($count === 5) {
                $this->sName += $offsets[4];
                $source->nameIndex = $this->sName;
            }
        }
        return $pos;
    }
388129
public static function replaceSegment($uri, int $offset, $segment)
    {
        $uri = self::filterUri($uri);

        return self::normalizePath($uri, (new HierarchicalPath($uri->getPath()))->withSegment($offset, $segment));
    }
274717
public function addSegments($segments)
    {
        if ( ! $segments instanceof Segments) {
            $segments = new Segments($segments);
        }

        $currentSegments = $this->segments->getParts();
        $addSegments = $segments->getParts();

        $uri = clone $this;
        $uri->segments = new Segments(array_merge($currentSegments, $addSegments));

        return $uri;
    }
1362547
protected function addSegment(Segment $segment)
    {
        if (!$segment->getSegment() && $this->segmentName) {
            $segment->setSegment($this->segmentName);
        }

        if (!$segment->getType()) {
            $metricTypes = array(self::TYPE_NUMBER, self::TYPE_FLOAT, self::TYPE_MONEY, self::TYPE_DURATION_S, self::TYPE_DURATION_MS);
            if (in_array($this->getType(), $metricTypes, $strict = true)) {
                $segment->setType(Segment::TYPE_METRIC);
            } else {
                $segment->setType(Segment::TYPE_DIMENSION);
            }
        }

        if (!$segment->getCategoryId() && $this->category) {
            $segment->setCategory($this->category);
        }

        if (!$segment->getName() && $this->nameSingular) {
            $segment->setName($this->nameSingular);
        }

        $sqlSegment = $segment->getSqlSegment();

        if (empty($sqlSegment) && !$segment->getUnionOfSegments()) {
            if (!empty($this->sqlSegment)) {
                $segment->setSqlSegment($this->sqlSegment);
            } elseif ($this->dbTableName && $this->columnName) {
                $segment->setSqlSegment($this->dbTableName . '.' . $this->columnName);
            } else {
                throw new Exception('Segment cannot be added because no sql segment is set');
            }
        }

        if (!$this->suggestedValuesCallback) {
            // we can generate effecient value callback for enums automatically
            $enum = $this->getEnumColumnValues();
            if (!empty($enum)) {
                $this->suggestedValuesCallback = function ($idSite, $maxValuesToReturn) use ($enum) {
                    $values = array_values($enum);
                    return array_slice($values, 0, $maxValuesToReturn);
                };
            }
        }

        if (!$this->acceptValues) {
            // we can generate accept values for enums automatically
            $enum = $this->getEnumColumnValues();
            if (!empty($enum)) {
                $enumValues = array_values($enum);
                $enumValues = array_slice($enumValues, 0, 20);
                $this->acceptValues = 'Eg. ' . implode(', ', $enumValues);
            };
        }

        if ($this->acceptValues && !$segment->getAcceptValues()) {
            $segment->setAcceptedValues($this->acceptValues);
        }

        if (!$this->sqlFilterValue && !$segment->getSqlFilter() && !$segment->getSqlFilterValue()) {
            // no sql filter configured, we try to configure automatically for enums
            $enum = $this->getEnumColumnValues();
            if (!empty($enum)) {
                $this->sqlFilterValue = function ($value, $sqlSegmentName) use ($enum) {
                    if (isset($enum[$value])) {
                        return $value;
                    }

                    $id = array_search($value, $enum);

                    if ($id === false) {
                        $id = array_search(strtolower(trim(urldecode($value))), $enum);

                        if ($id === false) {
                            throw new \Exception("Invalid '$sqlSegmentName' segment value $value");
                        }
                    }

                    return $id;
                };
            };
        }

        if ($this->suggestedValuesCallback && !$segment->getSuggestedValuesCallback()) {
            $segment->setSuggestedValuesCallback($this->suggestedValuesCallback);
        }

        if ($this->sqlFilterValue && !$segment->getSqlFilterValue()) {
            $segment->setSqlFilterValue($this->sqlFilterValue);
        }

        if ($this->sqlFilter && !$segment->getSqlFilter()) {
            $segment->setSqlFilter($this->sqlFilter);
        }

        if (!$this->allowAnonymous) {
            $segment->setRequiresAtLeastViewAccess(true);
        }

        $this->segments[] = $segment;
    }
1363202
public function parse(&$segments)
    {
        $query = array();
        $path = implode('/', $segments);

        if ($path == 'signup') {
            return array('view' => 'person','layout' => 'signup');
        } elseif (
             !empty($segments) &&
             !is_numeric($segments[0]) &&
             !in_array(AnInflector::singularize($segments[0]), array('person', 'session', 'token'))
        ) {
            $query['username'] = $segments[0];
            //@TODO the parent::parse wants a numeric ID in order
            //to parse correctly. For now lets hack it
            $segments[0] = 10;
            $query['view'] = 'person';
            $query = array_merge(parent::parse($segments), $query);
            unset($query['id']);
        } else {
            if (preg_match('/tokens\/.*/', $path)) {
                $query['view'] = 'token';
                $query['id'] = array_pop($segments);
            } else {
                $query = parent::parse($segments);
            }
        }

        return $query;
    }
90346
private static function parse($url)
    {
        $enc_url = preg_replace_callback(
            '%[^:/@?&=#]+%usD',
            function ($matches) {
                return rawurlencode($matches[0]);
            },
            $url
        );

        $parts = parse_url($enc_url);

        if ($parts === false) {
            throw new \InvalidArgumentException('Malformed URL: ' . $url);
        }

        if (!empty($parts['scheme']) && !in_array($parts['scheme'], ['http', 'https', 'data'])) {
            throw new \InvalidArgumentException(sprintf('Invalid URL scheme: "%s"', $parts['scheme']));
        }

        foreach ($parts as $name => $value) {
            $parts[$name] = rawurldecode($value);
        }
        return $parts;
    }
338469
public function marketRequest($segment, array $parameters=[]) {
        $baseUrl = $this->market_url;
        return $this->privateRequest($baseUrl, $segment, $parameters);
    }
924896
public static function MakeNumberSegments($segments)
	{
		$NumberSegments = [];

		foreach ($segments as $segment)
		{
			$NumberSegments[] = new NumberSegment($segment);
		}

		return $NumberSegments;
	}
340664
protected function segmentMatches($urlSegment, $pathSegment)
    {
        $result = false;
        $realUrlSegment = $urlSegment;

        foreach ($this->getUrlSegmentVoters() as $urlSegmentVoter) {
            $urlSegmentVoter->setUrlSegment($urlSegmentVoter->transformSegment($urlSegment));
            $urlSegmentVoter->setPathSegment($pathSegment);

            if ($urlSegmentVoter->vote() === VoteResult::NO) {
                $result = false;
            }

            if ($urlSegmentVoter->vote() === VoteResult::YES) {
                $result = true;
                $realUrlSegment = $urlSegmentVoter->transformSegment($urlSegment);
            }
        }

        return $result ? $realUrlSegment : false;
    }
1241182
public function getData($segments){
		$data=new stdClass;
		$data->error=-1;
		//Check privileges.
		$bau=BAdminUsers::getInstance();

		$data->can_view=$bau->can($this->accessgroup,$this->access_view);
		$data->can_edit=$bau->can($this->accessgroup,$this->access_edit);
		if((!$data->can_view)&&(!$data->can_edit)){
			$data->error=ERR_LOW_PRIVS;
			return $data;
			}
		//Create item
		$data->item=new $this->itemclass();
		//Get Additional data.
		$this->getfilterdata($data);
		//
		$data->do=BRequest::getString('do');
		$data->saving=(($data->do=='save')||($data->do=='save_exit'));
		$this->fieldsval=array();
		if(($data->saving)&&($data->can_edit)){
			if(!$this->itemsetfields($data->item)){
				$data->errors=$this->errors;
				$data->warnings=$this->warnings;
				$data->error=2;
				return $data;
				}
			$data->fieldsval=$this->fieldsval;
			if(empty($this->errors)){
				$r=$data->item->saveToDB();
				if($r){
					$this->itemaftersave($data->item,$data);
					$data->redirect=$this->generateitemredirect($data->item);
					if($data->do=='save_exit'){
						$data->redirect=$this->url_exit;
						}
					}
				}
			}
		//
		$data->error=0;
		$data->errors=$this->errors;
		$data->warnings=$this->warnings;
		return $data;
		}
335051
public function localeFromRequest($segment = 0)
    {
        $url = $this->request->getUri();
        return $this->getLocaleFromUrl($url, $segment);
    }
928824
public function parse($schema)
    {
        $fields = $this->splitIntoFields($schema);

        foreach ($fields as $field) {
            $segments = $this->parseSegments($field);

            $this->addField($segments);
        }

        return $this->schema;
    }
1180595
protected function filterFragment($fragment)
    {
        $fragment = preg_replace_callback(
            '/(?:[^' . self::CHARACTERS_UNRESERVED . self::CHARACTERS_SUB_DELIMS . '%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
            function ($match) {
                return rawurlencode($match[0]);
            },
            $fragment
        );

        if (is_null($fragment)) {
            throw new InvalidArgumentException(sprintf('Invalid fragment "%s".', $fragment));
        } elseif (!$fragment) {
            $fragment = '';
        }

        if (substr($fragment, 0, 1) === '#') {
            $fragment = substr($fragment, 1);
        }

        return $fragment;
    }
1769
protected function processSegments(array $segments)
    {
        $this->segments = [];

        foreach ($segments as $segment) {
            $this->segments[] = $segment->traverse($this);
        }

        return $this->segments;
    }
674991
public function accountRequest($segment, array $parameters=[]) {
        $baseUrl = $this->account_url;
        return $this->privateRequest($baseUrl, $segment, $parameters);
    }
1217619
public function getLocaleFromRoute($segments = null) {
        // if segmets are not set - get from current request
        if (is_null($segments)) {
            $segments = \Request::segments();
        }
        $locale = $this->getDefaultRoutelocale();
        if ($allLocales = \Routelocale::getAllRoutelocales()) {
            // reduce array of segments to [0] and find by value
            if ($curLocaleIndex = array_search(array_shift($segments), $allLocales)) {
                $locale = $allLocales[$curLocaleIndex];
            }  
        }
        return $locale;
    }
1343918
public function append($segment)
    {
        $segments = is_array($segment) ? $segment : func_get_args();

        return $this->replicate(['path' => $this->path->copy()->extend($segments)]);
    }