public static function ensureProjectBinDirInSystemPath(string $binDir)
    {
        $pathStr = 'PATH';
        if (!isset($_SERVER[$pathStr]) && isset($_SERVER['Path'])) {
            $pathStr = 'Path';
        }

        if (!is_dir($binDir)) {
            return;
        }

        // add the bin dir to the PATH to make local binaries of deps usable in scripts
        $binDir = realpath($binDir);
        $hasBindDirInPath = preg_match(
            '{(^|'.PATH_SEPARATOR.')'.preg_quote($binDir).'($|'.PATH_SEPARATOR.')}',
            $_SERVER[$pathStr]
        );

        if (!$hasBindDirInPath && isset($_SERVER[$pathStr])) {
            $_SERVER[$pathStr] = $binDir.PATH_SEPARATOR.getenv($pathStr);
            putenv($pathStr.'='.$_SERVER[$pathStr]);
        }
    }