/** * @param array $config * @return MvcApplication */ public static function createMvcFrom(array $config) : MvcApplication { $di = Di::createMvcFrom($config); $application = new MvcApplication($di); if ($di->has('applicationEventManager')) { $application->setEventsManager($di->getShared('applicationEventManager')); } $application->useImplicitView(isset($config['view'])); return $application; }
protected function initApplication() { $di = $this->getDI(); if (!$this->getUserOption('app') instanceof Application) { $this->setUserOption('app', new Application()); } $this->app = $this->getUserOption('app'); $this->app->setDI($di); $this->app->setEventsManager($di->get('eventsManager')); // disable implicit views if using simple views if ($di->has('view') && !$di->get('view') instanceof ViewInterface) { $this->app->useImplicitView(false); } $di->setShared('app', $this->app); if (!defined('APP_ENV')) { define('APP_ENV', getenv('APP_ENV') ?: static::ENV_PRODUCTION); } }
<?php use Phalcon\Mvc\Application; /** * This file deals with the creation of the Application class, * It allows seperation so we can inject the application inside tests as * well as using it for its usual purpose. * */ $container = (require_once __DIR__ . '/environment.php'); $application = new Application($container); // Use explicit views $application->useImplicitView(false); /** * Register the modules * */ $mods = $container->get('modules'); $application->registerModules($mods); return $application;
/** * Setup the phalcon application. * * @param null $uri * @return string */ protected function applicationSetup($uri = null) { $app = new Application($this->di); $app->useImplicitView('null' === $this->config['view']['default'] ? false : true); // set event manager for application $eventManager = $app->getDI()->getShared('eventsManager'); $this->setEventsManager($eventManager); $this->registerEvents(); /* * TODO This is bug on phalcon 2.0.4 */ $app->setEventsManager($this->getEventsManager()); return $app->handle($uri)->getContent(); }
$eventsManager = $app->di->get(AppServices::EVENTS_MANAGER); $app->dispatcher->setEventsManager($eventsManager); $router = $app->di->get(AppServices::ROUTER); /** * Attach plugins, components, modules to app */ include APP_PATH . 'Config/middleware.php'; include APP_PATH . 'Config/routes.php'; $modules = (include APP_PATH . 'Config/modules.php'); if (count($modules) > 0) { $app->registerModules($modules); } /** * Disable automatic rendering */ $app->useImplicitView(false); /** * Start application */ $app->handle(); /** * Set content */ $returnedValue = $app->dispatcher->getReturnedValue(); if ($returnedValue !== null && !is_string($returnedValue)) { $app->response->setJsonContent($returnedValue); } $response = $app->response; } catch (\Exception $e) { $response = $di->get(AppServices::RESPONSE); $response->setErrorContent($e, $config->debug);