Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I migrate Zend Framework 1 to 3

Has anyone please describe how much architecture changed by Zend from Ver 1 to 3. Recently zend released ZF3 but no information provide how to migrate from zf1 to zf3. I have an application was developed in zf1, now looking for upgrade it to using PHP 7 power with ZF3. Should i need to rewrite entire code or how much effort need to move to latest version.

Also, ZF3 claimed its 4x faster under PHP7. In reality it is PHP7 itself which is faster, not ZF3. I am not sure how much they improved as comparing to Laravel framework which is one of top framework past few years.

If anyone used the ZF3 please share their experiences.

like image 220
Dheeraj Avatar asked Oct 22 '16 21:10

Dheeraj


2 Answers

If you're dealing with a large application, there will not be a quick and painless way to migrate to ZF3. From routing to services, both the practical and theoretical framework that sits beneath Zend Framework 2/3 is quite contrary to that of the first iteration.

When ZF2 was first released, I completed a ZF1 to ZF2 migration (as well as ZF2 to ZF3) on a very large project. We ended up using an incremental approach, requiring minor deviations from the core ZF1 library (i.e. we edited several Zend classes), which worked very well for us. Since ZF1 hit EOL in September, meaning there will no longer be any bug fixes or updates of any kind, this shouldn't pose a significant problem for you.

In the post I listed below, you'll find a description of the steps that allowed us to complete this migration, as well as a link to some of the code that aims to partially bridge ZF1/ZF2. Because the change from ZF2 and ZF3 did not create too many backwards compatibility issues, the steps I detailed in that post should still be (mostly) applicable for the migration from ZF1 to ZF3.

Step by step migration from Zend Framework 1 to 2

Here are two more links you may find helpful. The first link is the ZF1-to-ZF2 migration guide supplied by Zend. The second link is the general documentation for Zend Framework. If a component has been updated to version 3.0 (e.g. zend-mvc, zend-servicemanager, etc.), it should contain a migration guide that tells you what has changed between ZF2/3.

  • ZF1 to ZF2 migration - https://framework.zend.com/manual/2.4/en/migration/overview.html
  • ZF3 documentation - https://docs.zendframework.com/
like image 151
webjawns.com Avatar answered Sep 27 '22 21:09

webjawns.com


It may be a challenging road but I believe it is possible although it may come with a significant cost of time.

  1. Basically, migrate from ZF2 then migrate to ZF3.

  2. Or, if you just want the PHP7 speed ups, just upgrade to PHP7 and do some lint testing which may uncover some (but not all) bugs.

Read on for more...

Migrate to ZF2 first

https://framework.zend.com/manual/2.1/en/migration/overview.html

  1. Tools for namespacing your code.
  2. Tools for consuming Zend Framework 2 within your Zend Framework 1 application.
  3. Strategies for running Zend Framework 2 and Zend Framework 1 in parallel.
  4. Strategies for making your code easier to migrate, focussing primarily on clean separation of your domain logic and the MVC layer.
  5. Strategies for migrating the MVC layer.
  6. Strategies for migrating your domain layer.

Then, migrate to ZF3:

Zend Framework v2 to v3 has been intended as an incremental upgrade. We have even made efforts in the past year to provide forwards compatibility features in v2 versions of components, to allow users to prepare their code for upgrade.

This is not a comprehensive migration guide, however. While we know the majority of the areas where breakage can and will occur, we also know that only when developers are actually updating will we see the full situation. As such, treat this as a work in progress, and please feel free to propose updates or changes via issues or pull requests so we can improve!

https://docs.zendframework.com/tutorials/migration/to-v3/overview/

I'd imagine there is a significant amount of breakage due to the significant changes from ZF to ZF2 might have.

But, you can run ZF1 and ZF2 in parallel:

https://framework.zend.com/manual/2.4/en/migration/zf1_zf2_parallel.html

From a technical point of view it is absolutely possible to run ZF2 in parallel with ZF1 because there is no conflict between the classnames due to the fact that ZF2 uses namespaces and ZF1 does not. Running ZF1 and ZF2 in parallel can be used as a migration strategy in projects where it is not possible, or not convenient, to migrate an entire application from ZF1 to ZF2. For instance, you could implement any new features of the application using ZF2, while maintaining original ZF1 features.

It is unknown to me whether ZF1 and ZF3 can be run in parallel but perhaps not impossible.

Or, just try it out with PHP7

If it was me, I might just try upgrading to PHP7 first and look for any breakages in the code.

You can run something similar to the following to lint test your PHP code against PHP7:

find . -name "*.php" -print0 | xargs -P 8 -n 1 -0 sh -c '/usr/local/Cellar/php70/7.0.0/bin/php -l $0 || true' | grep -v 'No syntax'

If you're on a Mac you can use the PHP version switcher by installing it with brew.

brew install brew-php-switcher

You may need to comment out this line in your httpd.conf:

#LoadModule php5_module libexec/apache2/libphp5.so

then :

brew install php71

Add this line to your httpd.conf:

<FilesMatch .php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Switch versions:

brew-php-switcher 71
like image 36
Clay Avatar answered Sep 27 '22 21:09

Clay