Exemplo n.º 1
0
 public function init()
 {
     $debug = new \Phalcon\Debug();
     $debug->listen();
     $this->_registerServices();
     $this->registerModules($this->modules);
     echo $this->handle()->getContent();
 }
Exemplo n.º 2
0
 /**
  * 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();
     }
 }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
        $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();
Exemplo n.º 6
0
 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();
 }
Exemplo n.º 7
0
 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();
 }
Exemplo n.º 8
0
 * @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');
//为了适应原TP框架分离出来的目录
define('WEB_PATH', dirname(__FILE__));