How can I migrate Zend Framework 1 to 3
Asked Answered
P

2

9

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.

Pumpkinseed answered 22/10, 2016 at 21:28 Comment(2)
Please accept an answer using the check mark below the up/down vote arrows if it answers your original question, thank you!Consist
ZF3 doesn't claim it's 4x times faster under PHP7, it claims it's up to 4x times faster than ZF2. There have been made a lot of speed improvements to zend-servicemanager, zend-eventmanager and other components.Belayneh
S
8

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.

Seessel answered 24/10, 2016 at 0:16 Comment(1)
You might want to add the migration to v3 page: docs.zendframework.com/tutorials/migration/to-v3/overviewBelayneh
C
4

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
Consist answered 22/10, 2016 at 22:19 Comment(2)
I think Its a double effort to first move ZF1 to ZF2 and then ZF3. Migration from ZF1 to ZF3 is almost the same as writing a new application most likely and same apply to ZF2. Going directly to v3 might be faster.Pumpkinseed
Absolutely. Try doing the bare minimum migration to Zf2 so at least you can run zf1 in parallel with it. Then migrate that to zf3 which will hopefully allow you to continue to run zf1 in parallel then you can incrementally do full migrations of the zf1 parts. How big is the project? Doing a complete migration to zf3 would require a lot of code rewrites.Consist

© 2022 - 2024 — McMap. All rights reserved.