mezzio / mezzio-migration
Migrate Mezzio applications from v2 to v3
Fund package maintenance!
Community Bridge
Installs: 29 292
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 12
Forks: 4
Open Issues: 7
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
- ext-json: *
- symfony/console: ^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0
Requires (Dev)
- laminas/laminas-coding-standard: ~2.5.0
- phpunit/phpunit: ^9.6.21
- psalm/plugin-phpunit: ^0.19.0
- vimeo/psalm: ^5.26.1
Conflicts
This package is auto-updated.
Last update: 2024-11-18 04:15:24 UTC
README
π·πΊ Π ΡΡΡΠΊΠΈΠΌ Π³ΡΠ°ΠΆΠ΄Π°Π½Π°ΠΌ
ΠΡ, ΡΡΠ°ΡΡΠ½ΠΈΠΊΠΈ Laminas, ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ ΠΈ ΠΆΠΈΠ²Π΅ΠΌ Π² ΡΠ°Π·Π½ΡΡ ΡΡΡΠ°Π½Π°Ρ . Π£ ΠΌΠ½ΠΎΠ³ΠΈΡ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΠΊΠΈ ΠΈ ΠΊΠΎΠ»Π»Π΅Π³ΠΈ ΠΊΠ°ΠΊ Π² Π ΠΎΡΡΠΈΠΈ, ΡΠ°ΠΊ ΠΈ Π² Π£ΠΊΡΠ°ΠΈΠ½Π΅. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ Π² Π ΠΎΡΡΠΈΠΈ. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΠΆΠΈΠ²ΡΡ Π² Π ΠΎΡΡΠΈΠΈ. Π£ Π½Π΅ΠΊΠΎΡΠΎΡΡΡ Π±Π°Π±ΡΡΠΊΠΈ ΠΈ Π΄Π΅Π΄ΡΡΠΊΠΈ ΡΡΠ°ΠΆΠ°Π»ΠΈΡΡ Ρ ΡΠ°ΡΠΈΡΡΠ°ΠΌΠΈ Π²ΠΎ ΠΡΠΎΡΠΎΠΉ ΠΌΠΈΡΠΎΠ²ΠΎΠΉ Π²ΠΎΠΉΠ½Π΅. ΠΠ΄Π΅ΡΡ Π½ΠΈΠΊΡΠΎ Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ ΡΠ°ΡΠΈΠ·ΠΌ.
Π£ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ ΡΠΊΡΠ°ΠΈΠ½ΡΠΊΠ°Ρ ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΡΠ°, ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠΏΠ°ΡΠ»Π°ΡΡ ΠΈΠ· Π΄ΠΎΠΌΠ° Π²ΠΌΠ΅ΡΡΠ΅ Ρ ΡΡΠ½ΠΎΠΌ. ΠΠΎΠ΅Π·Π΄ Π·Π°Π΄Π΅ΡΠΆΠ°Π»ΡΡ ΠΈΠ·-Π·Π° Π±ΠΎΠΌΠ±Π΅ΠΆΠΊΠΈ Π½Π° Π΄ΠΎΡΠΎΠ³Π΅ Π²ΠΏΠ΅ΡΠ΅Π΄ΠΈ. Π£ Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΠΊΠΎΡΠΎΡΡΠ΅ ΠΏΡΡΡΡΡΡΡ Π² Π±ΠΎΠΌΠ±ΠΎΡΠ±Π΅ΠΆΠΈΡΠ°Ρ . ΠΡ Ρ ΡΡΠ΅Π²ΠΎΠ³ΠΎΠΉ ΠΆΠ΄Π΅ΠΌ Π²Π΅ΡΡΠΎΡΠΊΠΈ ΠΎΡ Π½ΠΈΡ ΠΏΠΎΡΠ»Π΅ Π²ΠΎΠ·Π΄ΡΡΠ½ΡΡ Π½Π°Π»Π΅ΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠ΅ Π±Π΅ΡΠΏΠΎΡΡΠ΄ΠΎΡΠ½ΠΎ Π½Π°Π½ΠΎΡΡΡ ΡΠ΄Π°ΡΡ ΠΈ ΠΏΠΎΠΏΠ°Π΄Π°ΡΡ ΠΏΠΎ Π±ΠΎΠ»ΡΠ½ΠΈΡΠ°ΠΌ, ΡΠΊΠΎΠ»Π°ΠΌ, Π΄Π΅ΡΡΠΊΠΈΠΌ ΡΠ°Π΄Π°ΠΌ ΠΈ Π΄ΠΎΠΌΠ°ΠΌ. ΠΡ Π½Π΅ Π±Π΅ΡΠ΅ΠΌ ΡΡΠΎ ΠΈΠ· ΠΊΠ°ΠΊΠΈΡ -Π»ΠΈΠ±ΠΎ Π‘ΠΠ. ΠΡ Π½Π°Π±Π»ΡΠ΄Π°Π΅ΠΌ ΡΡΠΎ Π½Π°ΠΏΡΡΠΌΡΡ.
ΠΡ Π΄ΠΎΠ²Π΅ΡΡΠ΅ΡΠ΅ Π½Π°ΠΌ Π΄ΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ, ΡΡΠΎΠ± ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π½Π°ΡΠΈ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ, ΠΈ ΠΌΡ ΠΏΡΠΎΡΠΈΠΌ Π²Π°Ρ Π΄ΠΎΠ²Π΅ΡΠΈΡΡΡΡ Π½Π°ΠΌ Π²Π½ΠΎΠ²Ρ. ΠΡ Π½ΡΠΆΠ΄Π°Π΅ΠΌΡΡ Π² ΠΏΠΎΠΌΠΎΡΠΈ. ΠΡΡ ΠΎΠ΄ΠΈΡΠ΅ ΠΈ ΠΏΡΠΎΡΠ΅ΡΡΡΠΉΡΠ΅ ΠΏΡΠΎΡΠΈΠ² ΡΡΠΎΠΉ Π±Π΅ΡΠΏΠΎΠ»Π΅Π·Π½ΠΎΠΉ Π²ΠΎΠΉΠ½Ρ. ΠΡΡΠ°Π½ΠΎΠ²ΠΈΡΠ΅ ΠΊΡΠΎΠ²ΠΎΠΏΡΠΎΠ»ΠΈΡΠΈΠ΅. Π‘ΠΊΠ°ΠΆΠΈΡΠ΅ "ΠΠ΅Ρ Π²ΠΎΠΉΠ½Π΅!"
πΊπΈ To Citizens of Russia
We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
This library provides a tool for migrating from Mezzio v2 to v3.
Installation
Run the following to install this library:
$ composer require --dev mezzio/mezzio-migration
Usage
Once you have installed the tool, execute it with the following:
$ ./vendor/bin/mezzio-migration migrate
Cloning versus composer installation
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/mezzio/mezzio-migrationAnd then, instead of using
./vendor/bin/mezzio-migration migrate
, use/full/path/to/mezzio-migration/bin/mezzio-migration
.
TODO:
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.
Requirements
All external packages used within your project must be compatible with Mezzio 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 Mezzio package versions compatible with version 3, and to which the migration tool will update.
What does the tool do?
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 Mezzio 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:
-
Removes the
vendor
directory. -
Installs current dependencies using
composer install
. -
Analyzes
composer.lock
to identify all packages which depends on Mezzio packages. -
Removes all installed Mezzio packages and packages that depend on them.
-
Updates all remaining packages using
composer update
. -
Requires all Mezzio packages previously installed, adding the packages
laminas/laminas-component-installer
andmezzio/mezzio-tooling
as development packages if they were not previously installed. -
Requires all packages installed previously that were dependent on Mezzio. This step may fail in situations where external packages are not yet compatible with Mezzio v3 or its required libraries.
-
Updates
config/pipeline.php
:- 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:
pipeRoutingMiddleware
becomes apipe()
statement referencingMezzio\Router\Middleware\RouteMiddleware
.pipeDispatchMiddleware
becomes apipe()
statement referencingMezzio\Router\Middleware\DispatchMiddleware
,- References to
Mezzio\Middleware\NotFoundHandler
becomeMezzio\Handler\NotFoundHandler
, - References to
Mezzio\Middleware\ImplicitHeadMiddleware
becomeMezzio\Router\Middleware\ImplicitHeadMiddleware
, - References to
Mezzio\Middleware\ImplicitOptionsMiddleware
becomeMezzio\Router\Middleware\ImplicitOptionsMiddleware
,
- pipes
Mezzio\Router\Middleware\MethodNotAllowedMiddleware
afterImplicit*Middleware
(or if these are not piped, afterMezzio\Router\Middleware\RouteMiddleware
).
-
Updates
config/routes.php
:- adds strict type declaration on top of the file;
- adds a function wrapper (as is done in the version 3 skeleton).
-
Replaces
public/index.php
with the latest version from the v3 skeleton. -
Updates container configuration if
pimple
orAura.Di
were used (config/container.php
) from the latest skeleton version. Additionally, it does the following:- For
pimple
: the packagextreamwayz/pimple-container-interop
is replaced bylaminas/laminas-pimple-config
. - For
Aura.Di
: the packageaura/di
is replaced bylaminas/laminas-auradi-config
.
- For
-
Migrates http-interop middleware to PSR-15 middleware using
./vendor/bin/mezzio migrate:interop-middleware
. -
Migrates PSR-15 middleware to PSR-15 request handlers using
./vendor/bin/mezzio migrate:middleware-to-request-handler
. -
Runs
./vendor/bin/phpcbf
if it is available.
What should you do after migration?
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.
Configuration-driven pipelines and routes
The script does not work currently make any modifications to pipeline and route configuration; these will need to be updated manually.