定制 maglnet/magl-legacy-application 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maglnet/magl-legacy-application

最新稳定版本:1.13.0

Composer 安装命令:

composer require maglnet/magl-legacy-application

包简介

Provides a laminas module that is able to run legacy applications with the power of laminas.

README 文档

README

Latest Stable Version Scrutinizer Code Quality License Build Status Code Coverage

Run your legacy applications within Laminas.

Introduction

Since rewriting your legacy application from scratch to a Laminas application could be nearly impossible due to time, effort, and resources, I was searching for a way to migrate a legacy application to a Laminas application.

A great article by Chris Abernethy described a way on how to run your legacy application within ZF1, so I migrated this HowTo to a small Laminas module, to be able to run a legacy application within Laminas.

While running your legacy application within a Laminas application it is possible to slowly migrate an existing application to Laminas by leaving your old application (nearly - see "Adjust your legacy Application") untouched and build new modules with the power of Laminas.
By adding a simple wrapper (see "Using Laminas within your legacy application") you could also use the new modules within your legacy application.

Installation

Install through composer

{
    "require" : {
        "maglnet/magl-legacy-application" : "*"
    }
}

Enable the module within your Laminas application.config.php

    'modules' => array(
        'Application',
        'MaglLegacyApplication',
    ),

Copy the provided file data/magl-laminas-legacy-wrapper.php to your public/ folder.
Copy the provided file data/.htaccess to your publix folder.
Copy your legacy Application to your public/ folder.

Your legacy application should now run within Laminas. :)

Configuration

For any SEO optimized route within your legacy application, add a route to the zend router that routes to legacy controller and remove the mod_rewrite rules from your .htaccess

return array(
    'router' => array(
        'routes' => array(
            // example for transferring mod rewrite rules to laminas routes
            'legacy-seo-calendar' => array(
                'type' => 'Laminas\Mvc\Router\Http\Regex',
                'options' => array(
                    'regex'    => '/calendar/(?<foo>.+)',
                    'defaults' => array(
                        'controller' => 'MaglLegacyApplication\Controller\Legacy',
                        'action'     => 'index',
                        'script'     => 'index-already-seo-optimized.php',
                    ),
                    'spec' => '/',
                ),
            ),
        ),
    ),
);

Adjust your legacy Application

There are several cases in which your legacy application won't run without additional adjustments, here are some of them:

Relative Paths

Using relative paths for require, require_once or includes will possibly fail now, since Laminas will do a chdir() to the Laminas' application root. So you will need to adjust your paths to match the new root.

Example:

include '../lib/somelib.php';

should be changed to:

include __DIR__ . '/../lib/somelib.php';

Using Globals / Server SCRIPT_FILENAME or SCRIPT_NAME

Because of mod_rewrite rules, SCRIPT_FILENAME and SCRIPT_NAME won't be your real script anymore. If you use these variables, you need to adjust these places within your legacy application:

Example:

$script_filename = $_SERVER['SCRIPT_FILENAME'];
$script_name     = $_SERVER['SCRIPT_NAME'];

should be changed to:

use MaglLegacyApplication\Application\MaglLegacy;
$legacy          = MaglLegacy::getInstance();
$script_filename = $legacy->getLegacyScriptFilename();
$script_name     = $legacy->getLegacyScriptName();

Using Laminas within your legacy application

use MaglLegacyApplication\Application\MaglLegacy;
$application = MaglLegacy::getInstance()->getApplication();
$yourService = $application->getServiceManager()->get('YourService');

Injecting responses from within your legacy application

from wherever you are within your legacy application, it is possible to bypass your legacy applications controller code and send a response to the Laminas Controller wrapper. This response will then be handled like within a normal Laminas controller.

use MaglLegacyApplication\Application\MaglLegacy;
$application = MaglLegacy::getInstance()->getApplication();
$application->getEventManager()->getSharedManager()->attach('*', MaglLegacy::EVENT_SHORT_CIRCUIT_RESPONSE, function(Event $e){
    $response = new \Laminas\Http\Response();
    $response->setStatusCode(404);
    $response->setContent('not found');
    $e->stopPropagation(true);
    return $response;
});

Contributing

If you have questions or problems regarding this module just open an issue or, even better, solve it and open a pull request. 👍

统计信息

  • 总下载量: 40.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-05-20