public function init() { $debug = new \Phalcon\Debug(); $debug->listen(); $this->_registerServices(); $this->registerModules($this->modules); echo $this->handle()->getContent(); }
/** * Initializes the environment */ public function init() { $di = $this->getDi(); $eventsManager = $this->getEventsManager(); set_error_handler(array('\\Engine\\Error', 'normal')); register_shutdown_function(array('\\Engine\\Error', 'shutdown')); set_exception_handler(array('\\Engine\\Error', 'exception')); if ($this->_config->application->debug && $this->_config->application->profiler) { $profiler = new \Engine\Profiler(); $di->set('profiler', $profiler); $debug = new \Phalcon\Debug(); $debug->listen(); } }
public function init() { $debug = new \Phalcon\Debug(); $debug->listen(); $this->_registerServices(); /* When Phalcon\Mvc\Application have modules registered, always is necessary that every matched route returns a valid module. Each registered module has an associated class offering functions to set the module itself up. Each module class definition must implement two methods: registerAutoloaders() and registerServices(), they will be called by Phalcon\Mvc\Application according to the module to be executed. */ $this->registerModules($this->modules); echo $this->handle()->getContent(); }
public function init() { $hanlder = new AppException(); if (APP_ENV == 'dev') { if (isset($_GET['debug'])) { $debug = new \Phalcon\Debug(); $debug->listen(false, true); } else { error_reporting(E_ALL); ini_set('display_errors', 'On'); set_exception_handler(array($hanlder, 'throwException')); set_error_handler(array($hanlder, 'throwError'), E_ALL); register_shutdown_function(array($hanlder, 'throwParseError')); } } else { error_reporting(0); set_exception_handler(array($hanlder, 'throwException')); set_error_handler(array($hanlder, 'throwError'), E_ERROR); } }
$volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }, true); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { return new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname)); }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); /** * Set debugger */ $debug = new Phalcon\Debug(); $debug->listen();
private function dispatch($di) { $router = $di['router']; $router->handle(); $view = $di['view']; $dispatcher = $di['dispatcher']; $response = $di['response']; $dispatcher->setModuleName($router->getModuleName()); $dispatcher->setControllerName($router->getControllerName()); $dispatcher->setActionName($router->getActionName()); $dispatcher->setParams($router->getParams()); $moduleName = \Application\Utils\ModuleName::camelize($router->getModuleName()); $ModuleClassName = $moduleName . '\\Module'; if (class_exists($ModuleClassName)) { $module = new $ModuleClassName(); $module->registerAutoloaders(); $module->registerServices($di); } $view->start(); $registry = $di['registry']; if ($registry->cms['DEBUG_MODE']) { $debug = new \Phalcon\Debug(); $debug->listen(); $dispatcher->dispatch(); } else { try { $dispatcher->dispatch(); } catch (\Phalcon\Exception $e) { // Errors catching $view->setViewsDir(__DIR__ . '/modules/Index/views/'); $view->setPartialsDir(''); $view->e = $e; if ($e instanceof \Phalcon\Mvc\Dispatcher\Exception) { $response->setHeader(404, 'Not Found'); $view->partial('error/error404'); } else { $response->setHeader(503, 'Service Unavailable'); $view->partial('error/error503'); } $response->sendHeaders(); echo $response->getContent(); return; } } $view->render($dispatcher->getControllerName(), $dispatcher->getActionName(), $dispatcher->getParams()); $view->finish(); $response = $di['response']; // AJAX $request = $di['request']; $_ajax = $request->getQuery('_ajax'); if ($_ajax) { $contents = $view->getContent(); $return = new \stdClass(); $return->html = $contents; $return->title = $di->get('helper')->title()->get(); $return->success = true; if ($view->bodyClass) { $return->bodyClass = $view->bodyClass; } $headers = $response->getHeaders()->toArray(); if (isset($headers[404]) || isset($headers[503])) { $return->success = false; } $response->setContentType('application/json', 'UTF-8'); $response->setContent(json_encode($return)); } else { $response->setContent($view->getContent()); } $response->sendHeaders(); echo $response->getContent(); }
/** * Catch the exception and log it, display pretty view * * @param \Exception $e */ public static function exception(\Exception $e) { $config = \Phalcon\DI::getDefault()->getShared('config'); $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n"); if ($config->app->env == "development") { // Display debug output $debug = new \Phalcon\Debug(); $debug->onUncaughtException($e); } else { // Display pretty view of the error $di = new \Phalcon\DI\FactoryDefault(); $view = new \Phalcon\Mvc\View\Simple(); $view->setDI($di); $view->setViewsDir(APP_PATH . '/app/frontend/views/'); $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di)); echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config)); // Log errors to file and send email with errors to admin \Baseapp\Bootstrap::log($errors); } }
<?php /** * index.php */ // Phalcon Debugger Listen to Exceptions Globally defined('APP_DEBUG') or define('APP_DEBUG', true); $debug = new \Phalcon\Debug(); $debug->setUri('//static.pails.xueron.com/debug/3.0.x/'); // 国内CDN静态资源 $debug->listen(); require_once __DIR__ . '/../vendor/autoload.php'; $container = new Pails\Container(dirname(__DIR__)); $container->run(App\Http\Application::class);
public static function run() { if (in_array(APPLICATION_ENV, array('development'))) { $debug = new \Phalcon\Debug(); $debug->listen(); } $di = new \Phalcon\DI\FactoryDefault(); $config = (include APPLICATION_PATH . '/config/application.php'); $di->set('config', $config); $loader = new \Phalcon\Loader(); $loader->registerNamespaces($config->loader->namespaces->toArray()); $loader->register(); $loader->registerDirs(array(APPLICATION_PATH . "/plugins/")); $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset)); $di->set('db', $db); $view = new View(); /* $view->disableLevel(array( View::LEVEL_BEFORE_TEMPLATE => true, View::LEVEL_LAYOUT => true, View::LEVEL_AFTER_TEMPLATE => true )); */ define('MAIN_VIEW_PATH', '../../../views/'); $view->setMainView(MAIN_VIEW_PATH . 'main'); $view->setLayoutsDir(MAIN_VIEW_PATH . '/layouts/'); $view->setPartialsDir(MAIN_VIEW_PATH . '/partials/'); $volt = new \Application\Mvc\View\Engine\Volt($view, $di); $volt->setOptions(array('compiledPath' => APPLICATION_PATH . '/cache/volt/')); $volt->initCompiler(); $viewEngines = array(".volt" => $volt); $view->registerEngines($viewEngines); $di->set('view', $view); $viewSimple = new \Phalcon\Mvc\View\Simple(); $viewSimple->registerEngines($viewEngines); $di->set('viewSimple', $viewSimple); $url = new \Phalcon\Mvc\Url(); $url->setBasePath('/'); $url->setBaseUri('/'); $application = new \Phalcon\Mvc\Application(); $application->registerModules($config->modules->toArray()); $router = new \Application\Mvc\Router\DefaultRouter(); foreach ($application->getModules() as $module) { $className = str_replace('Module', 'Routes', $module['className']); if (class_exists($className)) { $class = new $className(); $router = $class->init($router); } } $di->set('router', $router); $eventsManager = new \Phalcon\Events\Manager(); $dispatcher = new \Phalcon\Mvc\Dispatcher(); $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) { new ExceptionPlugin($dispatcher, $exception); }); $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) { new LocalizationPlugin($dispatcher); }); $eventsManager->attach("acl", function ($event, $acl) { if ($event->getType() == 'beforeCheckAccess') { echo $acl->getActiveRole(), $acl->getActiveResource(), $acl->getActiveAccess(); } }); $dispatcher->setEventsManager($eventsManager); $di->set('dispatcher', $dispatcher); $session = new \Phalcon\Session\Adapter\Files(); $session->start(); $di->set('session', $session); $acl = new \Application\Acl\DefaultAcl(); $acl->setEventsManager($eventsManager); $di->set('acl', $acl); $assets = new \Phalcon\Assets\Manager(); $di->set('assets', $assets); $flash = new \Phalcon\Flash\Session(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning')); $di->set('flash', $flash); $di->set('helper', new \Application\Mvc\Helper()); $application->setDI($di); echo $application->handle()->getContent(); }
/** * @author : Hunter.<*****@*****.**> * @Description : 入口文件 * 上线后需要做以下事项: * 1:关闭调试 index.php DEBUG 0 * APP_DEBUG 0 */ if (version_compare(PHP_VERSION, '5.3.0', '<')) { die('要求 PHP > 5.3.0 !'); } define('DEBUG', true); define('APP_DEBUG', true); if (DEBUG) { error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', 'on'); $phalcon_debug = new Phalcon\Debug(); $phalcon_debug->setUri('http://phalcon.debug.static/www/debug/2.0.0/'); $phalcon_debug->listen(); if (function_exists('opcache_reset')) { opcache_reset(); } //$debug = new \Phalcon\Debug(); //$debug->listen(); } date_default_timezone_set('Asia/Shanghai'); //定义基本常量 define('HTTP_TYPE', !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"); //http or https define('HTTP_HOST', HTTP_TYPE . $_SERVER['HTTP_HOST']); //http(s)://www.xxx.com define('FRONTEND_PATH', '/Frontend');