Search by

atatusoft / cli-bootstrap

amasiye

Dependency-scoped Composer startup for command-line tools.

Package info

github.com/atatusoft-ltd/cli-bootstrap

pkg:composer/atatusoft/cli-bootstrap

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-11-30 09:11 UTC

This package is auto-updated.

Last update: 2026-12-01 20:12:09 UTC


README

Start a Composer-distributed command-line tool with its own runtime dependencies, without running the consuming application's autoloader.

Installation

composer require atatusoft/cli-bootstrap

Requires PHP 8.4 or later and Composer 2.2 or later.

Usage

In the tool's entrypoint, include the package's bootstrap.php, then load the tool's dependency graph before registering any other autoloader:

require $vendorDirectory . '/atatusoft/cli-bootstrap/bootstrap.php';
Atatusoft\CliBootstrap\Bootstrap::load($toolRoot, $vendorDirectory);

$toolRoot is the tool's installed package directory and $vendorDirectory is the Composer dependency directory it was installed into. Both identify the running installation; the working directory never selects code.

load() returns a Runtime. Its unregister() method removes the class-loading callback. Classes and functions that PHP has already loaded cannot be unloaded.

What It Loads

The package graph comes from Composer 2 installed.json and the tool's own manifest. Development dependencies and unrelated application packages are excluded. Composer's class loader handles PSR-4, PSR-0 and generated classmaps. Declared dependency startup files keep their Composer-generated order. Installed version information remains available to the tool.

For an installed tool, its recorded location, version and installation reference must agree before its runtime dependencies are read from its manifest. Reference checks follow Composer's selection for source and distribution installations. Dependency versions, provider ranges and self.version replacements are checked, and platform requirements are verified against the running PHP. A missing or ambiguous provider fails explicitly.

What It Never Runs

Generated Composer array metadata is parsed as data. The parser accepts Composer's literal arrays and path expressions and rejects executable statements. The application's autoload.php, autoload_real.php, plugins and scripts are never executed. Startup runs no dependency solver, downloads, generated application copies or persistent caches.

The scoped loader rejects class paths outside the selected packages' declared runtime paths, including symbolic links that escape them. Optimized namespace entries must match the package's namespace rule; explicit classmap paths keep classmap behaviour.

Limits

  • load() permits one startup attempt per process. A repeated attempt, including after a failed startup or unregister(), fails before changing runtime state.
  • Startup fails if another autoloader is already registered.
  • Tool dependencies remain trusted executable code. This library provides no process isolation from malicious installed dependencies or a compromised PHP installation.
  • A tool that deliberately starts the application later remains responsible for that step.

License

Apache License 2.0. See LICENSE.