/** * */ public function setUp() { $di = new DI(); $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb'; $_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb'); $request = new Request(); $request->setDI($di); $this->request = $request; $response = new Response(); $response->setDI($di); $dispatcher = new Dispatcher(); $dispatcher->setDI($di); $this->dispatcher = $dispatcher; $cache = new BackendCache(new FrontendCache()); $di->set('viewCache', $cache); $config = new Config(array('cache' => array('enable' => true))); $di->set('config', $config); $eventsManager = new Manager(); $di->set('request', $request, true); $di->set('response', $response, true); $di->set('dispatcher', $dispatcher, true); $di->set('eventsManager', $eventsManager); $this->di = $di; $application = new Application(); $application->setDI($di); $application->setEventsManager($eventsManager); $this->application = $application; }
public function setUp() { $di = new DI(); $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb'; $_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb'); $request = new Request(); $request->setDI($di); $this->request = $request; $response = new Response(); $response->setDI($di); $this->response = $response; $eventsManager = new Manager(); $cors = new Cors(array(array('domain' => 'bar.com'))); $di->set('request', $request, true); $di->set('response', $response, true); $di->set('eventsManager', $eventsManager); $di->set('cors', $cors); $this->di = $di; $application = new Application(); $application->setDI($di); $application->setEventsManager($eventsManager); $this->application = $application; }
/** * @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; }
/** * Initialize phalcon application * @return PhalconApplication */ protected function initPhalconApplication() { $diFactory = $this->diManager->getDI(); $moduleHandler = $diFactory->get('moduleHandler'); // Register autoloader (new Autoloader($diFactory))->register(); // Register services and routers $this->diManager->initInvokableServices()->initFactoriedServices()->initRouterDi(); // Init listeners (new Listener($diFactory))->listenApplicationEvents(new Listener\Application())->listenDispatchEvents(new Listener\Dispatch()); // Register modules $application = new PhalconApplication($diFactory); $application->setEventsManager($diFactory['eventsManager']); $application->registerModules($moduleHandler->getRegisteredModules()); 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); } }
/** * Runs the application performing all initializations * * @param $options * * @return mixed */ public function run($options) { $loaders = ['config', 'loader', 'session', 'permission', 'url', 'database', 'logger', 'environment', 'flash', 'flashsession', 'router', 'dispatcher', 'modelsmanager', 'metadata', 'annotations', 'view', 'cache', 'security', 'crypt', 'cookie', 'beanstalkd', 'acl', 'filemanager', 'authentication']; foreach ($loaders as $service) { $function = 'init' . ucfirst($service); $this->{$function}($options); } $application = new PhApplication(); $application->setDI($this->di); $modules = $this->getModules(); $application->registerModules($modules); $eventsManager = new PhEventsManager(); $application->setEventsManager($eventsManager); $eventsManager->attach('application:beforeHandleRequest', function ($event, $application) { $config = $this->di->get('config'); $response = $this->di->get('response'); $dispatcher = $this->di->get('dispatcher'); $cookie = $this->di->get('cookie'); //Detect mobile device $detect = new \Fly\Mobile_Detect(); if ($config->app_mobile == true && $detect->isMobile() && SUBDOMAIN != 'm' && $dispatcher->getModuleName() == 'common') { //begin redirect link to mobile version $curPageURL = \Fly\Helper::getCurrentUrl(); $curPageURL = str_replace(array('http://', 'https://'), array('http://m.', 'https://m.'), $curPageURL); $response->redirect($curPageURL, true); } //Setting language service $this->di->setShared('lang', function () use($dispatcher, $cookie) { $language = ''; // Detect language via cookie if ($cookie->has('language')) { $language = $cookie->get('language')->getValue(); } else { //Get default language $language = $this->config->defaultLanguage; } return new FlyTranslate(['module' => strtolower($dispatcher->getModuleName()), 'controller' => $dispatcher->getControllerName(), 'language' => $language]); }); }); return $application->handle()->getContent(); }
*/ require ROOT_DIR . 'core/config/services.php'; /** * Handle the request */ $application = new Application(); /** * Assign the DI */ $application->setDI($di); /** * Include modules */ $application->registerModules(require ROOT_DIR . 'core/config/modules.php'); /** * Sets the event manager */ $application->setEventsManager($eventsManager); echo $application->handle()->getContent(); } catch (Exception $e) { echo $e->getMessage(); echo $e->getTraceAsString(); /** * Show an static error page */ if (!$di->get('config')->application->debug) { $response = new Response(); $response->redirect('errors/503'); $response->send(); } }
/** * 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(); }
*/ include __DIR__ . "/../var/config/loader.php"; /** * Read common services */ include __DIR__ . "/../var/config/services.php"; include __DIR__ . '/../var/config/routes.php'; $oLogger = $di->getFileLogger(); $strVendorLoaderPath = $oConfig->application->libraryDir . '/autoload.php'; require_once $strVendorLoaderPath; $oAppEventsManager = new Manager(); /** * Handle the request */ $application = new Application($di); $application->setEventsManager($oAppEventsManager); $oAppEventsManager->attach('application', function ($event, $application) use($oLogger) { $oLogger->debug('application: ' . $event->getType()); }); // $application->registerModules(); // $arNamespaces = $di->getLoader()->getNamespaces(); /** * here's all the magic with modules */ $oModuleRouter = new ModuleRouter($application); if ($oModuleRouter->handle()) { $oLogger->debug('app modules registered: ' . print_r($application->getModules(), true)); $oLogger->debug('app default module: "' . $application->getDefaultModule() . '"'); // $oRouter = new AppRoute(); // $di->set('router', $oRouter); echo $application->handle()->getContent();