protected function startDispatcher() { $front = \Zend_Controller_Front::getInstance(); if (MIDORI_ENV == "test") { $front->setResponse(new \Midori\PHPUnit\Zend\HttpResponse()); $front->setRequest(new \Midori\PHPUnit\Zend\HttpRequest()); } if (MIDORI_ENV != "development") { $error_plugin = new \Zend_Controller_Plugin_ErrorHandler(); $error_plugin->setErrorHandlerController('Error')->setErrorHandlerAction('error'); $front->registerPlugin($error_plugin); } $paths = $this->config->paths; $front->setControllerDirectory(array('default' => $paths->controllers, 'admin' => $paths->controllers . '/admin')); $front->setDefaultControllerName("home"); $front->setDefaultAction('index'); $router = $front->getRouter(); require MIDORI_ROOT . "config/routes.php"; $array = \Midori\Application\Routes::getAllRoutes(); foreach ($array as $name => $routes) { foreach ($routes as $route) { $router->addRoute($name, $route); } } if (MIDORI_ENV == "development") { $front->throwExceptions(true); } $this->config->zend->frontController = $this->config->dispatcher = $front; }
protected function _getErrorHandlerInstance() { require_once 'Zend/Controller/Plugin/ErrorHandler.php'; $plugin = new Zend_Controller_Plugin_ErrorHandler(); $plugin->setErrorHandlerController($this->getController(self::CONTROLLER_ERROR)); return $plugin; }
protected function _initError() { $frontcontroller = $this->getResource('frontcontroller'); $error = new Zend_Controller_Plugin_ErrorHandler(); $error->setErrorHandlerController('error'); $frontcontroller->registerPlugin($error, 100); return $error; }
public function appBootstrap() { $this->frontController->setControllerDirectory(dirname(__FILE__) . '/_files/functional-test-app/controllers/'); // create an instance of the ErrorHandler so we can make sure it will point to our specially named ErrorController $plugin = new Zend_Controller_Plugin_ErrorHandler(); $plugin->setErrorHandlerController('zend-layout-functional-test-error')->setErrorHandlerAction('error'); $this->frontController->registerPlugin($plugin, 100); Zend_Layout::startMvc(dirname(__FILE__) . '/_files/functional-test-app/layouts/'); }
/** * * @return Zend_Controller_Plugin_ErrorHandler error handler plugin */ public function init() { $opt = $this->getOptions(); $controller = $this->getBootstrap()->getResource('frontController'); if (isset($opt['enable']) && (bool) $opt['enable']) { $errorHandler = new Zend_Controller_Plugin_ErrorHandler(); $errorHandler->setErrorHandlerModule($opt['module'])->setErrorHandlerController($opt['controller'])->setErrorHandlerAction($opt['action']); $controller->registerPlugin($errorHandler); $controller->throwExceptions(false); } else { $controller->throwExceptions(true); } return isset($errorHandler) ? $errorHandler : false; }
public function _setupErrorHandler($options) { $errorHandler = new Zend_Controller_Plugin_ErrorHandler($options); if (isset($options['module'])) { $errorHandler->setErrorHandlerModule($options['module']); } if (isset($options['controller'])) { $errorHandler->setErrorHandlerController($options['controller']); } if (isset($options['action'])) { $errorHandler->setErrorHandlerAction($options['action']); } $fc = Zend_Controller_Front::getInstance(); $fc->registerPlugin($errorHandler); return $errorHandler; }
/** * Retrieves the error handler * * @return Zend_Controller_Plugin_ErrorHandler|null * @throws Glitch_Application_Resource_Exception */ public function getErrorHandler() { if (null === $this->_errorHandler) { // Pull in the front controller; bootstrap first if necessary $this->_bootstrap->bootstrap('FrontController'); $front = $this->_bootstrap->getResource('FrontController'); // Ignore if no error handler is to be used if ($front->getParam('noErrorHandler')) { return null; } // Get existing plugin, if any, or create a new one $this->_errorHandler = $front->hasPlugin($this->_className) ? $front->getPlugin($this->_className) : new $this->_className(); // Dynamic class loading; perform sanity check if (!$this->_errorHandler instanceof Zend_Controller_Plugin_ErrorHandler) { throw new Glitch_Application_Resource_Exception('Class is not a valid error handler instance'); } // Get the default options $options = array('module' => $this->_errorHandler->getErrorHandlerModule(), 'controller' => $this->_errorHandler->getErrorHandlerController(), 'action' => $this->_errorHandler->getErrorHandlerAction()); // Merge with user-defined options from the config $options = array_merge($options, $this->getOptions()); // Be aware: values must be formatted as URI values (e.g. "default", not "Default"); $this->_errorHandler->setErrorHandlerModule($options['module']); $this->_errorHandler->setErrorHandlerController($options['controller']); $this->_errorHandler->setErrorHandlerAction($options['action']); if (!$front->hasPlugin($this->_className)) { // Use the same stack index as in Zend_Controller_Front::dispatch() $front->registerPlugin($this->_errorHandler, 100); } } return $this->_errorHandler; }
/** * @param \Zend_Controller_Request_Abstract $request * @throws mixed */ protected function _handleError(\Zend_Controller_Request_Abstract $request) { // remove zend error handler $front = \Zend_Controller_Front::getInstance(); $front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler"); $response = $this->getResponse(); if ($response->isException() && !$this->_isInsideErrorHandlerLoop) { // get errorpage try { // enable error handler $front->setParam('noErrorHandler', false); $errorPath = Config::getSystemConfig()->documents->error_pages->default; if (Site::isSiteRequest()) { $site = Site::getCurrentSite(); $errorPath = $site->getErrorDocument(); } if (empty($errorPath)) { $errorPath = "/"; } $document = Document::getByPath($errorPath); if (!$document instanceof Document\Page) { // default is home $document = Document::getById(1); } if ($document instanceof Document\Page) { $params = Tool::getRoutingDefaults(); if ($module = $document->getModule()) { $params["module"] = $module; } if ($controller = $document->getController()) { $params["controller"] = $controller; $params["action"] = "index"; } if ($action = $document->getAction()) { $params["action"] = $action; } $this->setErrorHandler($params); $request->setParam("document", $document); \Zend_Registry::set("pimcore_error_document", $document); // ensure that a viewRenderer exists, and is enabled if (!\Zend_Controller_Action_HelperBroker::hasHelper("viewRenderer")) { $viewRenderer = new \Pimcore\Controller\Action\Helper\ViewRenderer(); \Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); } $viewRenderer = \Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer"); $viewRenderer->setNoRender(false); if ($viewRenderer->view === null) { $viewRenderer->initView(PIMCORE_WEBSITE_PATH . "/views"); } } } catch (\Exception $e) { \Logger::emergency("error page not found"); } } // call default ZF error handler parent::_handleError($request); }
public function testPostDispatchQuitsWithFalseUserErrorHandlerParam() { $front = Zend_Controller_Front::getInstance(); $front->resetInstance(); $front->setParam('noErrorHandler', true); $this->response->setException(new Zend_Controller_Dispatcher_Exception('Testing controller exception')); $this->request->setModuleName('foo')->setControllerName('bar')->setActionName('baz'); $this->plugin->postDispatch($this->request); $this->assertNull($this->request->getParam('error_handler')); }
protected function _init() { $this->setDispatcher(new Kwf_Controller_Dispatcher()); $this->setControllerDirectory('controllers'); $this->returnResponse(true); $this->setParam('disableOutputBuffering', true); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Welcome', 'kwf_controller_action_welcome'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/User', 'kwf_controller_action_user'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Error', 'kwf_controller_action_error'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Pool', 'kwf_controller_action_pool'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Debug', 'kwf_controller_action_debug'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Cli', 'kwf_controller_action_cli'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Cli/Web', 'kwf_controller_action_cli_web'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Media', 'kwf_controller_action_media'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Spam', 'kwf_controller_action_spam'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Enquiries', 'kwf_controller_action_enquiries'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Redirects', 'kwf_controller_action_redirects'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Maintenance', 'kwf_controller_action_maintenance'); $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Trl', 'kwf_controller_action_trl'); if (file_exists('controllers/Cli')) { $this->addControllerDirectory('controllers/Cli', 'cli'); } $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Component', 'kwf_controller_action_component'); if (is_dir('controllers')) { //automatically add controller directories from web based on existing directories in filesystem in web $iterator = new DirectoryIterator('controllers'); $filter = new Zend_Filter_Word_CamelCaseToDash(); foreach ($iterator as $fileinfo) { if (!$fileinfo->isDot() && $fileinfo->isDir() && $fileinfo->getBasename() != 'Cli') { $this->addControllerDirectory($fileinfo->getPathname(), strtolower($filter->filter($fileinfo->getBasename()))); } } } $plugin = new Zend_Controller_Plugin_ErrorHandler(); $plugin->setErrorHandlerModule('kwf_controller_action_error'); if (PHP_SAPI == 'cli') { $plugin->setErrorHandlerController('cli'); } $this->registerPlugin($plugin); $this->setBaseUrl(Kwf_Setup::getBaseUrl()); }
protected function _handleError(Zend_Controller_Request_Abstract $request) { // remove zend error handler $front = Zend_Controller_Front::getInstance(); $front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler"); $response = $this->getResponse(); if ($response->isException() && !$this->_isInsideErrorHandlerLoop) { // get errorpage try { // enable error handler $front->setParam('noErrorHandler', false); $siteKey = Pimcore_Tool_Frontend::getSiteKey(); $errorPath = Pimcore_Config::getSystemConfig()->documents->error_pages->{$siteKey}; if (empty($errorPath)) { $errorPath = "/"; } $document = Document::getByPath($errorPath); if (!$document instanceof Document_Page) { // default is home $document = Document::getById(1); } if ($document instanceof Document_Page) { $params = Pimcore_Tool::getRoutingDefaults(); if ($module = $document->getModule()) { $params["module"] = $module; } if ($controller = $document->getController()) { $params["controller"] = $controller; $params["action"] = "index"; } if ($action = $document->getAction()) { $params["action"] = $action; } $this->setErrorHandler($params); $request->setParam("document", $document); Zend_Registry::set("pimcore_error_document", $document); } } catch (Exception $e) { Logger::emergency("error page not found"); } } // call default ZF error handler parent::_handleError($request); }
$autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->pushAutoloader(array('Phprojekt_Loader', 'autoload')); Phprojekt_Loader::addIncludeDirectory(realpath(PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'application')); ini_set('max_execution_time', 0); error_reporting(-1); // Set the timezone to UTC date_default_timezone_set('UTC'); // Start zend session to handle all session stuff Zend_Session::start(); $view = new Zend_View(); $view->addScriptPath(PHPR_CORE_PATH . '/Setup/Views/dojo/'); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view); $viewRenderer->setViewBasePathSpec(':moduleDir/Views'); $viewRenderer->setViewScriptPathSpec(':action.:suffix'); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); $plugin = new Zend_Controller_Plugin_ErrorHandler(); $plugin->setErrorHandlerModule('Setup'); $plugin->setErrorHandlerController('Error'); $plugin->setErrorHandlerAction('error'); $front = Zend_Controller_Front::getInstance(); $front->setDispatcher(new Phprojekt_Dispatcher()); $front->registerPlugin($plugin); $front->setDefaultModule('Setup'); $front->setModuleControllerDirectoryName('Controllers'); $front->addModuleDirectory(PHPR_CORE_PATH); $front->setParam('useDefaultControllerAlways', true); try { Zend_Controller_Front::getInstance()->dispatch(); } catch (Exception $error) { echo "Caught exception: " . $error->getFile() . ':' . $error->getLine() . "\n"; echo '<br/>' . $error->getMessage();
/** * init plugins * @return void */ protected function _initPlugins() { # only embed the debugging plugin if application status is development or testing if ($this->applicationStatus == "development") { # embed the ZFDebug Plugin/console $debug = new ZFDebug_Controller_Plugin_Debug(array('jquery_path' => '', 'plugins' => array('Variables', 'File' => array('basePath' => APPLICATION_PATH), 'Memory', 'Time', 'Html', 'Exception'))); $this->frontController->registerPlugin($debug); } # init error handler $this->frontController->throwExceptions(false); $errorhandler = new Zend_Controller_Plugin_ErrorHandler(); $errorhandler->setErrorHandler(array('module' => 'cms', 'controller' => 'error', 'action' => 'error')); $this->frontController->registerPlugin($errorhandler); # gadget plugin $gadgetPlugin = new FansubCMS_Controller_Plugin_Gadget(); $this->frontController->registerPlugin($gadgetPlugin); # not-logged-in-so-go-to-login plugin $aclPlugin = new FansubCMS_Controller_Plugin_Acl(Zend_Auth::getInstance()->setStorage(new FansubCMS_Auth_Storage_DoctrineSession())); $this->frontController->registerPlugin($aclPlugin); # check if install or update is needed $installPlugin = new FansubCMS_Controller_Plugin_InstallCheck(); $this->frontController->registerPlugin($installPlugin); # the navigation plugin $navPlugin = new FansubCMS_Controller_Plugin_Navigation(); $this->frontController->registerPlugin($navPlugin); }
/** * Initialize the paths, the config values and all the render stuff. * * @return void */ public function _initialize() { // Report all PHP errors error_reporting(-1); define('PHPR_CORE_PATH', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'application'); define('PHPR_LIBRARY_PATH', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'library'); if (!defined('PHPR_CONFIG_FILE')) { define('PHPR_CONFIG_FILE', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'configuration.php'); } set_include_path('.' . PATH_SEPARATOR . PHPR_LIBRARY_PATH . PATH_SEPARATOR . get_include_path()); require_once 'Zend/Loader/Autoloader.php'; require_once 'Phprojekt/Loader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->pushAutoloader(array('Phprojekt_Loader', 'autoload')); // Read the config file, but only the production setting try { $this->_config = new Zend_Config_Ini(PHPR_CONFIG_FILE, PHPR_CONFIG_SECTION, true); } catch (Zend_Config_Exception $error) { $response = new Zend_Controller_Request_Http(); $webPath = $response->getScheme() . '://' . $response->getHttpHost() . $response->getBasePath() . '/'; header("Location: " . $webPath . "setup.php"); die('You need the file configuration.php to continue. Have you tried the <a href="' . $webPath . 'setup.php">setup</a> routine?' . "\n" . '<br />Original error: ' . $error->getMessage()); } // Set webpath, tmpPath and applicationPath if (empty($this->_config->webpath)) { $response = new Zend_Controller_Request_Http(); $this->_config->webpath = $response->getScheme() . '://' . $response->getHttpHost() . $response->getBasePath() . '/'; } define('PHPR_ROOT_WEB_PATH', $this->_config->webpath . 'index.php/'); define('PHPR_TEMP_PATH', $this->_config->tmpPath); define('PHPR_USER_CORE_PATH', $this->_config->applicationPath); set_include_path('.' . PATH_SEPARATOR . PHPR_LIBRARY_PATH . PATH_SEPARATOR . PHPR_CORE_PATH . PATH_SEPARATOR . PHPR_USER_CORE_PATH . PATH_SEPARATOR . get_include_path()); // Set the timezone to UTC date_default_timezone_set('UTC'); // Start zend session to handle all session stuff try { Zend_Session::start(); } catch (Zend_Session_Exception $error) { Zend_Session::writeClose(); Zend_Session::start(); Zend_Session::regenerateId(); error_log($error); } // Set a metadata cache and clean it $frontendOptions = array('automatic_serialization' => true); $backendOptions = array('cache_dir' => PHPR_TEMP_PATH . 'zendCache' . DIRECTORY_SEPARATOR); try { $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); } catch (Exception $error) { die("The directory " . PHPR_TEMP_PATH . "zendCache do not exists or not have write access."); } Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache); // Use for Debug only //Zend_Db_Table_Abstract::getDefaultMetadataCache()->clean(); // Check Logs $this->getLog(); $missingRequirements = array(); // The following extensions are either needed by components of the Zend Framework that are used // or by P6 components itself. $extensionsNeeded = array('mbstring', 'iconv', 'ctype', 'gd', 'pcre', 'pdo', 'Reflection', 'session', 'SPL', 'zlib'); // These settings need to be properly configured by the admin $settingsNeeded = array('magic_quotes_gpc' => 0, 'magic_quotes_runtime' => 0, 'magic_quotes_sybase' => 0); // Check the PHP version $requiredPhpVersion = "5.2.4"; if (version_compare(phpversion(), $requiredPhpVersion, '<')) { // This is a requirement of the Zend Framework $missingRequirements[] = "- PHP Version '" . $requiredPhpVersion . "' or newer"; } foreach ($extensionsNeeded as $extension) { if (!extension_loaded($extension)) { $missingRequirements[] = "- The '" . $extension . "' extension must be enabled."; } } // Check pdo library $mysql = extension_loaded('pdo_mysql'); $sqlite = extension_loaded('pdo_sqlite2'); $pgsql = extension_loaded('pdo_pgsql'); if (!$mysql && !$sqlite && !$pgsql) { $missingRequirements[] = "- You need one of these PDO extensions: pdo_mysql, pdo_pgsql or pdo_sqlite"; } foreach ($settingsNeeded as $conf => $value) { if (ini_get($conf) != $value) { $missingRequirements[] = "- The php.ini setting of '" . $conf . "' has to be '" . $value . "'."; } } if (!empty($missingRequirements)) { $message = "Your PHP does not meet the requirements needed for P6.<br />" . implode("<br />", $missingRequirements); die($message); } $helperPaths = $this->_getHelperPaths(); $view = $this->_setView($helperPaths); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view); $viewRenderer->setViewBasePathSpec(':moduleDir/Views'); $viewRenderer->setViewScriptPathSpec(':action.:suffix'); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); foreach ($helperPaths as $helperPath) { Zend_Controller_Action_HelperBroker::addPath($helperPath['directory']); } $plugin = new Zend_Controller_Plugin_ErrorHandler(); $plugin->setErrorHandlerModule('Default'); $plugin->setErrorHandlerController('Error'); $plugin->setErrorHandlerAction('error'); $front = Zend_Controller_Front::getInstance(); $front->setDispatcher(new Phprojekt_Dispatcher()); $front->registerPlugin($plugin); $front->setDefaultModule('Default'); $front->setModuleControllerDirectoryName('Controllers'); $front->addModuleDirectory(PHPR_CORE_PATH); $front->addModuleDirectory(PHPR_USER_CORE_PATH); // Add SubModules directories with controlles $moduleDirectories = $this->_getControllersFolders($helperPaths); foreach ($moduleDirectories as $moduleDirectory) { $front->addModuleDirectory($moduleDirectory); } $front->setParam('useDefaultControllerAlways', true); // Define general error handler set_error_handler(array("Phprojekt", "errorHandler")); }
/** * */ public function __construct(array $option = array()) { $errorhandler = array('controller' => 'index', 'action' => 'sitemap'); $errorhandler = array_merge($errorhandler, $option); parent::__construct($errorhandler); }
/** * Route to APImodule * @param \Zend_Controller_Front $front */ private function routeToApi(\Zend_Controller_Front $front) { $errorPlugin = new \Zend_Controller_Plugin_ErrorHandler(); $errorPlugin->setErrorHandlerController(BaseRouter::DEFAULT_ERROR_CONTROLLER); $errorPlugin->setErrorHandlerAction(BaseRouter::DEFAULT_ERROR_ACTION); $errorPlugin->setErrorHandlerModule(ApiRouter::API_MODULE); $front->setParam('noViewRenderer', true); $front->setRequest(new ApiRequest())->setRouter(new ApiRouter())->registerPlugin($errorPlugin); }
protected function _initControllers() { $acl = new Zend_Acl(); $roleGuest = new Zend_Acl_Role('guest'); $acl->addRole($roleGuest); $acl->addRole(new Zend_Acl_Role('editor'), 'guest'); $acl->addRole(new Zend_Acl_Role('administrator')); $acl->add(new Zend_Acl_Resource('blog')); $acl->allow('editor', 'blog', array('index', 'archive', 'delete')); //Zend_Debug::dump($acl->isAllowed('editor', 'blog', 'index')); //Zend_Debug::dump($acl); // FrontController $this->bootstrap('FrontController'); //$this->frontController->setControllerDirectory(APPLICATION_PATH . '/controllers', 'default'); $error_plugin = new Zend_Controller_Plugin_ErrorHandler(); $error_plugin->setErrorHandlerModule('default')->setErrorHandlerController('error')->setErrorHandlerAction('error'); $front = $this->frontController; $front->setParam('Zend_Acl', $acl)->throwExceptions(true)->registerPlugin(new Lds_Controller_Plugin_Smarty())->registerPlugin(new Lds_Controller_Plugin_Modules())->registerPlugin($error_plugin); // ->registerPlugin(new Lds_Controller_Plugin_Filter()) $router = $front->getRouter(); //login $router->addRoute('login', new Zend_Controller_Router_Route('login/*', array('module' => 'settings', 'controller' => 'index', 'action' => 'login'))); //login $router->addRoute('logout', new Zend_Controller_Router_Route('logout/*', array('module' => 'settings', 'controller' => 'index', 'action' => 'logout'))); //register $router->addRoute('register', new Zend_Controller_Router_Route('register/*', array('module' => 'settings', 'controller' => 'index', 'action' => 'register'))); //各种操作note的command,都有此控制器此动作分配,命令单入口 $router->addRoute('note', new Zend_Controller_Router_Route('note/:command', array('module' => 'default', 'controller' => 'note', 'action' => 'index'))); //按category读取所拥有的note $router->addRoute('category', new Zend_Controller_Router_Route('category/:category_id', array('module' => 'default', 'controller' => 'category', 'action' => 'index'))); /* $this->frontController->throwExceptions(true); $this->frontController->setControllerDirectory(array( 'default' => APPLICATION_PATH . '/controllers', 'blog' => APPLICATION_PATH . '/modules/blog/controllers' )); */ //Zend_Registry::set('baseUrl',$this->frontController->getBaseUrl()); //Zend_Session::start(); /* $router = $this -> _front -> getRouter(); $config = new Zend_Config_Ini($this->_root . '/application/config/route.ini','route'); $router -> addConfig($config, 'routes'); */ //$options = $this->getOption('resources'); }
/** * Initialize the paths, the config values and all the render stuff. * * @return void */ public function _initialize() { // Report all PHP errors error_reporting(-1); define('PHPR_CORE_PATH', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'application'); define('PHPR_LIBRARY_PATH', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'library'); if (!defined('PHPR_CONFIG_FILE')) { define('PHPR_CONFIG_FILE', PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'configuration.php'); } set_include_path('.' . PATH_SEPARATOR . PHPR_LIBRARY_PATH . PATH_SEPARATOR . get_include_path()); require_once 'Zend/Loader/Autoloader.php'; require_once 'Phprojekt/Loader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->pushAutoloader(array('Phprojekt_Loader', 'autoload')); // Read the config file, but only the production setting try { $this->_config = new Zend_Config_Ini(PHPR_CONFIG_FILE, PHPR_CONFIG_SECTION, true); } catch (Zend_Config_Exception $error) { $response = new Zend_Controller_Request_Http(); $webPath = $response->getScheme() . '://' . $response->getHttpHost() . $response->getBasePath() . '/'; header("Location: " . $webPath . "setup.php"); die('You need the file configuration.php to continue. Have you tried the <a href="' . $webPath . 'setup.php">setup</a> routine?' . "\n" . '<br />Original error: ' . $error->getMessage()); } // Set webpath, tmpPath and applicationPath if (empty($this->_config->webpath)) { $response = new Zend_Controller_Request_Http(); $this->_config->webpath = $response->getScheme() . '://' . $response->getHttpHost() . $response->getBasePath() . '/'; } define('PHPR_ROOT_WEB_PATH', $this->_config->webpath . 'index.php/'); define('PHPR_TEMP_PATH', $this->_config->tmpPath); define('PHPR_USER_CORE_PATH', $this->_config->applicationPath); set_include_path('.' . PATH_SEPARATOR . PHPR_LIBRARY_PATH . PATH_SEPARATOR . PHPR_CORE_PATH . PATH_SEPARATOR . PHPR_USER_CORE_PATH . PATH_SEPARATOR . get_include_path()); // Set the timezone to UTC date_default_timezone_set('UTC'); // Start zend session to handle all session stuff try { Zend_Session::start(); } catch (Zend_Session_Exception $error) { Zend_Session::writeClose(); Zend_Session::start(); Zend_Session::regenerateId(); error_log($error); } // Set a metadata cache and clean it $frontendOptions = array('automatic_serialization' => true); $backendOptions = array('cache_dir' => PHPR_TEMP_PATH . 'zendCache' . DIRECTORY_SEPARATOR); try { $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); } catch (Exception $error) { die("The directory " . PHPR_TEMP_PATH . "zendCache do not exists or not have write access."); } Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache); // Use for Debug only //Zend_Db_Table_Abstract::getDefaultMetadataCache()->clean(); // Check Logs $this->getLog(); // Check the server $checkServer = Phprojekt::checkExtensionsAndSettings(); // Check the PHP version if (!$checkServer['requirements']['php']['checked']) { $missingRequirements[] = "- You need the PHP Version '" . $checkServer['requirements']['php']['required'] . "' or newer"; } // Check required extension foreach ($checkServer['requirements']['extension'] as $name => $values) { if (!$values['checked']) { $missingRequirements[] = "- The '" . $name . "' extension must be enabled."; } } // Check required settings foreach ($checkServer['requirements']['settings'] as $name => $values) { if (!$values['checked']) { $missingRequirements[] = "- The php.ini setting of '" . $name . "' has to be '" . $values['required'] . "'."; } } // Show message if (!empty($missingRequirements)) { $message = "Your PHP does not meet the requirements needed for P6.<br />" . implode("<br />", $missingRequirements); die($message); } $helperPaths = $this->_getHelperPaths(); $view = $this->_setView($helperPaths); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view); $viewRenderer->setViewBasePathSpec(':moduleDir/Views'); $viewRenderer->setViewScriptPathSpec(':action.:suffix'); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); foreach ($helperPaths as $helperPath) { Zend_Controller_Action_HelperBroker::addPath($helperPath['directory']); } $plugin = new Zend_Controller_Plugin_ErrorHandler(); $plugin->setErrorHandlerModule('Default'); $plugin->setErrorHandlerController('Error'); $plugin->setErrorHandlerAction('error'); $front = Zend_Controller_Front::getInstance(); $front->setDispatcher(new Phprojekt_Dispatcher()); $front->registerPlugin($plugin); $front->setDefaultModule('Default'); $front->setModuleControllerDirectoryName('Controllers'); $front->addModuleDirectory(PHPR_CORE_PATH); $front->addModuleDirectory(PHPR_USER_CORE_PATH); // Add SubModules directories with controlles $moduleDirectories = $this->_getControllersFolders($helperPaths); foreach ($moduleDirectories as $moduleDirectory) { $front->addModuleDirectory($moduleDirectory); } $front->setParam('useDefaultControllerAlways', true); // Define general error handler set_error_handler(array("Phprojekt", "errorHandler")); }
/** * Front Controller Bootstrap * * @return \Zend_Controller_Front */ protected static function initFrontController() { $front = \Zend_Controller_Front::getInstance(); $front->throwExceptions(false); $front->setParam('noViewRenderer', true); static::getModules(); $errorPlugin = new \Zend_Controller_Plugin_ErrorHandler(); $errorPlugin->setErrorHandlerModule(BaseRouter::DEFAULT_MODULE); $errorPlugin->setErrorHandlerController(BaseRouter::DEFAULT_ERROR_CONTROLLER); $errorPlugin->setErrorHandlerAction(BaseRouter::DEFAULT_ERROR_ACTION); $front->registerPlugin($errorPlugin); $contentType = new ContentType(); $secureCookies = new SecureCookies(); $front->registerPlugin($contentType); $front->registerPlugin($secureCookies); return $front; }
/** * setErrorHandler() - setup the error handling options * * @param array $options * @return Zym_Controller_Plugin_ErrorHandler */ public function setErrorHandler(array $options = array()) { if (isset($options['moduleErrorHandling'])) { $this->setModuleErrorHandling($options['moduleErrorHandling']); } if (isset($options['moduleErrorHandlerMap'])) { $this->setModuleErrorHandlerMap($options['moduleErrorHandlerMap']); } return parent::setErrorHandler($options); }
public static function setupFrontController() { $zmax_context = self::getRegistry()->get("zmax_context"); $config = $zmax_context->config; $app_dir = self::getRoot() . 'application' . DIRECTORY_SEPARATOR; self::$frontController = Zmax_Controller_Front::getInstance(); // Keep the front controller from sending exceptions self::$frontController->throwExceptions(false); // This tells where the controllers code can be found self::$frontController->setControllerDirectory(array('default' => $app_dir . 'controllers' . DIRECTORY_SEPARATOR, 'admin' => $app_dir . 'admin' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR)); // Set the error handler // PR: does not work, because it shows a warning when used // with Zend View and Zend_Layout .... if ($config->view->zmax_view_system == "phplib") { set_error_handler(array(self::$frontController, "errorHandler")); } // Change the error handler plugin, to forward exceptions // to the 'stalled' action of the index controller $eh = new Zend_Controller_Plugin_ErrorHandler(); $eh->setErrorHandlerController('index')->setErrorHandlerAction('stalled'); self::$frontController->registerPlugin($eh); // Remove all automatic escaping self::$frontController->normalizeHTTP(); // Set the base url self::$frontController->setBaseUrl(); }