Parse Mapbox parts

@param array $parts
966588
private function _mapbox (array $parts)
	{
		$parts = array_reduce(
			$parts,
			function ($a, $part) {
				$key = explode('.', $part['id'])[0];
				$a[$key] = $part['text'];

				return $a;
			},
			[
				'number' => $parts['address'],
				$parts['place_type'][0] => $parts['text'],
			]
		);

		$this->number   = $parts['number'];
		$this->address  = $parts['address'];
		$this->city     = $parts['city'];
		$this->postcode = $parts['postcode'];
		$this->county   = $parts['county'];
		$this->state    = $parts['state'];
		$this->country  = $parts['country'];
	}
1094536
final public function createAbstractClazzFromStringArray(array $parts) : AbstractClazz
    {
        return new AbstractClazz(
            $this->extractClazzPart($parts),
            new Namespaze($this->extractNamespaceParts($parts))
        );
    }
54996
public static function buildUrl(array $parts)
    {
        $scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
        $host = isset($parts['host']) ? $parts['host'] : '';
        $port = isset($parts['port']) ? ':' . $parts['port'] : '';
        $user = isset($parts['user']) ? $parts['user'] : '';
        $pass = isset($parts['pass']) ? ':' . $parts['pass'] : '';
        $pass = ($user || $pass) ? "$pass@" : '';
        $path = isset($parts['path']) ? $parts['path'] : '';
        $query = isset($parts['query']) ? '?' . $parts['query'] : '';
        $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
    }
123848
protected function dataArrayGet(array $array, array $parts, $default = null)
    {
        if ($parts === null) {
            return $array;
        }

        if (count($parts) === 1) {
            $key = array_shift($parts);
            if (isset($array[$key])) {
                return $array[$key];
            }

            return $default;
        }

        foreach ($parts as $segment) {
            if (!is_array($array) || !array_key_exists($segment, $array)) {
                return $default;
            }

            $array = $array[$segment];
        }

        return $array;
    }
134935
public function map(array $parts): array
    {
        if ($this->isMatchingSinglePart($parts)) {
            $parts[0] = new Suffix($parts[0], $this->suffixes[$this->getKey($parts[0])]);
            return $parts;
        }

        $start = count($parts) - 1;

        for ($k = $start; $k > 1; $k--) {
            $part = $parts[$k];

            if (!$this->isSuffix($part)) {
                break;
            }

            $parts[$k] = new Suffix($part, $this->suffixes[$this->getKey($part)]);
        }

        return $parts;
    }
466010
protected static function tokenize( array $parts ) {
		$tokens = [];
		$index  = 0;

		foreach ( $parts as $part ) {
			if ( \preg_match( self::_RE_SPACE, $part ) ) {
				$tokens[ $index ] = new Token( $part, Token::SPACE );
			} elseif ( \preg_match( self::_RE_PUNCTUATION, $part ) ) {
				$tokens[ $index ] = new Token( $part, Token::PUNCTUATION );
			} elseif ( \preg_match( self::_RE_WORD, $part ) ) {
				// Make sure that things like email addresses and URLs are not broken up
				// into words and punctuation not preceeded by an 'other'.
				self::parse_ambiguous_token( Token::WORD, $part, $tokens, $index );
			} else {
				// Make sure that things like email addresses and URLs are not broken up into words
				// and punctuation not preceeded by an 'other' or 'word'.
				self::parse_ambiguous_token( Token::OTHER, $part, $tokens, $index );
			}

			$index++;
		}

		return $tokens;
	}
131532
protected function parseMappings()
    {
        $this->mappedAttributes = [];

        foreach ($this->getMaps() as $attribute => $mapping) {
            if (is_array($mapping)) {
                $this->parseImplicitMapping($mapping, $attribute);
            } else {
                $this->mappedAttributes[$attribute] = $mapping;
            }
        }
    }
647732
protected function convertNamedParams($parts, $args) {
		if (empty($args)) return array($parts, $args);
		$params = array();
		$pos = 0;
		foreach ($parts as &$part) {
			if (preg_match('/:\w+/i', $part, $match)) {
				if (!array_key_exists($match[0],$args))
					trigger_error(sprintf(self::E_MISSINGBINDKEY,
						$match[0]),E_USER_ERROR);
				$part = str_replace($match[0], '?', $part);
				$params[] = $args[$match[0]];
			} elseif (is_int(strpos($part, '?')))
				$params[] = $args[$pos++];
			unset($part);
		}
		return array($parts, $params);
	}
968784
public function toString(array $parts = array('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'))
	{
		// Make sure the query is created
		$query = $this->getQuery();

		$uri = '';
		$uri .= in_array('scheme', $parts) ? (!empty($this->scheme) ? $this->scheme . '://' : '') : '';
		$uri .= in_array('user', $parts) ? $this->user : '';
		$uri .= in_array('pass', $parts) ? (!empty($this->pass) ? ':' : '') . $this->pass . (!empty($this->user) ? '@' : '') : '';
		$uri .= in_array('host', $parts) ? $this->host : '';
		$uri .= in_array('port', $parts) ? (!empty($this->port) ? ':' : '') . $this->port : '';
		$uri .= in_array('path', $parts) ? $this->path : '';
		$uri .= in_array('query', $parts) ? (!empty($query) ? '?' . $query : '') : '';
		$uri .= in_array('fragment', $parts) ? (!empty($this->fragment) ? '#' . $this->fragment : '') : '';

		return $uri;
	}
477652
public function map(array $parts): array
    {
        $last = count($parts) - 1;

        foreach ($parts as $k => $part) {
            if ($part instanceof AbstractPart) {
                continue;
            }

            if (!$this->matchLastPart && $k === $last) {
                continue;
            }

            if ($this->isInitial($part)) {
                $parts[$k] = new Initial($part);
            }
        }

        return $parts;
    }
49277
protected function _buildRegexFromParsed(array $parts, $matchExact = null)
    {
        $regex = '';

        // [0 => ['_literal_' => 'localhost'], 1=>['_optional' => ..] ..]
        foreach ($parts as $parsed) {
            $definition_name  = key($parsed);
            $definition_value = $parsed[$definition_name];
            // $parsed can also have extra parsed data options
            // _parameter_ String(3) => tld \
            // tld String(4)         => .com
            switch ($definition_name) {
                case '_regex_':
                    $regex .= $definition_value;
                    break;
                case '_token_':
                case '_literal_':
                    $regex .= preg_quote($definition_value);
                    break;

                case '_parameter_':
                    $groupName = '?P<' . $definition_value . '>';

                    if (isset($parsed[$definition_value])) {
                        // Delimiter: localhost:port{{\d+}}
                        $regex .= '(' . $groupName . $parsed[$definition_value] . ')';
                    } else{
                        $regex .= '(' . $groupName . '[^.]+)';
                    }

                    break;

                case '_optional_':
                    $regex .= '(?:' . $this->_buildRegexFromParsed($definition_value, null) . ')?';
                    break;
            }
        }

        if ($matchExact !== null) {
            $regex = ( (bool) $matchExact )
                ? "(^{$regex}$)" ## exact match
                : "(^{$regex})"; ## only start with criteria "/pages[/other/paths]"
        }

        return $regex;
    }
717939
protected function parseRouteParam($part, $targetPart)
    {
        preg_match('/\[(d|s)(?:\:([0-9a-zA-Z]*))?\]/', $part, $matches);

        $value = null;
        
        // If the part is a data type we need this route parameter
        if ($matches[1] === 'd' && is_numeric($targetPart)) {
            // Transform the value into the correct data type
            $value = $targetPart * 1;
        } else if ($matches[1] === 's' && is_string($targetPart)) {
            $value = $targetPart;
        }
        
        $key = '';
        if (isset($matches[2])) {
            $key = $matches[2];
        }
        
        return [$key, $value];
    }
391238
public function map(array $parts): array
    {
        // If we don't expect a lastname, match a mimimum of 2 parts
        $minumumParts = ($this->mapWithoutLastname ? 2 : 3);

        if (count($parts) < $minumumParts) {
            return $parts;
        }

        $start = $this->findFirstMapped(Firstname::class, $parts);

        if (false === $start) {
            return $parts;
        }

        return $this->mapFrom($start, $parts);
    }
1012190
private function parseParameters(array $dsnParts): void
    {
        foreach ($dsnParts as $part) {
            $option = $this->splitKeyValuePair($part);

            $this->parameters[$option[0]] = $option[1];
        }
    }
982979
private function parseHostAndPath(array $locationParts): void
    {
        $path = $locationParts['path'] ?? '';
        $host = $locationParts['host'] ?? '';

        if ($this->getScheme() === 'file') {
            $this->path = $host . $path;
        } else {
            $this->host = $host;
            $this->path = $path;
        }
    }
982386
public function withArray(array $parts = null)
	{	//	WARNING: Cannot use ?? because we might want to set some parts explicity to null, eg. ['fragment' => null]
		//	UPDATE: we could do this: ['fragment' => '']
		$new = new static();
		$new->scheme	=	isset($parts['scheme'])		?	$parts['scheme']	:	$this->_scheme;
		$new->user		=	isset($parts['user'])		?	$parts['user']		:	$this->_user;
		$new->pass		=	isset($parts['pass'])		?	$parts['pass']		:	$this->_pass;
		$new->host		=	isset($parts['host'])		?	$parts['host']		:	$this->_host;
		$new->port		=	isset($parts['port'])		?	$parts['port']		:	$this->_port;
		$new->path		=	isset($parts['path'])		?	$parts['path']		:	$this->_path;
		$new->query		=	isset($parts['query'])		?	$parts['query']		:	$this->_query;
		$new->fragment	=	isset($parts['fragment'])	?	$parts['fragment']	:	$this->_fragment;
		return $new;
	}
26681
public function map(array $parts): array
    {
        $isEncapsulated = false;

        $regexp = $this->buildRegexp();

        $closingDelimiter = '';

        foreach ($parts as $k => $part) {
            if ($part instanceof AbstractPart) {
                continue;
            }

            if (preg_match($regexp, $part, $matches)) {
                $isEncapsulated = true;
                $part = substr($part, 1);
                $closingDelimiter = $this->delimiters[$matches[1]];
            }

            if (!$isEncapsulated) {
                continue;
            }

            if ($closingDelimiter === substr($part, -1)) {
                $isEncapsulated = false;
                $part = substr($part, 0, -1);
            }

            $parts[$k] = new Nickname(str_replace(['"', '\''], '', $part));
        }

        return $parts;
    }