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 function indexAction() { $docroot = getcwd() . '/' . $this->options->getDocRoot(); $docroot = rtrim($docroot, '/'); $scriptName = $this->params('script'); if (empty($scriptName)) { $path = $this->params('path') ? $this->params('path') : ''; foreach ($this->options->getIndexFiles() as $indexFile) { if (file_exists($docroot . '/' . $path . $indexFile)) { ob_start(); include $docroot . '/' . $path . $indexFile; $output = ob_get_clean(); $this->getResponse()->setContent($output); return $this->getResponse(); } } } $scriptUri = '/' . ltrim($scriptName, '/'); // force leading '/' $legacyScriptFilename = $docroot . $scriptUri; if (!file_exists($legacyScriptFilename)) { // if we're here, the file doesn't really exist and we do not know what to do $response = $this->getResponse(); /* @var $response Response */ //<-- this one for netbeans (WHY, NetBeans, WHY??) /** @var Response $response */ // <-- this one for other IDEs and code analyzers :) $response->setStatusCode(404); return; } //inform the application about the used script $this->legacy->setLegacyScriptFilename($legacyScriptFilename); $this->legacy->setLegacyScriptName($scriptUri); //inject get and request variables $this->setGetVariables(); ob_start(); include $legacyScriptFilename; $output = ob_get_clean(); $result = $this->getEventManager()->trigger(MaglLegacy::EVENT_SHORT_CIRCUIT_RESPONSE, $this); if ($result->stopped()) { return $result->last(); } $this->getResponse()->setContent($output); return $this->getResponse(); }
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();