Upgrading Applications

If you have an existing Zend Framework v2 application, and want to update it to the latest versions, you will have some special considerations.

Upgrading Zend Framework

Since the 2.5 release, the zendframework package has been essentially a "metapackage", defining no code, and only dependencies on the various component packages. This means that when you installzendframework/zendframework, you get the full set of components, at the latest 2.* versions.

With the release of version 3, we recommend:

  • Removing the zendframework/zendframework package.
  • Installing the zendframework/zend-component-installer package.
  • Installing the zendframework/zend-mvc package.
  • Installing each ZF component package you actually use in your application.

The process would look like this:

$ composer remove zendframework/zendframework
$ composer require zendframework/zend-component-installer
$ composer require zendframework/zend-mvc
# Repeat as necessary for components you use if not already installed

When you install zend-mvc, it will prompt you to add configuration for components; choose either application.config.php or modules.config.php, and re-use your selection for all other packages. This step ensures that the various components installed, and any news ones you add later, are configured in your application correctly.

This approach will ensure you are only installing what you actually need. As an example, if you are not using zend-barcode, or zend-permissions-acl, or zend-mail, there's no reason to install them.

Keeping the zendframework package

If you want to upgrade quickly, and cannot easily determine which components you use in your application, you can upgrade your zendframework requirement. When you do, you should also install the zend-component-installer, to ensure that component configuration is properly injected in your application.

$ composer require zendframework/zend-component-installer "zendframework/zendframework:^3.0"

During installation, it will prompt you to add configuration for components; choose either application.config.php or modules.config.php, and re-use your selection for all other packages. This step ensures that the various components installed, and any news ones you add later, are configured in your application correctly.

This will upgrade you to the latest releases of all Zend Framework components at once; it will also install new components developed as part of the version 3 initiative.

We still recommend reducing your dependencies at a later date, however.

Integration packages

During the Zend Framework 3 initiative, one goal was to reduce the number of dependencies for each package. This affected the MVC in particular, as a number of features were optional or presented deep integrations between the MVC and other components. These include the following:

Console tooling

If you were using the MVC console tooling, and are doing a partial update per the recommendations, you will need to install zend-mvc-console.

Forms integration

If you were using the forms in your MVC application, and are doing a partial update per the recommendations, you will need to install zend-mvc-form.

i18n integration

If you were using i18n features in your MVC application, and are doing a partial update per the recommendations, you will need to install zend-mvc-i18n.

Plugins

If you were using any of the prg()fileprg()identity(), orflashMessenger() MVC controller plugins, and are doing a partial update per the recommendations, you will need to install zend-mvc-plugins.

zend-di integration

If you were using the zend-servicemanager <-> zend-di integration within your application, you will need to install zend-servicemanager-di.

Autoloading

If you are doing a partial upgrade per the above recommendations (vs. upgrading the full zendframework package), one change is that zend-loader is no longer installed by default, nor recommended. Instead, we recommend using Composer for autoloading.

As such, you will need to setup autoloading rules for each module specific to your application.

As an example, if you are still defining the default Application module, you can add autoloading for it as follows in your project's composer.json:

"autoload": {
"psr-4": {
"Application\\": "module/Application/src/Application/"
},
"files": [
"module/Application/Module.php"
]
}

The above creates a PSR-4 autoloading rule for the Application module, telling it to look in the module/Application/src/Application/ directory. Since theApplication\Module class is defined at the module root, we specify it in thefiles configuration.

To improve on this, and simplify autoloading, we recommend adopting a complete PSR-4 directory structure for your module class files. As an example, to change the existing Application module to PSR-4, you can do the following:

$ cd module/Application
$ mv src temp
$ mv temp/Application src
$ rm -Rf ./temp
$ mv Module.php src/

Update your Module.php file to do the following:

  • Remove the getAutoloaderConfig() method entirely, if defined.
  • Update the getConfig() method frominclude __DIR__ . '/config/module.config.php toinclude _DIR__ . '/../config/module.config.php.

You can then update the autoload configuration to:

"autoload": {
"psr-4": {
"Application\\": "module/Application/src/"
}
}

The updated application skeleton already takes this approach.

Bootstrap

Because version 3 requires usage of Composer for autoloading, you can simplify your application bootstrap.

First, if you were using an init_autoloader.php file, you can now remove it.

Second, update your public/index.php to read as follows:

<?php

use Zend\Mvc\Application;

/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__)); // Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server') {
$path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (__FILE__ !== $path && is_file($path)) {
return false;
}
unset($path);
} // Composer autoloading
include __DIR__ . '/../vendor/autoload.php'; if (! class_exists(Application::class)) {
throw new RuntimeException(
"Unable to load application.\n"
. "- Type `composer install` if you are developing locally.\n"
);
} // Run the application!
Application::init(require __DIR__ . '/../config/application.config.php')->run();

Scripts

The skeleton application for version 2 shipped three scripts with it:

  • bin/classmap_generator.php
  • bin/pluginmap_generator.php
  • bin/templatemap_generator.php

If you are upgrading an existing application, these will still be present. However, if you are starting a new application, and used these previously, they are no longer present.

  • classmap_generator.php was removed as it's unnecessary when using Composer for autoloading. When preparing a production installation, runcomposer dump-autoload -o and/or composer dump-autoload -a; both will generate optimized class map autoloading rules for you.
  • pluginmap_generator.php was essentially obsolete due to the presence ofclassmap_generator.php anyways.
  • templatemap_generator.php was moved to the zend-view component with the 2.8.0 release of that component, and is now available via./vendor/bin/templatemap_generator.php. Additionally, its usage signature has changed; please use the --help or -h switches on first invocation to discover how to use it.

Development mode

Version 3 of the skeleton application adds a requirement on zfcampus/zf-development-mode, which provides a way to store common development-specific settings in your repository and then selectively enable/disable them during development.

If you are upgrading from an existing application, you can install this feature:

$ composer require zfcampus/zf-development-mode

Please refer to the package documentation for details on how to setup your application configuration to make use of this feature.

Upgrading Applications的更多相关文章

  1. JAVA工程师技能要求

    近期做了个JAVA工程师分类, JAVA工程师可能是市场上最多类的程序员:   初级JAVA工程师的基本要求 Good basic programming skills 良好基本编程技能 Founda ...

  2. Installation and Upgrading

    Cumulative Feature Overview Identifies product features available to you when upgrading. This tool r ...

  3. Oracle Applications Multiple Organizations Access Control for Custom Code

    档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code ...

  4. Oracle Applications DBA 基础(二)

    6.OAM及系统管理 2014年9月13日 20:40 参考资料: 1.Oracle Applications System Administrator's Guide - Configuration ...

  5. FNDCPASS Troubleshooting Guide For Login and Changing Applications Passwords

    In this Document   Goal   Solution   1. Error Starting Application Services After Changing APPS Pass ...

  6. Globalization Guide for Oracle Applications Release 12

    Section 1: Overview Section 2: Installing Section 3: Configuring Section 4: Maintaining Section 5: U ...

  7. 1.5 Upgrading From Previous Versions官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 1.5 Upgrading From Previous Versions 1.5 从 ...

  8. Authorization in Cloud Applications using AD Groups

    If you're a developer of a SaaS application that allows business users to create and share content – ...

  9. DAC Usage3:Monitor Data-tier Applications

    If you deploy a DAC to a managed instance of the Database Engine, information about the deployed DAC ...

随机推荐

  1. Asp.net MVC 4 异步方法

    今天我们来看一下,同样功能在 Asp.net MVC 4 下的实现,基于.net framework 4.5 下的async支持,让我们的代码更加简单,看下面片断代码名叫Index的Action方法: ...

  2. 下载网址 wMware

    http://blog.sina.com.cn/s/blog_4549d6770102vxue.html 安装mac 文档 http://jingyan.baidu.com/article/ff411 ...

  3. Java Web程序工作原理

    Web开发的最重要的基本功能是HTTP:Java Web开发的最重要的基本功是Servlet Specification.HTTP和Servlet Specitication对于Web Server和 ...

  4. 七牛上传Qt版本

    最近在找图床,写博客啥的需要.以前的图床好像挂了,搭在BAE上的图床也挂了,可能BAE3.0更新了吧. 花了点时间写了Qt版本 github地址:https://github.com/wzyuliya ...

  5. 深入了解JavaScript中的关键字

    this是Javascript语言的一个关键字它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用,下面分四种情况,详细讨论this的用法,感兴趣的朋友可以了解下. this是Javascri ...

  6. 5个最优秀的Java和C#代码转换工具

    http://www.codeceo.com/article/5-java-csharp-convert-tools.html 毋庸置疑,Java是一门最受欢迎而且使用最广泛的编程语言,目前有超过9百 ...

  7. bzoj 3122 [Sdoi2013]随机数生成器(逆元,BSGS)

    Description Input 输入含有多组数据,第一行一个正整数T,表示这个测试点内的数据组数.    接下来T行,每行有五个整数p,a,b,X1,t,表示一组数据.保证X1和t都是合法的页码. ...

  8. ios开发中,A valid provisioning profile for this executable was not found,的解决方法

    手头上的一个ios项目在上架后,再进行时出现了以上的这个错误,这是上架后忘了对一些配置进行复原 我的项目解决方法是: 是上面的这一块出现了问题,图片上的配置是正常的情况,但是上架的时候对其进行了修改, ...

  9. 卡特兰数 BZOJ3907 网格 NOIP2003 栈

    卡特兰数 卡特兰数2 卡特兰数:主要是求排列组合问题 1:括号化矩阵连乘,问多少种方案 2:走方格,不能过对角线,问多少种方案 3:凸边型,划分成三角形 4:1到n的序列进栈,有多少种出栈方案 NOI ...

  10. 你所不知道的五件事情--java.util.concurrent(第二部分)

    这是Ted Neward在IBM developerWorks中5 things系列文章中的一篇,仍然讲述了关于Java并发集合API的一些应用窍门,值得大家学习.(2010.06.17最后更新) 摘 ...