adachsoft/composer-lib
Composer 安装命令:
composer require adachsoft/composer-lib
包简介
Composer command library for non-interactive operations
README 文档
README
Library providing a high-level, non-interactive wrapper around Composer CLI. It is designed to be used from other PHP applications and tools that need to run Composer commands safely and programmatically.
Features
- Public API (
ComposerClientInterface) for executing Composer operations:installupdaterequire(asrequirePackages) – supportswithAllDependenciesoption (maps to--with-all-dependencies/-W)remove(asremovePackages)dump-autoloadvalidateoutdateddiagnoseshowlicensesdependsprohibitsrun-script(asrunScript)clear-cache(asclearCache)config(asconfig()) – new operation withConfigOptionsDtosupporting--global,--no-plugins,--unset,--list
- Non-interactive execution enforced by guards:
NonInteractiveGuard(adds flags and env vars like--no-interaction,CI=1)PromptDetector(detects interactive prompts in output and throws exception)
- Pluggable command execution via
CommandExecutorInterface - DTO-based configuration of all operations (options, execution policy, working directory, env vars)
Installation
Install via Composer:
composer require adachsoft/composer-lib
Basic Usage
Creating a client
The recommended way to get a ready-to-use client is the factory:
use AdachSoft\ComposerLib\PublicApi\Factory\ComposerClientFactory;
$client = ComposerClientFactory::create();
This will create:
- a default command executor based on
adachsoft/command-executor-lib - a default Composer configuration that runs the
composerbinary from yourPATH(no custom locator required) - non-interactive guard and prompt detector
If you need a custom executor (for logging, sandboxing, etc.), you can pass it:
use AdachSoft\ComposerLib\Infrastructure\Execution\CommandExecutorInterface;
use AdachSoft\ComposerLib\PublicApi\Factory\ComposerClientFactory;
/** @var CommandExecutorInterface $executor */
$client = ComposerClientFactory::create($executor);
Running operations
Each operation is configured by its own options DTO. Example for install:
use AdachSoft\ComposerLib\PublicApi\ComposerClientInterface;
use AdachSoft\ComposerLib\PublicApi\Dto\Enum\ConfigPatchModeEnum;
use AdachSoft\ComposerLib\PublicApi\Dto\Options\ConfigPatchPolicyDto;
use AdachSoft\ComposerLib\PublicApi\Dto\Options\ExecutionPolicyDto;
use AdachSoft\ComposerLib\PublicApi\Dto\Options\InstallOptionsDto;
use AdachSoft\ComposerLib\PublicApi\Dto\Value\WorkingDirectory;
/** @var ComposerClientInterface $client */
$workingDirectory = new WorkingDirectory('/path/to/project');
$executionPolicy = new ExecutionPolicyDto(
hardTimeoutSeconds: 60,
activityTimeoutSeconds: 30,
nonInteractiveEnforced: true,
);
$configPatchPolicy = new ConfigPatchPolicyDto(ConfigPatchModeEnum::PERMANENT);
$options = new InstallOptionsDto(
workingDirectory: $workingDirectory,
configPatchPolicy: $configPatchPolicy,
executionPolicy: $executionPolicy,
dev: true,
preferDist: true,
preferStable: true,
);
$result = $client->install($options);
if (!$result->success) {
// handle failure, inspect $result->stderr, $result->exitCode, etc.
}
Example for running a custom script via composer run-script:
use AdachSoft\ComposerLib\PublicApi\Dto\Options\ExecutionPolicyDto;
use AdachSoft\ComposerLib\PublicApi\Dto\Options\RunScriptOptionsDto;
use AdachSoft\ComposerLib\PublicApi\Dto\Value\WorkingDirectory;
$workingDirectory = new WorkingDirectory('/path/to/project');
$executionPolicy = new ExecutionPolicyDto(
hardTimeoutSeconds: 60,
activityTimeoutSeconds: 30,
nonInteractiveEnforced: true,
);
$options = new RunScriptOptionsDto(
workingDirectory: $workingDirectory,
executionPolicy: $executionPolicy,
script: 'my-script',
args: ['--flag', 'value'],
);
$result = $client->runScript($options);
Other operations (update, requirePackages, removePackages, dumpAutoload,
validate, outdated, diagnose, show, licenses, depends, prohibits,
runScript, clearCache, config) follow the same pattern with their respective
options DTOs. See ConfigOptionsDto for configuration of the new config() operation.
Non-Interactive Safety
This library is built to prevent accidental interactive Composer runs in CI or automated tools:
NonInteractiveGuardensures flags like--no-interactionand appropriate environment variables are always present.PromptDetectorscans stdout/stderr and throwsNonInteractiveViolationExceptionwhen it detects likely interactive prompts (e.g. "Do you want to continue?", "[y/N]", etc.).
Command Execution Abstraction
The infrastructure layer defines its own CommandExecutorInterface and ships
an adapter for adachsoft/command-executor-lib:
AdachSoft\ComposerLib\Infrastructure\Execution\CommandExecutorInterfaceAdachSoft\ComposerLib\Infrastructure\Execution\AdachsoftCommandExecutorAdapter
Composer processes inherit the base PHP environment (such as HOME and
COMPOSER_HOME) and their environment is extended or overridden by values
coming from the EnvVarMap DTO passed to operations.
You can provide your own implementation of CommandExecutorInterface if you
need to control how processes are spawned, logged or sandboxed.
Testing
The project ships with:
- unit tests for guards, operations, DTO collections, infrastructure
- a functional test that exercises the full public API against a temporary fixture project
To run tests:
vendor/bin/phpunit
To run static analysis:
composer stan
To check or fix code style:
composer cs:check
composer cs:fix
License
This library is released under the MIT License.
adachsoft/composer-lib 适用场景与选型建议
adachsoft/composer-lib 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「composer」 「composer-lib」 「non-interactive」 「command-executor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adachsoft/composer-lib 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adachsoft/composer-lib 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adachsoft/composer-lib 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Simple ASCII output of array data
Generate a Composer repository from installed WordPress plugins and themes.
An image upload package which provides lot of functions such as upload, resize, crop, rotate, delete.
PHPUnit Pretty Result Printer
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-09