Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Failing after 10m14s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Has been skipped
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Failing after 11m25s
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
- Remove middleware reference from Gitea Traefik labels (caused routing issues) - Optimize Gitea connection pool settings (MAX_IDLE_CONNS=30, authentication_timeout=180s) - Add explicit service reference in Traefik labels - Fix intermittent 504 timeouts by improving PostgreSQL connection handling Fixes Gitea unreachability via git.michaelschiemer.de
112 lines
3.3 KiB
PHP
112 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Console\Terminal;
|
|
|
|
/**
|
|
* Detects PhpStorm/JetBrains terminal environment
|
|
*
|
|
* Provides utilities for PhpStorm-specific terminal features like
|
|
* clickable file links and project root detection.
|
|
*/
|
|
final readonly class PhpStormDetector
|
|
{
|
|
/**
|
|
* Check if running in PhpStorm/JetBrains terminal
|
|
*/
|
|
public static function isPhpStorm(): bool
|
|
{
|
|
// Check TERMINAL_EMULATOR environment variable
|
|
$terminalEmulator = getenv('TERMINAL_EMULATOR');
|
|
if ($terminalEmulator !== false && $terminalEmulator === 'JetBrains-JediTerm') {
|
|
return true;
|
|
}
|
|
|
|
// Check IDE_PROJECT_ROOTS (set by PhpStorm/IntelliJ)
|
|
$ideProjectRoots = getenv('IDE_PROJECT_ROOTS');
|
|
if ($ideProjectRoots !== false && $ideProjectRoots !== '') {
|
|
return true;
|
|
}
|
|
|
|
// Check TERM for jetbrains-related values
|
|
$term = getenv('TERM');
|
|
if ($term !== false && str_contains(strtolower($term), 'jetbrains')) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get project root paths from IDE_PROJECT_ROOTS
|
|
*
|
|
* @return array<string> Array of project root paths, or empty array if not available
|
|
*/
|
|
public static function getProjectRoots(): array
|
|
{
|
|
$ideProjectRoots = getenv('IDE_PROJECT_ROOTS');
|
|
if ($ideProjectRoots === false || $ideProjectRoots === '') {
|
|
return [];
|
|
}
|
|
|
|
// IDE_PROJECT_ROOTS is typically a colon-separated list (Unix) or semicolon-separated (Windows)
|
|
$separator = str_contains($ideProjectRoots, ';') ? ';' : ':';
|
|
$roots = explode($separator, $ideProjectRoots);
|
|
|
|
// Filter out empty values and normalize paths
|
|
return array_filter(
|
|
array_map('trim', $roots),
|
|
fn(string $root) => $root !== '' && is_dir($root)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Convert absolute file path to relative path based on project roots
|
|
*
|
|
* If PhpStorm is detected and project roots are available, returns the shortest
|
|
* relative path. Otherwise returns the absolute path.
|
|
*
|
|
* @param string $filePath Absolute file path
|
|
* @return string Relative path if project root found, otherwise absolute path
|
|
*/
|
|
public static function getRelativePath(string $filePath): string
|
|
{
|
|
if (!self::isPhpStorm()) {
|
|
return $filePath;
|
|
}
|
|
|
|
$projectRoots = self::getProjectRoots();
|
|
if (empty($projectRoots)) {
|
|
return $filePath;
|
|
}
|
|
|
|
$filePath = realpath($filePath);
|
|
if ($filePath === false) {
|
|
return $filePath;
|
|
}
|
|
|
|
$shortestPath = $filePath;
|
|
$shortestLength = strlen($filePath);
|
|
|
|
foreach ($projectRoots as $root) {
|
|
$root = realpath($root);
|
|
if ($root === false) {
|
|
continue;
|
|
}
|
|
|
|
// Check if file is within this project root
|
|
if (str_starts_with($filePath, $root . DIRECTORY_SEPARATOR) || $filePath === $root) {
|
|
$relative = substr($filePath, strlen($root) + 1);
|
|
if (strlen($relative) < $shortestLength) {
|
|
$shortestPath = $relative;
|
|
$shortestLength = strlen($relative);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $shortestPath;
|
|
}
|
|
}
|
|
|