Migrate Expressive applications from v2 to v3
This repository has moved to mezzio/mezzio-migration.
This library provides a tool for migrating from Expressive v2 to v3.
Run the following to install this library:
$ composer require --dev zendframework/zend-expressive-migration
Once you have installed the tool, execute it with the following:
$ ./vendor/bin/expressive-migration migrate
If you'd rather clone the tooling once and re-use it many times, you can do that instead. Clone using:$ git clone https://github.com/zendframework/zend-expressive-migration
And then, instead of using
./vendor/bin/expressive-migration migrate, use
Our goal is to prepare a downloadable phar file that can be installed in your system and re-used; this change will come at a future date.
All external packages used within your project must be compatible with Expressive v3 libraries. If you are unsure, check their dependencies.
This script will uninstall all dependent packages and then will try to install them with the latest compatible version. In case any package is not compatible, the script will report an error indicating which package need to be updated.
The following table indicates Expressive package versions compatible with version 3, and to which the migration tool will update.
In order to operate, the tool requires that the application directory contains a
composer.json file, and that this file is writable by the script.
Next, it attempts to detect the currently used Expressive version. If the version detected is not a 2.X version, the script will exit without performing any changes.
It then performs the following steps:
Installs current dependencies using
composer.lockto identify all packages which depends on Expressive packages.
Removes all installed Expressive packages and packages that depend on them.
Updates all remaining packages using
Requires all Expressive packages previously installed, adding the packages
zendframework/zend-expressive-toolingas development packages if they were not previously installed.
Requires all packages installed previously that were dependent on Expressive. This step may fail in situations where external packages are not yet compatible with Expressive v3 or its required libraries.
- adds strict type declarations to the top of the file;
- adds a function wrapper (as is done in the version 3 skeleton);
- updates the following middleware:
- References to
- References to
- References to
Implicit*Middleware(or if these are not piped, after
- adds strict type declaration on top of the file;
- adds a function wrapper (as is done in the version 3 skeleton).
public/index.phpwith the latest version from the v3 skeleton.
Updates container configuration if
Aura.Diwere used (
config/container.php) from the latest skeleton version. Additionally, it does the following:
pimple: the package
xtreamwayz/pimple-container-interopis replaced by
Aura.Di: the package
aura/diis replaced by
Migrates http-interop middleware to PSR-15 middleware using
Migrates PSR-15 middleware to PSR-15 request handlers using
./vendor/bin/phpcbfif it is available.
You will need to update your tests to use PSR-15 middleware instead of http-interop middleware. This step is not done automatically because it is too complicated. We can easily change imported classes, but unfortunately test strategies and mocking strategies vary widely, and detecting all http-interop variants makes this even more difficult.
Please manually compare and verify all changes made. It is possible that in some edge cases, the script will not work correctly. This will depend primarily on the number of modifications you have made to the original skeleton.
The script does not work currently make any modifications to pipeline and route configuration; these will need to be updated manually.