private static function initDebug() { $di = get_app_di(); if ($di->get('config')->debug) { ini_set('display_errors', 'On'); error_reporting(E_ALL & ~E_NOTICE); } else { ini_set('display_errors', 'Off'); error_reporting(0); } }
private static function cgiRegister() { $di = get_app_di(); $config = self::getConfig(); self::registCommonService($di, $config); $di->setShared('router', function () { $router = new \Phalcon\Mvc\Router(); $router->removeExtraSlashes(true); $router->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3)); return $router; }); $di->setShared('dispatcher', function () { $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach('dispatch:beforeException', new NotFoundPlugin()); $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setEventsManager($eventsManager); $dispatcher->setDefaultNamespace("App\\Controllers\\"); return $dispatcher; }); $di->setShared('view', function () use($config) { $view = new \Phalcon\Mvc\View(); $view->setViewsDir($config->view->templatePath); $view->registerEngines(array('.html' => function ($view, $di) { $config = $di->get('config'); $compiledPath = $config->view->compiledPath; if (!file_exists($compiledPath)) { mkdir($compiledPath, 0744, true); } $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di); $volt->setOptions(array('compiledPath' => $compiledPath, 'compiledExtension' => $config->view->compiledExtension, 'compileAlways' => isset($config->view->compileAlways) ?: false)); $compiler = $volt->getCompiler(); $compiler->addExtension(new VoltExtension()); $autoEscape = isset($config->view->autoEscape) ?: true; ClassUtil::modifyPrivateProperties($compiler, array('_autoescape' => $autoEscape)); return $volt; })); return $view; }); $di->setShared('elements', function () { return new ElementsPlugin(); }); }
function run_cgi_application() { $di = get_app_di(); $application = new \Phalcon\Mvc\Application($di); echo $application->handle()->getContent(); }
public function __construct() { $this->setDI(get_app_di()); }