Rector rules for migrating an application from laminas-db 2.x to php-db/phpdb.
Warning
This tool is provided as-is, with no guarantee about the code it produces. Back up your code, or commit it to version control, before you begin, and review every change it makes before you deploy.
Each rule either rewrites code or leaves it alone and adds a comment:
- Rewrite: the new code means the same as the old code.
- Rewrite, review: the new code is right in the common case but behaves
slightly differently, for example by catching more exceptions. The rule
adds a
TODO(phpdb-migration)comment that starts withreview. - Flag: the right change depends on what the code meant. The rule leaves
the code alone and adds a
/** TODO(phpdb-migration) … */docblock that explains the break and the replacement.
Each comment names the finding it relates to, for example
TODO(phpdb-migration) R10:, which matches a heading in the documentation.
- PHP 8.3 or later
- Rector 2.9 or later, installed with this package
-
Back up or commit your code.
-
Install phpdb and the driver package for your database, for example:
composer require php-db/phpdb php-db/phpdb-mysql
-
Install this package as a development dependency:
composer require --dev php-db/phpdb-laminas-migration
-
Add the set to
rector.php:use PhpDb\LaminasMigration\Set\LaminasMigrationSetList; use Rector\Config\RectorConfig; return RectorConfig::configure() ->withPaths([__DIR__ . '/config', __DIR__ . '/src']) ->withSets([LaminasMigrationSetList::LAMINAS_DB_TO_PHPDB]) ->withImportNames(removeUnusedImports: true);
-
Preview the changes, then apply them:
vendor/bin/rector process --dry-run vendor/bin/rector process
-
Find everything left for you to check:
grep -rn "TODO(phpdb-migration)" config src -
Remove laminas-db and this package once the migration is finished.
| Set | Covers |
|---|---|
LAMINAS_DB_TO_PHPDB |
Every rule below, in the right order |
MYSQL |
MySQL driver, platform and metadata classes |
SQL |
Sql, Select, predicates and expressions |
CONFIG |
Adapter construction and configuration, drivers and service factories |
GATEWAY |
The adapter, gateways, result sets and metadata |
EXTENSION |
Classes that extend or implement phpdb types |
NAMESPACE |
Every other laminas-db class that phpdb keeps under the same name. Run it last |
Use the area sets to migrate in stages. Run them in the order shown.
config/class-map.php is generated. When phpdb adds or removes classes,
regenerate it from a laminas-db 2.22 checkout and a phpdb checkout:
php bin/generate-class-map.php path/to/laminas-db/src path/to/phpdb/srcconfig/signatures.php is generated too, from the installed php-db/phpdb and
php-db/phpdb-mysql packages. Regenerate it after updating them:
php bin/generate-signatures.phpThe end-to-end tests run the full set on two small sample applications, a
laminas-mvc one and a Mezzio one, in test/e2e, and compare the result with
each app's expected/ tree. Run them with composer e2e. After a deliberate
change to a rule, regenerate the expected trees and review the diff:
UPDATE_E2E=1 composer e2eThis package is in early development. Only some rules are implemented so far; see the documentation for the rule list.
See docs/book.