Search by

adachsoft / php-interpreter-resolver

Arkadiusz Adach

Lists available PHP interpreters and resolves binary paths for logical PHP versions.

Package info

gitlab.com/a.adach/php-interpreter-resolver

Issues

pkg:composer/adachsoft/php-interpreter-resolver

Statistics

Installs: 57

Dependents: 3

Suggesters: 0

Stars: 0

v0.1.0 2026-11-27 14:35 UTC

This package is auto-updated.

Last update: 2026-11-27 13:35:19 UTC


README

A PHP library for listing available PHP interpreters and resolving an interpreter binary path for a logical PHP version.

Features

  • Lists PHP versions configured through update-alternatives.
  • Resolves a logical version such as 8.3 or 8.3.1 to its interpreter binary path.
  • Keeps interpreter paths out of the public version DTO and collection.
  • Uses adachsoft/command-executor-lib as the process-execution boundary.

Requirements

  • PHP 8.3 or higher.
  • The update-alternatives command configured with PHP interpreter alternatives.
  • adachsoft/command-executor-lib ^2.0.
  • adachsoft/collection ^3.0.

Installation

composer require adachsoft/php-interpreter-resolver

Usage

Create the resolver through PhpInterpreterResolverFactory and provide a command executor and working directory:

<?php

declare(strict_types=1);

use AdachSoft\CommandExecutorLib\SimpleCommandExecutor;
use AdachSoft\PhpInterpreterResolver\PhpInterpreterResolverFactory;

$commandExecutor = new SimpleCommandExecutor();
$resolver = PhpInterpreterResolverFactory::create($commandExecutor, __DIR__);

foreach ($resolver->listAvailableVersions() as $phpVersion) {
    printf(
        '%s%s',
        $phpVersion->version,
        $phpVersion->isCurrent ? ' (current)' : '',
    );
    echo PHP_EOL;
}

$binaryPath = $resolver->resolveBinaryPath('8.3');

The returned binary path is intended for runner integrations. Do not expose it to end users when it is not part of the consuming application's interface.

See Basic usage for another example.

Exceptions

The resolver throws PhpInterpreterResolverException when a requested version has an invalid format, is unavailable, or the alternatives query fails. Its getCode() value can be compared with CODE_INVALID_VERSION, CODE_VERSION_NOT_AVAILABLE, or CODE_EXECUTION_FAILED.

<?php

use AdachSoft\PhpInterpreterResolver\Exception\PhpInterpreterResolverException;

try {
    $binaryPath = $resolver->resolveBinaryPath('8.3');
} catch (PhpInterpreterResolverException $exception) {
    // Handle the stable library error code without exposing internal command details.
    error_log((string) $exception->getCode());
}