atatusoft / cli-bootstrap
Dependency-scoped Composer startup for command-line tools.
Requires
- php: ^8.4
- composer-runtime-api: ^2.2
- composer/semver: ^3.4
Requires (Dev)
- phpunit/phpunit: ^13.3
- symfony/process: ^8.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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 orunregister(), 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.