fix(php): add PHP version validation for Phpactor

Check that the installed PHP version is >= 8.1 before proceeding with
Phpactor setup. Raises RuntimeError with a clear message if the version
is too old, and logs a warning if the version string cannot be parsed.

Addresses review comment on PR #1002.
This commit is contained in:
takeokunn committed 2026-02-08 01:03:04 +09:00
1 parent 65c24a0df8
commit d39967dd67
1 file changed
+14
+14
View File
@@ -5,8 +5,10 @@ Provides PHP specific instantiation of the LanguageServer class using Phpactor.
import logging
import os
import pathlib
import re
import shutil
import stat
import subprocess
from overrides import override
@@ -48,6 +50,18 @@ class PhpactorServer(SolidLanguageServer):
php_path is not None
), "PHP is not installed or not found in PATH. Phpactor requires PHP 8.1+. Please install PHP and try again."
# Check PHP version (Phpactor requires PHP 8.1+)
result = subprocess.run(["php", "--version"], capture_output=True, text=True, check=False)
php_version_output = result.stdout.strip()
log.info(f"PHP version: {php_version_output}")
version_match = re.search(r"PHP (\d+)\.(\d+)", php_version_output)
if version_match:
major, minor = int(version_match.group(1)), int(version_match.group(2))
if major < 8 or (major == 8 and minor < 1):
raise RuntimeError(f"PHP {major}.{minor} detected, but Phpactor requires PHP 8.1+. Please upgrade PHP.")
else:
log.warning("Could not parse PHP version from output. Continuing anyway.")
phpactor_phar_path = os.path.join(self._ls_resources_dir, "phpactor.phar")
if not os.path.exists(phpactor_phar_path):
os.makedirs(self._ls_resources_dir, exist_ok=True)