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:

  1. $ composer remove zendframework/zendframework
  2. $ composer require zendframework/zend-component-installer
  3. $ composer require zendframework/zend-mvc
  4. # 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.

  1. $ 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:

  1. "autoload": {
  2. "psr-4": {
  3. "Application\\": "module/Application/src/Application/"
  4. },
  5. "files": [
  6. "module/Application/Module.php"
  7. ]
  8. }

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:

  1. $ cd module/Application
  2. $ mv src temp
  3. $ mv temp/Application src
  4. $ rm -Rf ./temp
  5. $ 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:

  1. "autoload": {
  2. "psr-4": {
  3. "Application\\": "module/Application/src/"
  4. }
  5. }

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:

  1. <?php
  2. use Zend\Mvc\Application;
  3. /**
  4. * This makes our life easier when dealing with paths. Everything is relative
  5. * to the application root now.
  6. */
  7. chdir(dirname(__DIR__));
  8. // Decline static file requests back to the PHP built-in webserver
  9. if (php_sapi_name() === 'cli-server') {
  10. $path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
  11. if (__FILE__ !== $path && is_file($path)) {
  12. return false;
  13. }
  14. unset($path);
  15. }
  16. // Composer autoloading
  17. include __DIR__ . '/../vendor/autoload.php';
  18. if (! class_exists(Application::class)) {
  19. throw new RuntimeException(
  20. "Unable to load application.\n"
  21. . "- Type `composer install` if you are developing locally.\n"
  22. );
  23. }
  24. // Run the application!
  25. 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:

  1. $ 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. 在MFC框架中使用OpenGL的简单实例

    引言 我们知道,在MFC框架中,用于绘图的接口是GDI.但GDI只能绘制简单的2D图形,要想制作精美的3D图形,一个可行的办法是使用OpenGL或者Direct3D等第三方库. 由于最近在给导师的一个 ...

  2. DNN学习

    DNN(DotNetNuke)是一个免费.开源.可扩展的内容管理系统,可广泛用于商务网站.企业内网和外网网站.在线内容发布网站.DotNetNuke是微软第一次向开源说"Yes"的 ...

  3. Android实例-TTabControl的使用(XE8+小米2)

    结果:  1.如果直接改变Tab的TabIndex,那样是没有动态效果的.如果想要动态效果需要用到ChangeTabAction1; 2.ChangeTabAction1可以直接为按钮指定Action ...

  4. Java Serializable(序列化)的理解和总结、具体实现过程(转)

    原文地址:http://www.apkbus.com/forum.php?mod=viewthread&tid=13576&fromuid=3402 Java Serializable ...

  5. Linq使用之标准运算符方法

    #region linq的标准查询运算符(即lambda方式) 注:C#不支持标准查询运算符中带有整形参数(索引)的重载 // 1.标准查询运算符之筛选方法——where            //I ...

  6. 第一个android程序所遇到问题

    1.工程package的命名空间与activity的命名空间不一致,导致setcontentview找不到layout文件 2.增加Button等控件后,Java.R中id必须在删除现有Java.R文 ...

  7. VirtualBox NAT方式与主机互相通信

    之前说过,桥接方式适合在统一的网络环境中使用(一样的网关和许可). 如果网络环境发生改变,那就难堪了 -- 这就是我遇到的问题,公司里每人的IP都是固定的. 解决办法,改为NAT网络地址转换模式. 但 ...

  8. Moebius实现Sqlserver集群~介绍篇

    今年是一个不平凡的一年,接触到了很多新艳的,让人兴奋的东西,虽然自己的牙掉了两颗,但感觉自己又年青了两岁,哈哈!进入正题,今年公司开始启用数据库集群,对于Sqlserver来说,实现方式并不是很多,一 ...

  9. 设计Account 对象如下:  private long id;       private double balance;       private String password; 要求完善设计,使得该Account 对象能够自动分配id。 给定一个List 如下: &#

    package homework005; public class Account { private long id; private double balance; private String ...

  10. IDF实验室-python ByteCode writeup

    题目地址:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=45 下载来发现是crackme.pyc 可以用unc ...