Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Common.php

function Common::realpath

CodeSniffer alternative for realpath.

Allows for PHAR support.

Parameters

string $path The path to use.:

Return value

string|false

14 calls to Common::realpath()
Cache::load in vendor/squizlabs/php_codesniffer/src/Util/Cache.php
Loads existing cache data for the run, if any.
Config::processFilePath in vendor/squizlabs/php_codesniffer/src/Config.php
Processes a file path and add it to the file list.
Config::processLongArgument in vendor/squizlabs/php_codesniffer/src/Config.php
Processes a long (--example) command-line argument.
ExactMatch::accept in vendor/squizlabs/php_codesniffer/src/Filters/ExactMatch.php
Check whether the current element of the iterator is acceptable.
Filter::accept in vendor/squizlabs/php_codesniffer/src/Filters/Filter.php
Check whether the current element of the iterator is acceptable.

... See full list

File

vendor/squizlabs/php_codesniffer/src/Util/Common.php, line 91

Class

Common

Namespace

PHP_CodeSniffer\Util

Code

public static function realpath($path) {
    // Support the path replacement of ~ with the user's home directory.
    if (substr($path, 0, 2) === '~/') {
        $homeDir = getenv('HOME');
        if ($homeDir !== false) {
            $path = $homeDir . substr($path, 1);
        }
    }
    // Check for process substitution.
    if (strpos($path, '/dev/fd') === 0) {
        return str_replace('/dev/fd', 'php://fd', $path);
    }
    // No extra work needed if this is not a phar file.
    if (self::isPharFile($path) === false) {
        return realpath($path);
    }
    // Before trying to break down the file path,
    // check if it exists first because it will mostly not
    // change after running the below code.
    if (file_exists($path) === true) {
        return $path;
    }
    $phar = Phar::running(false);
    $extra = str_replace('phar://' . $phar, '', $path);
    $path = realpath($phar);
    if ($path === false) {
        return false;
    }
    $path = 'phar://' . $path . $extra;
    if (file_exists($path) === true) {
        return $path;
    }
    return false;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal