You are here

protected static function UrlBag::getUriPart in Mini site 8

Get a part from the provided URI.

Parameters

string $uri: The URI to assess. Note that URI must have UUID-like string.

int $part_name: One of the part constants from this class.

Return value

string URI part.

Throws

\Drupal\minisite\Exception\UrlBagException If incorrectly formatted URI provided.

3 calls to UrlBag::getUriPart()
UrlBag::getAssetDir in src/UrlBag.php
Get asset directory.
UrlBag::getPathInArchive in src/UrlBag.php
Get path in the archive.
UrlBag::getRootDir in src/UrlBag.php
Get root directory.

File

src/UrlBag.php, line 315

Class

UrlBag
Class UrlBag.

Namespace

Drupal\minisite

Code

protected static function getUriPart($uri, $part_name) {
  $parts = preg_split('/([a-f0-9]{8}\\-[a-f0-9]{4}\\-4[a-f0-9]{3}\\-(?:8|9|a|b)[a-f0-9]{3}\\-[a-f0-9]{12})/', $uri, -1, PREG_SPLIT_DELIM_CAPTURE);
  if (!$parts || count($parts) != 3) {
    throw new UrlBagException('Invalid URI provided');
  }
  $tail = array_pop($parts);
  $tail_parts = array_filter(explode('/', $tail));
  $parts[] = array_shift($tail_parts);
  $parts[] = implode('/', $tail_parts);
  if ($part_name == self::URI_PART_ASSET_DIR) {
    return $parts[0] . $parts[1];
  }
  if ($part_name == self::URI_PART_ROOT_ARCHIVE_DIR) {
    return ltrim($parts[2], '/');
  }
  if ($part_name == self::URI_PART_PATH_IN_ARCHIVE) {
    return ltrim($parts[3], '/');
  }
  if ($part_name == self::URI_PART_BASENAME) {
    return basename($parts[3]);
  }
}