PMA\libraries\Error::relPath PHP Метод

relPath() публичный статический Метод

prevent path disclosure in error message, and make users feel safe to submit error reports
public static relPath ( string $path ) : string
$path string path to be shorten
Результат string shortened path
    public static function relPath($path)
    {
        $dest = @realpath($path);
        /* Probably affected by open_basedir */
        if ($dest === FALSE) {
            return basename($path);
        }
        $Ahere = explode(DIRECTORY_SEPARATOR, realpath(__DIR__ . DIRECTORY_SEPARATOR . '..'));
        $Adest = explode(DIRECTORY_SEPARATOR, $dest);
        $result = '.';
        // && count ($Adest)>0 && count($Ahere)>0 )
        while (implode(DIRECTORY_SEPARATOR, $Adest) != implode(DIRECTORY_SEPARATOR, $Ahere)) {
            if (count($Ahere) > count($Adest)) {
                array_pop($Ahere);
                $result .= DIRECTORY_SEPARATOR . '..';
            } else {
                array_pop($Adest);
            }
        }
        $path = $result . str_replace(implode(DIRECTORY_SEPARATOR, $Adest), '', $dest);
        return str_replace(DIRECTORY_SEPARATOR . PATH_SEPARATOR, DIRECTORY_SEPARATOR, $path);
    }

Usage Example

Пример #1
0
 /**
  * Error handler to catch fatal errors when loading configuration
  * file
  *
  *
  * PMA_Config_fatalErrorHandler
  * @return void
  */
 public static function fatalErrorHandler()
 {
     if (!isset($GLOBALS['pma_config_loading']) || !$GLOBALS['pma_config_loading']) {
         return;
     }
     $error = error_get_last();
     if ($error === null) {
         return;
     }
     PMA_fatalError(sprintf('Failed to load phpMyAdmin configuration (%s:%s): %s', Error::relPath($error['file']), $error['line'], $error['message']));
 }
All Usage Examples Of PMA\libraries\Error::relPath