public function testSetGetApplication()
 {
     $appMock = $this->getMockBuilder('Zend\\Mvc\\Application')->disableOriginalConstructor()->getMock();
     $instance = MaglLegacy::getInstance();
     $instance->setApplication($appMock);
     $this->assertSame($appMock, $instance->getApplication());
 }
 public function getControllerConfig()
 {
     return array('factories' => array('MaglLegacyApplication\\Controller\\Legacy' => function ($sl) {
         $options = $sl->getServiceLocator()->get('MaglLegacyApplicationOptions');
         $legacyApp = Application\MaglLegacy::getInstance();
         return new \MaglLegacyApplication\Controller\LegacyController($options, $legacyApp);
     }));
 }
 public static function init()
 {
     $zf2ModulePaths = array(dirname(dirname(__DIR__)));
     if ($path = static::findParentPath('vendor')) {
         $zf2ModulePaths[] = $path;
     }
     if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0] && $path) {
         $zf2ModulePaths[] = $path;
     }
     static::initAutoloader();
     // use ModuleManager to load this module and it's dependencies
     $config = array('module_listener_options' => array('module_paths' => $zf2ModulePaths, 'config_glob_paths' => array(__DIR__ . '/application.config.php')), 'modules' => array('MaglLegacyApplication'));
     $app = Application::init($config);
     \MaglLegacyApplication\Application\MaglLegacy::getInstance()->setApplication($app);
     static::$serviceManager = $app->getServiceManager();
 }
<?php

/**
 * This is the index.php from the zf2 skeleton application
 * it was renamed to index-zf2-wrapper.php since the
 * legacy application could have (and possibly already has) an index.php
 *
 * additionally it uses MaglLegacyApplication::run() to be able to access the ZF2 mvc application from
 * within your legacy application
 */
define('REQUEST_MICROTIME', microtime(true));
chdir(dirname(__DIR__));
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
    return false;
}
// Setup autoloading
require 'init_autoloader.php';
// you do not need this, if MaglLegacyApplication is installed through composer
require_once realpath(__DIR__ . '/../module/MaglLegacyApplication/src/MaglLegacyApplication/Application/MaglLegacy.php');
$application = Zend\Mvc\Application::init(require 'config/application.config.php');
\MaglLegacyApplication\Application\MaglLegacy::getInstance()->setApplication($application);
$application->run();