You are here

private function PharInvocationResolver::resolveBaseName in Drupal 7

Parameters

string $path:

int $flags:

Return value

null|string

1 call to PharInvocationResolver::resolveBaseName()
PharInvocationResolver::resolve in misc/typo3/phar-stream-wrapper/src/Resolver/PharInvocationResolver.php
Resolves PharInvocation value object (baseName and optional alias).

File

misc/typo3/phar-stream-wrapper/src/Resolver/PharInvocationResolver.php, line 117

Class

PharInvocationResolver

Namespace

TYPO3\PharStreamWrapper\Resolver

Code

private function resolveBaseName($path, $flags) {
  $baseName = $this
    ->findInBaseNames($path);
  if ($baseName !== null) {
    return $baseName;
  }
  $baseName = Helper::determineBaseFile($path);
  if ($baseName !== null) {
    $this
      ->addBaseName($baseName);
    return $baseName;
  }
  $possibleAlias = $this
    ->resolvePossibleAlias($path);
  if (!($flags & static::RESOLVE_ALIAS) || $possibleAlias === null) {
    return null;
  }
  $trace = debug_backtrace();
  foreach ($trace as $item) {
    if (!isset($item['function']) || !isset($item['args'][0]) || !in_array($item['function'], $this->invocationFunctionNames, true)) {
      continue;
    }
    $currentPath = $item['args'][0];
    if (Helper::hasPharPrefix($currentPath)) {
      continue;
    }
    $currentBaseName = Helper::determineBaseFile($currentPath);
    if ($currentBaseName === null) {
      continue;
    }

    // ensure the possible alias name (how we have been called initially) matches
    // the resolved alias name that was retrieved by the current possible base name
    try {
      $reader = new Reader($currentBaseName);
      $currentAlias = $reader
        ->resolveContainer()
        ->getAlias();
    } catch (ReaderException $exception) {

      // most probably that was not a Phar file
      continue;
    }
    if (empty($currentAlias) || $currentAlias !== $possibleAlias) {
      continue;
    }
    $this
      ->addBaseName($currentBaseName);
    return $currentBaseName;
  }
  return null;
}