PHPackages                             phpnomad/update - 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. phpnomad/update

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

phpnomad/update
===============

1.0.2(3w ago)05.6k↓17.9%[2 PRs](https://github.com/phpnomad/update/pulls)2MITPHPCI passing

Since Dec 18Pushed 3w ago2 watchersCompare

[ Source](https://github.com/phpnomad/update)[ Packagist](https://packagist.org/packages/phpnomad/update)[ Docs](https://github.com/phpnomad/update)[ RSS](/packages/phpnomad-update/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (3)Dependencies (4)Versions (8)Used By (2)

phpnomad/update
===============

[](#phpnomadupdate)

[![Latest Version](https://camo.githubusercontent.com/fdb0a90b3ae5d236d1443ff3de8f36b9feaa86ca31b892ef05758e3e860e70c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f7570646174652e737667)](https://packagist.org/packages/phpnomad/update)[![Total Downloads](https://camo.githubusercontent.com/1a63624babc7ffe2b533ced9fbf2dd1a13d188a24a11fb5957c8d88c7b11c703/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f7570646174652e737667)](https://packagist.org/packages/phpnomad/update)[![PHP Version](https://camo.githubusercontent.com/9ca83c1564db6abac73fec385498d65ed200ee134fc2a5fb05086a8ad88665ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f7570646174652e737667)](https://packagist.org/packages/phpnomad/update)[![License](https://camo.githubusercontent.com/60d894a23a74038b6aba1313080c628fc81d499f6b7c59f461ae8cfaecd87a8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f7570646174652e737667)](https://packagist.org/packages/phpnomad/update)

`phpnomad/update` runs upgrade routines when an application moves from one version to another. You define routines as small classes that declare a target version and do their work in an `up()` method, and the package handles filtering them to the right range, sorting them by version, and running them in order. Coordination happens through `phpnomad/event`, so routines can be contributed from any initializer without manual wiring.

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

[](#installation)

Install via Composer:

```
composer require phpnomad/update
```

Overview
--------

[](#overview)

- `UpgradeRoutine` is the interface each routine implements. It declares a target version via a static method and does its work in `up()`.
- `HasUpdates` is what your loader initializers implement to contribute routines. When `phpnomad/loader` boots an initializer that implements it, the loader attaches the routines to the collection event for you.
- `UpdateService::update($current, $target)` broadcasts the collection event, filters the returned routines to the ones whose target version falls above the current version and at or below the target, sorts them, and runs each one.
- `PlatformUpdateRequested` is the event a host broadcasts when it detects that the stored application version differs from the running version. A listener in the host calls `UpdateService::update()` in response.
- `StoredVersionDatastore` is the interface a host implements to read and write the currently installed version (options table, config file, environment variable, whatever fits the runtime).

Routine example
---------------

[](#routine-example)

A routine is a class that knows its target version and what to do:

```
