Zend con practical-zf1-zf2-migration

C
Clark EverettsProfessional Services (Software) Consultant and Trainer at Perforce Software, Inc.
Practical ZF1 to ZF2 Migration:
Lessons from the Field
Clark Everetts,
Zend Technologies, Inc.
2
What are we going to talk about?
Getting from Here to Here
Higher-Level
(ROI, Organizational, Planning, Goals, Constraints)
Lower-Level
(Coding Suggestions, Tools, Resources, Best Practices)
Suggestions / Best Practices
3
•Clark Everetts
– Professional Services Consultant for Zend Technologies
– Onsite and Remote Consulting – Linux, IBM iSeries, Windows
●
Software Architecture Audits and Code Reviews
●
Performance Audits
●
Continuous Delivery Assessments
– Online / Onsite Training in PHP, ZF, Studio, Server, etc.
– SmartStarts: Training and Onsite Guided Development
•Past Life: Independent Consultant (2002 - 2012)
– Web Sites and Web Applications
– Contract Instructor for Zend
•Past, Past Life: Contractor for US Army and NASA (1990 - 2002)
– Interceptor Ground Control Software; Green Screen Db Applications
– Space Station: Real-time, Embedded Software; Science Platforms,
Life Support
Who am I?
4
•Your role: Manager, developer, stakeholder/decision-maker?
•Size: Small to large companies; small to large dev teams
•Have you migrated applications from ZF1 to ZF2?
•Migrating now? How far along in the process are you?
•What challenges did you face / are you facing?
•What tools did you use, or wish existed?
•What did you do before you started?
•Did you expect to accomplish anything besides “the
migration?”
Who are You?
What (I think) You Want to Know
•Available Tools? How much do they do?
•Low-hanging fruit; most difficulties?
•Cost/Benefit? Expected gains?
– Short-term?
– Long-term?
– When not to migrate?
•How to plan a migration; what factors affect the planning?
•Developer skills / skill levels required?
•Budget, schedule is expected for a given project size?
•Other resources?
6
•Zend's Collective Experience
– Planning, Guiding, Implementing Migrations
Where this talk comes from
7
The Prospect of Migration...
8
•Write new ZF2 application from scratch?
•Run ZF1 and ZF2 side-by-side?
– Use ZF2 components in existing ZF1 application
– Use ZF1 components in new ZF2 application
– Some URLs (existing capabilities) ZF1, with other URLs
(entirely new features) implemented in ZF2
– Convert models, controllers, utility functions, helpers,
etc.
•Which ZF2 components are easiest to use in a ZF1 app?
Decisions, decisions...
More Decisions!
•New URLs for new features of application: can do in ZF2, but will likely rely
upon existing ZF1 models, helpers, etc., especially if you took the effort to
make those components reusable in the first place
•Build and test ZF2 version and then cut over from old site to new one, or
iterate existing ZF1 production site into a new ZF2-based site?
•Select a minimum PHP version
– PHP 5.3.3 is minimum for ZF2; current are 5.5.4 and 5.4.20. PHP
5.3.27+ will receive only security fixes through much of 2014 (Zend
supports PHP 5.2 for Enterprise customers on particular product
versions; will continue to support PHP 5.3)
– Consider most recent PHP version you can; this implies parallel
migrations (PHP version as well as ZF2), Look at
http://php.net/ChangeLog-5.php for removal of /changes to legacy
features and new capabilities
– Consider impact to other PHP apps on the server
10
No One Migration Strategy to Rule Them All
There is no single, one-size-fits all, “correct” migration path for all
applications and organizations.
Many factors, including project size, team size and experience with ZF1
and ZF2, structure and quality of the ZF1 codebase, all affect the path to
take.
* http://ligh7bulb.deviantart.com/
*
Remember the Planned Migration Layer?
•Remember the planned Migration Layer?
– Was to allow ZF1 code to run on the ZF2 “engine”
– Work started during ZF2 betas; too much change between beta
releases to keep such a tool current
– Emulating ZF1 behaviour in ZF2 would have taken unacceptable
amount of developer time away from ZF2 development
•Though many people desired it, a full Migration Layer isn't strictly necessary
– PHP 5.3 Namespaces
– Migration: tedious, but not as hard as you think
●
Depends on the code you're starting with!
●
Fat controllers w/ data access, business logic, HTML :-(
Some Tools Exist to Help
•ZF2 Documentation Page
http://framework.zend.com/manual/2.2/en/migration/overview.html
●
GitHub: EvanDotPro/zf-2-for-1
ZF2 Form View Helpers, could be extended to other features
• GitHib: prolic/HumusMvcSkeletonApplication
integrates ModuleManager and ServiceManager into ZF1 application
See http://www.sasaprolic.com/2012/10/when-migration-to-zend-
framework-2.html
13
ZF1 Compatibility Module - Overview
•Custom ZF2 Module that you write – simple, straightforward
•Use existing ZF1-based application resources with minimal
initial code rewrite:
– Database
– Translation
– Session
•That is, Any Zend_Application_Resource plugin
•Obtain and use these resources as ZF2 Services via
ServiceManager
•Only for Application-wide, “global” resources
14
The Prospect of Migration...
Starting to Feel Better?
15
•What you do depends on what you want
– Delay a complete rewrite
●
Phased approach, reusing much of your ZF1 code
– Refactor and clean up “bad” code
•Smaller Application, perhaps non mission-critical
– Rewrite, use as a learning experience for a larger
migration effort
Planning
16
// config/application.config.php
'modules' => array(
'Application',
'Zf1', // <-- your ZF1 compatibility module
// you will add other modules to the list as you
progress
),
// remainder of config array
ZF1 Compatibility Module – Add Module to config
17
// module/Zf1/Module.php
namespace Zf1;
use ZendModuleManagerFeatureAutoloaderProviderInterface;
use ZendMvcMvcEvent;
class Module implements AutoloaderProviderInterface
{
public function getAutoloaderConfig()
{
$zf1path = getenv('ZF1_PATH'); // SetEnv in Apache vhost/.htaccess
if (!$zf1path) { throw new Exception('Define ZF1 library path'); }
/// more coming...
ZF1 Compatibility Module – Autoload ZF1 Classes
18
// module/Zf1/Module.php getAutoloaderConfig()
return array(
'ZendLoaderStandardAutoloader' => array (
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' .
str_replace('', '/', __NAMESPACE__)
),
'prefixes' => array('Zend' => $zf1path)
)
);
ZF1 Compatibility Module – Autoload ZF1 (cont.)
19
// module/Zf1/config/module.config.php
'service_manager' => array (
'factories' => array(
'zf1-db' => 'Zf1ServiceFactoryDatabase',
'zf1-translate'=> 'Zf1ServiceFactoryTranslate',
// other ZF1-based resources...
),
'aliases' => array (
'translate' => 'zf1-translate',
)
)
ZF1 Compat. Module – Resources become Services
20
ZF1 Compat. Module – Factories to Create Services
namespace Zf1ServiceFactory;
use ZendServiceManager;
class Database implements ServiceManagerFactoryInterface {
public function createService(
ServiceManagerServiceLocatorInterface $serviceLocator
)
{
$config = $serviceLocator->get('config');
$adapter = Zend_Db::factory(
$config['zf1-db']['adapter'],
$config['zf1-db']['params']
);
return $adapter;
}
}
21
ZF1 Compatibility Module – Register the Services
// module/Zf1/Module.php
public function onBootstrap(MvcEvent $e)
{
$services = $e->getApplication()->getServiceManager();
$dbAdapter = $services->get('zf1-db');
Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);
// Perhaps your views need config. For now, in views, access config
// directly via registry. Later, use code that injects config into view
$config = $services->get('config');
Zend_Registry::set('config', Util::arrayToObject($config));
// In audits, we often find ZF1 models accessing the db via registry
// What you see here is not “best practice,” but a baby step toward
// injecting this dependency in a later phase of migration
$database = $services->get('zf1-db');
Zend_Registry::set('database', $database);
$services = $e->getApplication()->getServiceManager();
Zend_Registry::set('session', $services->get('auth')->getStorage()-
>read());
}
22
ZF1 Compatibility Module – Review
•Temporary, stop-gap measure for reusing ZF1 resources
•Avoids major up-front rewrite
•Obtain and use these resources as ZF2 Services via
ServiceManager:
– Add it to the list of modules used by your ZF2 app
– Set up autoloading to find ZF1 library
– Identify Resources as Services to the ServiceManager
– Write Factories to create the services
– Register the Services
•Only for Application-wide, “global” resources
•Remember: This Module will GO AWAY in a later phase!
23
The Prospect of Migration...
How are you
feeling?
24
Reusing ZF1 Configuration - Overview
•ZF1 Configuration – .ini, .xml, .json, .yaml
•ZF2 Configuration – arrays
•Reuse existing ZF1 configuration files in ZF2 application
25
Reusing ZF1 Configuration - .ini files
// module/SomeModule/Module.php
public function getConfig ()
{
$path = __DIR__ . '/config/config.ini';
$config = new Zend_Config_Ini($path, $section);
$oldConfig = $config->toArray();
if (defined('ZF1_COMPAT')) {
$oldConfig['zf1-db'] = $oldConfig['db']; }
// Fix 1: for the database options
$dbParams = array ('driver' => $oldConfig['db']['adapter']);
$dbParams = array_merge($dbParams, $oldConfig['db']['params']);
$oldConfig['db'] = $dbParams;
$phpConfig = include __DIR__ . '/config/module.config.php';
return array_merge($oldConfig, $phpConfig);
}
26
Reuse ZF1 Models - Autoloading
// module/SomeModule/Module.php
public function getAutoloaderConfig ()
{
return array(
'ZendLoaderClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php'
),
'ZendLoaderStandardAutoloader' => array (
'namespaces' => array(
// if we're in a namespace deeper than one level we need to
// fix the  in the path
__NAMESPACE__ => __DIR__ . '/src/' . str_replace('', '/',
__NAMESPACE__)
),
'prefixes' => array(// This goes away in later phase
'Model' => __DIR__ .'/src/' . str_replace('', '/', __NAMESPACE__)
. '/Model',
)
)
);
}
27
Reuse ZF1 Models – Merge config with ZF2 config
// module/SomeModule/Module.php
public function getConfig ()
{
include __DIR__ . '/config/config.php';
$path = __DIR__ . '/config/config.ini';
$config = new Zend_Config_Ini($path, $section);
$oldConfig = $config->toArray();
if (defined('ZF1_COMPAT')) {
$oldConfig['zf1-db'] = $oldConfig['db'];
}
// database options from db section of config.ini
$dbParams = array('driver' => $oldConfig['db']['adapter']);
$dbParams = array_merge($dbParams, $oldConfig['db']['params']);
$oldConfig['db'] = $dbParams;
$phpConfig = include __DIR__ . '/config/module.config.php';
return array_merge($oldConfig, $phpConfig);
}
Opportunity for refactoring
Thank You!
Please give constructive feedback at
https://joind.in/9083
Email: clark.e@zend.com
https://github.com/clarkphp
Twitter: @clarkphp
1 of 28

Recommended

Zend con what-i-learned-about-mobile-first by
Zend con what-i-learned-about-mobile-firstZend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-firstClark Everetts
3.5K views15 slides
Sunshine php practical-zf1-zf2-migration by
Sunshine php practical-zf1-zf2-migrationSunshine php practical-zf1-zf2-migration
Sunshine php practical-zf1-zf2-migrationClark Everetts
2.7K views29 slides
Zend Framework 2, What's new, Confoo 2011 by
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Bachkoutou Toutou
1K views35 slides
Performance tuning with zend framework by
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
7.7K views26 slides
PHP Toolkit from Zend and IBM: Open Source on IBM i by
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden
40.5K views90 slides
Why Plone Will Die by
Why Plone Will DieWhy Plone Will Die
Why Plone Will DieAndreas Jung
6.5K views48 slides

More Related Content

What's hot

Browser tools that make web development easier by
Browser tools that make web development easierBrowser tools that make web development easier
Browser tools that make web development easierAlan Seiden
1.4K views30 slides
Git preso to valtech cfml team by
Git preso to valtech cfml teamGit preso to valtech cfml team
Git preso to valtech cfml teamSaravanaMuthu Jayaraj
637 views49 slides
Organizing Your PHP Projects (2010 ConFoo) by
Organizing Your PHP Projects (2010 ConFoo)Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Paul Jones
9.3K views50 slides
Zend Products and PHP for IBMi by
Zend Products and PHP for IBMi  Zend Products and PHP for IBMi
Zend Products and PHP for IBMi Shlomo Vanunu
2.2K views35 slides
Edp bootstrapping a-software_company by
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_companyGanesh Kulkarni
925 views117 slides
La vita nella corsia di sorpasso; A tutta velocità, XPages! by
La vita nella corsia di sorpasso; A tutta velocità, XPages!La vita nella corsia di sorpasso; A tutta velocità, XPages!
La vita nella corsia di sorpasso; A tutta velocità, XPages!Ulrich Krause
1.5K views68 slides

What's hot(19)

Browser tools that make web development easier by Alan Seiden
Browser tools that make web development easierBrowser tools that make web development easier
Browser tools that make web development easier
Alan Seiden1.4K views
Organizing Your PHP Projects (2010 ConFoo) by Paul Jones
Organizing Your PHP Projects (2010 ConFoo)Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)
Paul Jones9.3K views
Zend Products and PHP for IBMi by Shlomo Vanunu
Zend Products and PHP for IBMi  Zend Products and PHP for IBMi
Zend Products and PHP for IBMi
Shlomo Vanunu2.2K views
Edp bootstrapping a-software_company by Ganesh Kulkarni
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
Ganesh Kulkarni925 views
La vita nella corsia di sorpasso; A tutta velocità, XPages! by Ulrich Krause
La vita nella corsia di sorpasso; A tutta velocità, XPages!La vita nella corsia di sorpasso; A tutta velocità, XPages!
La vita nella corsia di sorpasso; A tutta velocità, XPages!
Ulrich Krause1.5K views
KYSUC - Keep Your Schema Under Control by Coimbra JUG
KYSUC - Keep Your Schema Under ControlKYSUC - Keep Your Schema Under Control
KYSUC - Keep Your Schema Under Control
Coimbra JUG5.7K views
Preparing for java 9 modules upload by Ryan Cuprak
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
Ryan Cuprak1.7K views
Node.js Development with Apache NetBeans by Ryan Cuprak
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
Ryan Cuprak5.5K views
Mixing Plone and Django for explosive results by Simone Deponti
Mixing Plone and Django for explosive resultsMixing Plone and Django for explosive results
Mixing Plone and Django for explosive results
Simone Deponti1.9K views
MWLUG 2015 - An Introduction to MVC by Ulrich Krause
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
Ulrich Krause1.3K views
Workshop Framework(J2EE/OSGi/RCP) by Summer Lu
Workshop Framework(J2EE/OSGi/RCP)Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)
Summer Lu683 views
“Bootify your app - from zero to hero by Izzet Mustafaiev
“Bootify  your app - from zero to hero“Bootify  your app - from zero to hero
“Bootify your app - from zero to hero
Izzet Mustafaiev2.2K views
Testing Alfresco extensions by ITD Systems
Testing Alfresco extensionsTesting Alfresco extensions
Testing Alfresco extensions
ITD Systems942 views
An Introduction to Play 2 Framework by PT.JUG
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 Framework
PT.JUG3.2K views

Viewers also liked

Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned by
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learnedMoving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learnedBaldur Rensch
4.2K views68 slides
NEC Japan by
NEC JapanNEC Japan
NEC JapanDave Michels
1.5K views34 slides
2012 deep research report on china special steel industry by
2012 deep research report on china special steel industry2012 deep research report on china special steel industry
2012 deep research report on china special steel industrysmarter2011
810 views15 slides
Tema 08 by
Tema 08Tema 08
Tema 08Faustino Arce Gomez
176 views10 slides
Skills And Competence A Lifespan Perspective Public by
Skills And Competence A Lifespan Perspective PublicSkills And Competence A Lifespan Perspective Public
Skills And Competence A Lifespan Perspective PublicLeo Casey
1K views61 slides

Viewers also liked(20)

Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned by Baldur Rensch
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learnedMoving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
Baldur Rensch4.2K views
2012 deep research report on china special steel industry by smarter2011
2012 deep research report on china special steel industry2012 deep research report on china special steel industry
2012 deep research report on china special steel industry
smarter2011810 views
Skills And Competence A Lifespan Perspective Public by Leo Casey
Skills And Competence A Lifespan Perspective PublicSkills And Competence A Lifespan Perspective Public
Skills And Competence A Lifespan Perspective Public
Leo Casey1K views
Top 10 Tips from Millionaires by maemis
Top 10 Tips from MillionairesTop 10 Tips from Millionaires
Top 10 Tips from Millionaires
maemis489 views
Using Oracle Applications on your iPad by Oracle Day
Using Oracle Applications on your iPadUsing Oracle Applications on your iPad
Using Oracle Applications on your iPad
Oracle Day2.4K views
مفهوم الضرر بين الشرع والطب by Dr Ghaiath Hussein
مفهوم الضرر بين الشرع والطبمفهوم الضرر بين الشرع والطب
مفهوم الضرر بين الشرع والطب
Dr Ghaiath Hussein923 views
Q2 2013 ASSA ABLOY investors presentation 19 july by ASSA ABLOY
Q2 2013 ASSA ABLOY investors presentation 19 julyQ2 2013 ASSA ABLOY investors presentation 19 july
Q2 2013 ASSA ABLOY investors presentation 19 july
ASSA ABLOY749 views
SAP Business Object Material by erpsoln
SAP Business Object Material SAP Business Object Material
SAP Business Object Material
erpsoln1.6K views
Open stack in action cern _openstack_accelerating_science by eNovance
Open stack in action  cern _openstack_accelerating_scienceOpen stack in action  cern _openstack_accelerating_science
Open stack in action cern _openstack_accelerating_science
eNovance1.8K views
Respeaking as a part of translation and interpreting curriculum by University of Warsaw
Respeaking as a part of translation and interpreting curriculumRespeaking as a part of translation and interpreting curriculum
Respeaking as a part of translation and interpreting curriculum
The Invention of Capitalism - Michael Perelman by berat celik
The Invention of Capitalism - Michael PerelmanThe Invention of Capitalism - Michael Perelman
The Invention of Capitalism - Michael Perelman
berat celik1.5K views

Similar to Zend con practical-zf1-zf2-migration

Extending ZF & Extending With ZF by
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZFRalph Schindler
1.2K views35 slides
SD PHP Zend Framework by
SD PHP Zend FrameworkSD PHP Zend Framework
SD PHP Zend Frameworkphilipjting
1.2K views10 slides
Frameworks choice by
Frameworks choiceFrameworks choice
Frameworks choicePawel Graczyk
1.3K views26 slides
ZF2 Modules: Events, Services, and of course, modularity by
ZF2 Modules: Events, Services, and of course, modularityZF2 Modules: Events, Services, and of course, modularity
ZF2 Modules: Events, Services, and of course, modularityJohn Coggeshall
765 views18 slides
Serverless design with Fn project by
Serverless design with Fn projectServerless design with Fn project
Serverless design with Fn projectSiva Rama Krishna Chunduru
467 views49 slides
faastRuby - Building a FaaS platform with Redis (RedisConf19) by
faastRuby - Building a FaaS platform with Redis (RedisConf19)faastRuby - Building a FaaS platform with Redis (RedisConf19)
faastRuby - Building a FaaS platform with Redis (RedisConf19)Paulo Arruda
49 views23 slides

Similar to Zend con practical-zf1-zf2-migration(20)

Extending ZF & Extending With ZF by Ralph Schindler
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZF
Ralph Schindler1.2K views
SD PHP Zend Framework by philipjting
SD PHP Zend FrameworkSD PHP Zend Framework
SD PHP Zend Framework
philipjting1.2K views
ZF2 Modules: Events, Services, and of course, modularity by John Coggeshall
ZF2 Modules: Events, Services, and of course, modularityZF2 Modules: Events, Services, and of course, modularity
ZF2 Modules: Events, Services, and of course, modularity
John Coggeshall765 views
faastRuby - Building a FaaS platform with Redis (RedisConf19) by Paulo Arruda
faastRuby - Building a FaaS platform with Redis (RedisConf19)faastRuby - Building a FaaS platform with Redis (RedisConf19)
faastRuby - Building a FaaS platform with Redis (RedisConf19)
Paulo Arruda49 views
Building A FaaA Platform With Redis: Paulo Arruda by Redis Labs
Building A FaaA Platform With Redis: Paulo ArrudaBuilding A FaaA Platform With Redis: Paulo Arruda
Building A FaaA Platform With Redis: Paulo Arruda
Redis Labs306 views
Puppet camp london nov 2014 slides (1) by Puppet
Puppet camp london nov 2014   slides (1)Puppet camp london nov 2014   slides (1)
Puppet camp london nov 2014 slides (1)
Puppet895 views
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf by ssuser705051
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
ssuser70505113 views
A quick start on Zend Framework 2 by Enrico Zimuel
A quick start on Zend Framework 2A quick start on Zend Framework 2
A quick start on Zend Framework 2
Enrico Zimuel16.5K views
Expressive Microservice Framework Blastoff by Adam Culp
Expressive Microservice Framework BlastoffExpressive Microservice Framework Blastoff
Expressive Microservice Framework Blastoff
Adam Culp1.6K views
Zend expressive workshop by Adam Culp
Zend expressive workshopZend expressive workshop
Zend expressive workshop
Adam Culp1.7K views
Organinzing Your PHP Projects (2010 Memphis PHP) by Paul Jones
Organinzing Your PHP Projects (2010 Memphis PHP)Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)
Paul Jones4.5K views
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013 by Mack Hardy
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy8.1K views
z13: New Opportunities – if you dare! by Michael Erichsen
z13: New Opportunities – if you dare!z13: New Opportunities – if you dare!
z13: New Opportunities – if you dare!
Michael Erichsen343 views
ZF2: Writing Service Components by Mike Willbanks
ZF2: Writing Service ComponentsZF2: Writing Service Components
ZF2: Writing Service Components
Mike Willbanks2K views

Recently uploaded

RADIUS-Omnichannel Interaction System by
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction SystemRADIUS
15 views21 slides
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze by
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeDigital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeNUS-ISS
19 views47 slides
Roadmap to Become Experts.pptx by
Roadmap to Become Experts.pptxRoadmap to Become Experts.pptx
Roadmap to Become Experts.pptxdscwidyatamanew
11 views45 slides
Perth MeetUp November 2023 by
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023 Michael Price
15 views44 slides
.conf Go 2023 - Data analysis as a routine by
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routineSplunk
93 views12 slides
[2023] Putting the R! in R&D.pdf by
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdfEleanor McHugh
38 views127 slides

Recently uploaded(20)

RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze by NUS-ISS
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeDigital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
NUS-ISS19 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
.conf Go 2023 - Data analysis as a routine by Splunk
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routine
Splunk93 views
[2023] Putting the R! in R&D.pdf by Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex19 views
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... by NUS-ISS
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
NUS-ISS34 views
How the World's Leading Independent Automotive Distributor is Reinventing Its... by NUS-ISS
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS15 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS28 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views

Zend con practical-zf1-zf2-migration

  • 1. Practical ZF1 to ZF2 Migration: Lessons from the Field Clark Everetts, Zend Technologies, Inc.
  • 2. 2 What are we going to talk about? Getting from Here to Here Higher-Level (ROI, Organizational, Planning, Goals, Constraints) Lower-Level (Coding Suggestions, Tools, Resources, Best Practices) Suggestions / Best Practices
  • 3. 3 •Clark Everetts – Professional Services Consultant for Zend Technologies – Onsite and Remote Consulting – Linux, IBM iSeries, Windows ● Software Architecture Audits and Code Reviews ● Performance Audits ● Continuous Delivery Assessments – Online / Onsite Training in PHP, ZF, Studio, Server, etc. – SmartStarts: Training and Onsite Guided Development •Past Life: Independent Consultant (2002 - 2012) – Web Sites and Web Applications – Contract Instructor for Zend •Past, Past Life: Contractor for US Army and NASA (1990 - 2002) – Interceptor Ground Control Software; Green Screen Db Applications – Space Station: Real-time, Embedded Software; Science Platforms, Life Support Who am I?
  • 4. 4 •Your role: Manager, developer, stakeholder/decision-maker? •Size: Small to large companies; small to large dev teams •Have you migrated applications from ZF1 to ZF2? •Migrating now? How far along in the process are you? •What challenges did you face / are you facing? •What tools did you use, or wish existed? •What did you do before you started? •Did you expect to accomplish anything besides “the migration?” Who are You?
  • 5. What (I think) You Want to Know •Available Tools? How much do they do? •Low-hanging fruit; most difficulties? •Cost/Benefit? Expected gains? – Short-term? – Long-term? – When not to migrate? •How to plan a migration; what factors affect the planning? •Developer skills / skill levels required? •Budget, schedule is expected for a given project size? •Other resources?
  • 6. 6 •Zend's Collective Experience – Planning, Guiding, Implementing Migrations Where this talk comes from
  • 7. 7 The Prospect of Migration...
  • 8. 8 •Write new ZF2 application from scratch? •Run ZF1 and ZF2 side-by-side? – Use ZF2 components in existing ZF1 application – Use ZF1 components in new ZF2 application – Some URLs (existing capabilities) ZF1, with other URLs (entirely new features) implemented in ZF2 – Convert models, controllers, utility functions, helpers, etc. •Which ZF2 components are easiest to use in a ZF1 app? Decisions, decisions...
  • 9. More Decisions! •New URLs for new features of application: can do in ZF2, but will likely rely upon existing ZF1 models, helpers, etc., especially if you took the effort to make those components reusable in the first place •Build and test ZF2 version and then cut over from old site to new one, or iterate existing ZF1 production site into a new ZF2-based site? •Select a minimum PHP version – PHP 5.3.3 is minimum for ZF2; current are 5.5.4 and 5.4.20. PHP 5.3.27+ will receive only security fixes through much of 2014 (Zend supports PHP 5.2 for Enterprise customers on particular product versions; will continue to support PHP 5.3) – Consider most recent PHP version you can; this implies parallel migrations (PHP version as well as ZF2), Look at http://php.net/ChangeLog-5.php for removal of /changes to legacy features and new capabilities – Consider impact to other PHP apps on the server
  • 10. 10 No One Migration Strategy to Rule Them All There is no single, one-size-fits all, “correct” migration path for all applications and organizations. Many factors, including project size, team size and experience with ZF1 and ZF2, structure and quality of the ZF1 codebase, all affect the path to take. * http://ligh7bulb.deviantart.com/ *
  • 11. Remember the Planned Migration Layer? •Remember the planned Migration Layer? – Was to allow ZF1 code to run on the ZF2 “engine” – Work started during ZF2 betas; too much change between beta releases to keep such a tool current – Emulating ZF1 behaviour in ZF2 would have taken unacceptable amount of developer time away from ZF2 development •Though many people desired it, a full Migration Layer isn't strictly necessary – PHP 5.3 Namespaces – Migration: tedious, but not as hard as you think ● Depends on the code you're starting with! ● Fat controllers w/ data access, business logic, HTML :-(
  • 12. Some Tools Exist to Help •ZF2 Documentation Page http://framework.zend.com/manual/2.2/en/migration/overview.html ● GitHub: EvanDotPro/zf-2-for-1 ZF2 Form View Helpers, could be extended to other features • GitHib: prolic/HumusMvcSkeletonApplication integrates ModuleManager and ServiceManager into ZF1 application See http://www.sasaprolic.com/2012/10/when-migration-to-zend- framework-2.html
  • 13. 13 ZF1 Compatibility Module - Overview •Custom ZF2 Module that you write – simple, straightforward •Use existing ZF1-based application resources with minimal initial code rewrite: – Database – Translation – Session •That is, Any Zend_Application_Resource plugin •Obtain and use these resources as ZF2 Services via ServiceManager •Only for Application-wide, “global” resources
  • 14. 14 The Prospect of Migration... Starting to Feel Better?
  • 15. 15 •What you do depends on what you want – Delay a complete rewrite ● Phased approach, reusing much of your ZF1 code – Refactor and clean up “bad” code •Smaller Application, perhaps non mission-critical – Rewrite, use as a learning experience for a larger migration effort Planning
  • 16. 16 // config/application.config.php 'modules' => array( 'Application', 'Zf1', // <-- your ZF1 compatibility module // you will add other modules to the list as you progress ), // remainder of config array ZF1 Compatibility Module – Add Module to config
  • 17. 17 // module/Zf1/Module.php namespace Zf1; use ZendModuleManagerFeatureAutoloaderProviderInterface; use ZendMvcMvcEvent; class Module implements AutoloaderProviderInterface { public function getAutoloaderConfig() { $zf1path = getenv('ZF1_PATH'); // SetEnv in Apache vhost/.htaccess if (!$zf1path) { throw new Exception('Define ZF1 library path'); } /// more coming... ZF1 Compatibility Module – Autoload ZF1 Classes
  • 18. 18 // module/Zf1/Module.php getAutoloaderConfig() return array( 'ZendLoaderStandardAutoloader' => array ( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . str_replace('', '/', __NAMESPACE__) ), 'prefixes' => array('Zend' => $zf1path) ) ); ZF1 Compatibility Module – Autoload ZF1 (cont.)
  • 19. 19 // module/Zf1/config/module.config.php 'service_manager' => array ( 'factories' => array( 'zf1-db' => 'Zf1ServiceFactoryDatabase', 'zf1-translate'=> 'Zf1ServiceFactoryTranslate', // other ZF1-based resources... ), 'aliases' => array ( 'translate' => 'zf1-translate', ) ) ZF1 Compat. Module – Resources become Services
  • 20. 20 ZF1 Compat. Module – Factories to Create Services namespace Zf1ServiceFactory; use ZendServiceManager; class Database implements ServiceManagerFactoryInterface { public function createService( ServiceManagerServiceLocatorInterface $serviceLocator ) { $config = $serviceLocator->get('config'); $adapter = Zend_Db::factory( $config['zf1-db']['adapter'], $config['zf1-db']['params'] ); return $adapter; } }
  • 21. 21 ZF1 Compatibility Module – Register the Services // module/Zf1/Module.php public function onBootstrap(MvcEvent $e) { $services = $e->getApplication()->getServiceManager(); $dbAdapter = $services->get('zf1-db'); Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter); // Perhaps your views need config. For now, in views, access config // directly via registry. Later, use code that injects config into view $config = $services->get('config'); Zend_Registry::set('config', Util::arrayToObject($config)); // In audits, we often find ZF1 models accessing the db via registry // What you see here is not “best practice,” but a baby step toward // injecting this dependency in a later phase of migration $database = $services->get('zf1-db'); Zend_Registry::set('database', $database); $services = $e->getApplication()->getServiceManager(); Zend_Registry::set('session', $services->get('auth')->getStorage()- >read()); }
  • 22. 22 ZF1 Compatibility Module – Review •Temporary, stop-gap measure for reusing ZF1 resources •Avoids major up-front rewrite •Obtain and use these resources as ZF2 Services via ServiceManager: – Add it to the list of modules used by your ZF2 app – Set up autoloading to find ZF1 library – Identify Resources as Services to the ServiceManager – Write Factories to create the services – Register the Services •Only for Application-wide, “global” resources •Remember: This Module will GO AWAY in a later phase!
  • 23. 23 The Prospect of Migration... How are you feeling?
  • 24. 24 Reusing ZF1 Configuration - Overview •ZF1 Configuration – .ini, .xml, .json, .yaml •ZF2 Configuration – arrays •Reuse existing ZF1 configuration files in ZF2 application
  • 25. 25 Reusing ZF1 Configuration - .ini files // module/SomeModule/Module.php public function getConfig () { $path = __DIR__ . '/config/config.ini'; $config = new Zend_Config_Ini($path, $section); $oldConfig = $config->toArray(); if (defined('ZF1_COMPAT')) { $oldConfig['zf1-db'] = $oldConfig['db']; } // Fix 1: for the database options $dbParams = array ('driver' => $oldConfig['db']['adapter']); $dbParams = array_merge($dbParams, $oldConfig['db']['params']); $oldConfig['db'] = $dbParams; $phpConfig = include __DIR__ . '/config/module.config.php'; return array_merge($oldConfig, $phpConfig); }
  • 26. 26 Reuse ZF1 Models - Autoloading // module/SomeModule/Module.php public function getAutoloaderConfig () { return array( 'ZendLoaderClassMapAutoloader' => array( __DIR__ . '/autoload_classmap.php' ), 'ZendLoaderStandardAutoloader' => array ( 'namespaces' => array( // if we're in a namespace deeper than one level we need to // fix the in the path __NAMESPACE__ => __DIR__ . '/src/' . str_replace('', '/', __NAMESPACE__) ), 'prefixes' => array(// This goes away in later phase 'Model' => __DIR__ .'/src/' . str_replace('', '/', __NAMESPACE__) . '/Model', ) ) ); }
  • 27. 27 Reuse ZF1 Models – Merge config with ZF2 config // module/SomeModule/Module.php public function getConfig () { include __DIR__ . '/config/config.php'; $path = __DIR__ . '/config/config.ini'; $config = new Zend_Config_Ini($path, $section); $oldConfig = $config->toArray(); if (defined('ZF1_COMPAT')) { $oldConfig['zf1-db'] = $oldConfig['db']; } // database options from db section of config.ini $dbParams = array('driver' => $oldConfig['db']['adapter']); $dbParams = array_merge($dbParams, $oldConfig['db']['params']); $oldConfig['db'] = $dbParams; $phpConfig = include __DIR__ . '/config/module.config.php'; return array_merge($oldConfig, $phpConfig); } Opportunity for refactoring
  • 28. Thank You! Please give constructive feedback at https://joind.in/9083 Email: clark.e@zend.com https://github.com/clarkphp Twitter: @clarkphp