mezzio/mezzio-migration

Migrate Mezzio applications from v2 to v3

1.4.0 2024-10-16 22:08 UTC

README

Build Status

πŸ‡·πŸ‡Ί Русским Π³Ρ€Π°ΠΆΠ΄Π°Π½Π°ΠΌ

ΠœΡ‹, участники 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-migration

And 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:

  1. Removes the vendor directory.

  2. Installs current dependencies using composer install.

  3. Analyzes composer.lock to identify all packages which depends on Mezzio packages.

  4. Removes all installed Mezzio packages and packages that depend on them.

  5. Updates all remaining packages using composer update.

  6. Requires all Mezzio packages previously installed, adding the packages laminas/laminas-component-installer and mezzio/mezzio-tooling as development packages if they were not previously installed.

  7. 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.

  8. Updates config/pipeline.php:

    1. adds strict type declarations to the top of the file;
    2. adds a function wrapper (as is done in the version 3 skeleton);
    3. updates the following middleware:
      • pipeRoutingMiddleware becomes a pipe() statement referencing Mezzio\Router\Middleware\RouteMiddleware.
      • pipeDispatchMiddleware becomes a pipe() statement referencing Mezzio\Router\Middleware\DispatchMiddleware,
      • References to Mezzio\Middleware\NotFoundHandler become Mezzio\Handler\NotFoundHandler,
      • References to Mezzio\Middleware\ImplicitHeadMiddleware become Mezzio\Router\Middleware\ImplicitHeadMiddleware,
      • References to Mezzio\Middleware\ImplicitOptionsMiddleware become Mezzio\Router\Middleware\ImplicitOptionsMiddleware,
    4. pipes Mezzio\Router\Middleware\MethodNotAllowedMiddleware after Implicit*Middleware (or if these are not piped, after Mezzio\Router\Middleware\RouteMiddleware).
  9. Updates config/routes.php:

    1. adds strict type declaration on top of the file;
    2. adds a function wrapper (as is done in the version 3 skeleton).
  10. Replaces public/index.php with the latest version from the v3 skeleton.

  11. Updates container configuration if pimple or Aura.Di were used (config/container.php) from the latest skeleton version. Additionally, it does the following:

    • For pimple: the package xtreamwayz/pimple-container-interop is replaced by laminas/laminas-pimple-config.
    • For Aura.Di: the package aura/di is replaced by laminas/laminas-auradi-config.
  12. Migrates http-interop middleware to PSR-15 middleware using ./vendor/bin/mezzio migrate:interop-middleware.

  13. Migrates PSR-15 middleware to PSR-15 request handlers using ./vendor/bin/mezzio migrate:middleware-to-request-handler.

  14. 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.