PHPackages                             php-tuf/composer-stager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. php-tuf/composer-stager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

php-tuf/composer-stager
=======================

Stages Composer commands so they can be safely run on a production codebase.

v2.1.0(3mo ago)173.5M—1.6%11[22 issues](https://github.com/php-tuf/composer-stager/issues)2MITPHPPHP &gt;=8.1.0CI passing

Since Jun 30Pushed 2mo ago6 watchersCompare

[ Source](https://github.com/php-tuf/composer-stager)[ Packagist](https://packagist.org/packages/php-tuf/composer-stager)[ Docs](https://github.com/php-tuf/composer-stager)[ RSS](/packages/php-tuf-composer-stager/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (41)Used By (2)

Composer Stager
===============

[](#composer-stager)

[![Latest stable version](https://camo.githubusercontent.com/1ce3ceeaef9f093eb166aacd008f72979ed9e84f784351a60f8987e4922b5d99/68747470733a2f2f706f7365722e707567782e6f72672f7068702d7475662f636f6d706f7365722d7374616765722f762f737461626c65)](https://packagist.org/packages/php-tuf/composer-stager)[![Tests status](https://github.com/php-tuf/composer-stager/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/php-tuf/composer-stager/actions/workflows/main.yml)[![Coverage](https://camo.githubusercontent.com/166698b2f7a300c68e3c2b1dac8973f0e6f3dfa0456cb8896245ed71395baba8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d3130302532352d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/php-tuf/composer-stager/actions/workflows/main.yml) [![PHPStan](https://camo.githubusercontent.com/c900c36226ce5c3f53590febf222d81ad8bb39a391eda5e89b4b258c713bcc2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6d61782d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

Composer Stager makes long-running Composer commands safe to run on a codebase in production by "staging" them--performing them on a non-live copy of the codebase and syncing back the result for the least possible downtime.

- [Whom is it for?](#whom-is-it-for)
- [Why is it needed?](#why-is-it-needed)
- [Installation](#installation)
- [Usage](#usage)
- [Configuring services](#configuring-services)
- [Example](#example)
- [Contributing](#contributing)

Whom is it for?
---------------

[](#whom-is-it-for)

Composer Stager enables PHP products and frameworks (like [Drupal](https://drupal.org/)) to provide automated Composer-based self-updates for users without access to more robust solutions like [staged](https://en.wikipedia.org/wiki/Development,_testing,_acceptance_and_production) and [blue-green](https://martinfowler.com/bliki/BlueGreenDeployment.html) deployments--on restrictive or low-cost hosting, for example, or with little or no budget or development staff. It could conceivably be used with custom Composer-based apps, as well. It is not intended for end users.

Why is it needed?
-----------------

[](#why-is-it-needed)

It may not be obvious at first that a tool like this is really necessary. Why not just use Composer in-place? Or why not just rsync files out and back? It turns out that the problem is incredibly complex, and the edge cases are myriad:

- You can't use Composer directly on a live codebase, because long-running commands put it in an unknown in-between state, and failures can irrecoverably corrupt it. The only safe option is to copy it elsewhere, run the commands there, and sync the result back to the live version. But...
- You may not have write access to directories outside the codebase--especially on low end shared hosting--so you must provide a (more complicated) alternative strategy using a subdirectory of the live codebase.
- You can't assume the availability of such tools as rsync, so you must provide detection and fallback capabilities.
- There are lots of cross-platform issues, including Unix vs. Windows paths, process execution peculiarities, disabled PHP functions, and symlink support, to name a few.
- Symlinks represent a problem space unto themselves, with as many logical issues as technical ones.
- Error messages must be translatable (i18n/l10n).
- You have to account for non-code files, like user uploads, cache files, and logs that may be changed in the live codebase while Composer commands are being run on the copy and could be clobbered when syncing it back.
- Failure to handle any of these challenges can easily have catastrophic results, including data loss or complete destruction of a live codebase. You need to anticipate and prevent them and provide actionable user feedback.

The list could go on. It should be obvious by now that a dedicated library is warranted.

Installation
------------

[](#installation)

The library is installed via Composer:

```
composer require php-tuf/composer-stager
```

Usage
-----

[](#usage)

It is invoked via its PHP API. Given a configured service container ([see below](#configuring-services)), its services can be used like the following, for example:

```
class Updater
{
    public function __construct(
        private readonly BeginnerInterface $beginner,
        private readonly StagerInterface $stager,
        private readonly CommitterInterface $committer,
        private readonly CleanerInterface $cleaner,
        private readonly PathFactoryInterface $pathFactory,
        private readonly PathListFactoryInterface $pathListFactory,
    ) {
    }

    public function update(): void
    {
        $activeDir = $this->pathFactory->create('/var/www/public');
        $stagingDir = $this->pathFactory->create('/var/www/staging');
        $exclusions = $this->pathListFactory->create(
            'cache',
            'uploads',
        );

        // Copy the codebase to the staging directory.
        $this->beginner->begin($activeDir, $stagingDir, $exclusions);

        // Run a Composer command on it.
        $this->stager->stage([
            'require',
            'example/package',
            '--update-with-all-dependencies',
        ], $activeDir, $stagingDir);

        // Sync the changes back to the active directory.
        $this->committer->commit($stagingDir, $activeDir, $exclusions);

        // Remove the staging directory.
        $this->cleaner->clean($stagingDir);
    }
}
```

Configuring services
--------------------

[](#configuring-services)

Composer Stager uses the [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) pattern, and its services are best accessed via a container that supports autowiring, e.g., [Symfony's](https://symfony.com/doc/current/service_container.html). (Manual wiring is brittle and therefore not officially supported.) See [`services.yml`](services.yml) for a working example.

Example
-------

[](#example)

A complete, functioning example implementation of Composer Stager can be found in the [Composer Stager Console](https://github.com/php-tuf/composer-stager-console) repository.

Contributing
------------

[](#contributing)

[Pull requests](https://github.com/php-tuf/composer-stager/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc) are welcome. For major changes, please [open an issue](https://github.com/php-tuf/composer-stager/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) first to discuss what you would like to change. Observe [the coding standards](https://github.com/php-tuf/composer-stager/wiki/Coding-standards-&-style-guide), and if you're able, add and update [the tests](https://github.com/php-tuf/composer-stager/wiki/Automated-testing-&-analysis) as appropriate.

---

[More info in the Wiki.](https://github.com/php-tuf/composer-stager/wiki)

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance64

Regular maintenance activity

Popularity54

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 90.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Recently: every ~110 days

Total

35

Last Release

103d ago

Major Versions

v0.5.0 → v1.0.0-beta12022-06-10

v1.2.1 → v2.0.0-alpha12023-03-17

PHP version history (3 changes)v0.1.0PHP ^7.3 || ^8.0

v1.0.0-rc1PHP ^7.4 || ^8.0

v2.0.0-alpha1PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c55ed0dc1d2e7df0158d61a56358e5299a38cdcc3728d513ce335382de9b94fe?d=identicon)[TravisCarden](/maintainers/TravisCarden)

![](https://avatars.githubusercontent.com/u/132772?v=4)[Ted Bowman](/maintainers/tedbow)[@tedbow](https://github.com/tedbow)

![](https://www.gravatar.com/avatar/0871439f61a26650be59267f0ab5754402c46761fe89f9ba981162a597de3ace?d=identicon)[PHP-TUF](/maintainers/PHP-TUF)

---

Top Contributors

[![TravisCarden](https://avatars.githubusercontent.com/u/959246?v=4)](https://github.com/TravisCarden "TravisCarden (1798 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (182 commits)")[![phenaproxima](https://avatars.githubusercontent.com/u/4504530?v=4)](https://github.com/phenaproxima "phenaproxima (6 commits)")[![mstrelan](https://avatars.githubusercontent.com/u/665110?v=4)](https://github.com/mstrelan "mstrelan (1 commits)")[![longwave](https://avatars.githubusercontent.com/u/197817?v=4)](https://github.com/longwave "longwave (1 commits)")[![larowlan](https://avatars.githubusercontent.com/u/555254?v=4)](https://github.com/larowlan "larowlan (1 commits)")[![alexpott](https://avatars.githubusercontent.com/u/769634?v=4)](https://github.com/alexpott "alexpott (1 commits)")

---

Tags

composer

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/php-tuf-composer-stager/health.svg)

```
[![Health](https://phpackages.com/badges/php-tuf-composer-stager/health.svg)](https://phpackages.com/packages/php-tuf-composer-stager)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
